def test_pk(self): data = self.get_indicator_data(pk=143, program=RFProgramFactory()) self.assertEqual(data['pk'], 143)
def test_indicator_manual_sorting_manual_display_migrated(self): program = RFProgramFactory(migrated=True) indicator = Indicator.rf_aware_objects.get(pk=IndicatorFactory( program=program).pk) self.assertEqual(indicator.manual_number_display, False)
def test_manual_sorting_unmigrated(self): program = Program.objects.get(pk=RFProgramFactory(migrated=False).pk) self.assertEqual(program.manual_numbering, True)
def test_frequencies_annual(self): program = RFProgramFactory() RFIndicatorFactory(program=program, target_frequency=Indicator.ANNUAL) data = get_serialized_data(program.pk) self.assertEqual(data['frequencies'], [Indicator.ANNUAL])
def test_program_multiple_levels(self): program = RFProgramFactory(tiers=['Tier1', SPECIAL_CHARS, LONG_NAME]) levels = {} tiers = sorted(program.level_tiers.all(), key=lambda tier: tier.tier_depth) goal = LevelFactory(program=program, parent=None, name=SPECIAL_CHARS, customsort=1) levels[goal.pk] = { 'name': SPECIAL_CHARS, 'tier_pk': tiers[0].pk, 'tier_name': 'Tier1', 'chain_pk': 'all', 'ontology': '' } impact1 = LevelFactory(program=program, parent=goal, name=LONG_NAME, customsort=1) levels[impact1.pk] = { 'name': LONG_NAME, 'tier_pk': tiers[1].pk, 'tier_name': SPECIAL_CHARS, 'chain_pk': impact1.pk, 'ontology': '1' } output1 = LevelFactory(program=program, parent=impact1, name=SPECIAL_CHARS, customsort=1) levels[output1.pk] = { 'name': SPECIAL_CHARS, 'tier_pk': tiers[2].pk, 'tier_name': LONG_NAME, 'chain_pk': impact1.pk, 'ontology': '1.1' } output2 = LevelFactory(program=program, parent=impact1, customsort=2) levels[output2.pk] = {'ontology': '1.2'} impact2 = LevelFactory(program=program, parent=goal, customsort=2) levels[impact2.pk] = { 'tier_pk': tiers[1].pk, 'chain_pk': impact2.pk, 'ontology': '2' } levels[LevelFactory(program=program, parent=goal, customsort=3).pk] = { 'ontology': '3' } levels[LevelFactory(program=program, parent=impact2, customsort=1).pk] = { 'tier_pk': tiers[2].pk, 'chain_pk': impact2.pk, 'ontology': '2.1' } data = get_serialized_data(program.pk, levels=True) counted = [] for level_data in data['levels']: self.assertIn(level_data['pk'], levels) for key, value in levels[level_data['pk']].items(): self.assertEqual(level_data[key], value) counted.append(level_data['pk']) self.assertEqual(set(counted), set(levels.keys()))
def test_migrated_no_level_number(self): p = RFProgramFactory(tiers=['tier1', 'tier2'], levels=True) data = self.get_indicator_data(program=p, level=None) self.assertEqual(data['number'], None)
def get_program_data(self, **kwargs): return ProgramReportingPeriodSerializer( Program.rf_aware_objects.filter(pk=RFProgramFactory(**kwargs).pk), many=True ).data[0]
def test_manual_sorting_rf_always_auto_off(self): program = Program.objects.get(pk=RFProgramFactory( migrated=None, auto_number_indicators=False).pk) self.assertEqual(program.manual_numbering, True)
def test_rf_program_many_indicators(self): p = RFProgramFactory(months=20, tiers=['Goal', 'Outcome', 'Output', 'Activity'], levels=3) p.levels.filter(parent__isnull=True, customsort__gt=1).delete() goal_level = p.levels.filter(parent__isnull=True).first() goal_pk_a = RFIndicatorFactory( program=p, level=goal_level, target_frequency=Indicator.LOP, targets=300, results=310 ).pk goal_pk_b = RFIndicatorFactory( program=p, level=goal_level, target_frequency=Indicator.ANNUAL, targets=10, results=40, baseline="100", baseline_na=True ).pk pks = [] pks.append( RFIndicatorFactory( program=p, level=None, number='A1' ).pk ) pks.append( RFIndicatorFactory( program=p, level=None, old_level='Outcome', number='X21' ).pk ) pks.append( RFIndicatorFactory( program=p, level=None, old_level='Outcome', number='C14' ).pk ) pks.append( RFIndicatorFactory( program=p, level=None, old_level='Goal' ).pk ) unassigned_pks = pks[::-1] levels = list( sorted( sorted( [l for l in p.levels.filter(parent__isnull=False)], key=lambda l: l.customsort ), key=lambda l: l.level_depth ) ) for level in list(reversed(levels)): pks.append( RFIndicatorFactory( program=p, level=level, ).pk ) expected_pks = [goal_pk_a, goal_pk_b] + list(reversed(pks)) with self.assertNumQueries(4): data = ProgramPageProgramSerializer.get_for_pk(p.pk).data self.assertEqual(data['by_result_chain'], 'by Outcome chain') self.assertNotEqual(data['indicator_pks_level_order'], data['indicator_pks_chain_order']) indicator_pks = data['indicator_pks_level_order'] self.assertEqual(indicator_pks, expected_pks) chain_pks = [indicator.pk for indicator in goal_level.indicator_set.order_by('level_order')] for level in goal_level.get_children(): chain_pks += [indicator.pk for indicator in level.indicator_set.order_by('level_order')] chain_pks += unassigned_pks self.assertEqual(data['indicator_pks_chain_order'], chain_pks) self.assertTrue(data['indicators'][goal_pk_a]['is_reporting']) self.assertEqual(data['indicators'][goal_pk_a]['over_under'], 0) self.assertEqual(data['indicators'][goal_pk_a]['lop_target'], 300) self.assertEqual(data['indicators'][goal_pk_a]['level_pk'], goal_level.pk) self.assertEqual(data['indicators'][goal_pk_b]['baseline'], None) self.assertEqual(data['indicators'][goal_pk_b]['over_under'], 1) self.assertEqual(data['indicators'][unassigned_pks[0]]['number'], None) self.assertEqual(data['indicators'][unassigned_pks[1]]['old_level_name'], None) self.assertEqual(data['indicators'][unassigned_pks[2]]['level_pk'], None) translation.activate('fr') with self.assertNumQueries(4): french_data = ProgramPageProgramSerializer.get_for_pk(p.pk).data translation.activate('en') self.assertEqual(french_data['by_result_chain'], u'par chaîne Résultat') self.assertEqual(french_data['indicators'][goal_pk_b]['number'], u'Objectif b') self.assertEqual(french_data['indicators'][expected_pks[6]]['number'], u'Rendement 1.2a') self.assertEqual(french_data['indicators'][unassigned_pks[1]]['old_level_name'], None)
def test_no_level_pk(self): p = RFProgramFactory(tiers=["Tier1", "Tier2"], levels=1, levels__1={'id': 901}) data = self.get_indicator_data(program=p) self.assertEqual(data['level_pk'], None)
def test_means_of_verification(self): p = RFProgramFactory() for means in ["test means", "long " * 50, u"Spécîa¬l character means"]: data = self.get_indicator_data(program=p, means_of_verification=means) self.assertEqual(data['means_of_verification'], means)
def test_translated_old_level(self): translation.activate('fr') data = self.get_indicator_data( program=RFProgramFactory(migrated=False), old_level="Outcome") self.assertEqual(data['old_level_name'], u"Résultat") translation.activate('en')
def test_non_rf_level_pk(self): data = self.get_indicator_data( program=RFProgramFactory(migrated=False), old_level="Activity") self.assertEqual(data['old_level_name'], "Activity") self.assertEqual(data['level_pk'], 6)
def test_name(self): p = RFProgramFactory() for name in ['normal name', u'Spécîal Characters', 'asdfg' * 99]: data = self.get_indicator_data(program=p, name=name) self.assertEqual(data['name'], name)
def test_non_migrated_long_number_number_blank(self): p = RFProgramFactory(migrated=False) data = self.get_indicator_data(program=p, number=None) self.assertEqual(data['number'], None)
def test_reporting_closed_program_lop_with_results(self): data = self.get_indicator_data(program=RFProgramFactory(), target_frequency=Indicator.LOP, targets=True, results=True) self.assertEqual(data['is_reporting'], True)
def test_migrated_manual_number_long_number_number_empty(self): p = RFProgramFactory(migrated=True, auto_number_indicators=False) data = self.get_indicator_data(program=p, number="") self.assertEqual(data['number'], None)
def test_reporting_closed_program_lop_no_results(self): data = self.get_indicator_data(program=RFProgramFactory(), target_frequency=Indicator.LOP, targets=True) self.assertEqual(data['is_reporting'], False) self.assertEqual(data['over_under'], None)
def test_migrated_has_level_number_special_chars(self): special_chars = u"Tiér Speciål Chars" p = RFProgramFactory(tiers=['tier1', special_chars], levels=True) l = [l for l in p.levels.all() if l.level_depth == 2][0] data = self.get_indicator_data(program=p, level=l, level_order=0) self.assertEqual(data['number'], u"{} 1a".format(special_chars))
def test_over_under_program_lop_on_target(self): data = self.get_indicator_data(program=RFProgramFactory(), target_frequency=Indicator.LOP, targets=200, results=205) self.assertEqual(data['over_under'], 0)
def get_program_data(**kwargs): return get_serialized_data(RFProgramFactory(**kwargs).pk)
def test_all_targets_defined(self): data = self.get_indicator_data(program=RFProgramFactory(), target_frequency=Indicator.ANNUAL, targets=500) self.assertEqual(data['has_all_targets_defined'], True)
def test_program_no_levels(self): program = RFProgramFactory() data = get_serialized_data(program.pk, levels=True) self.assertEqual(data['levels'], [])
def test_all_targets_not_defined(self): data = self.get_indicator_data(program=RFProgramFactory(), target_frequency=Indicator.SEMI_ANNUAL, targets='incomplete') self.assertEqual(data['has_all_targets_defined'], False)
def get_program_data(self, **kwargs): return ProgramPageProgramSerializer( Program.program_page_objects.filter(pk=RFProgramFactory(**kwargs).pk), many=True ).data[0]
def test_non_migrated_long_number(self): p = RFProgramFactory(migrated=False) data = self.get_indicator_data(program=p, number="142.5a") self.assertEqual(data['number'], "142.5a")
def test_indicator_manual_sorting_manual_display_rf_always_auto_off(self): program = RFProgramFactory(migrated=None, auto_number_indicators=False) indicator = Indicator.rf_aware_objects.get(pk=IndicatorFactory( program=program).pk) self.assertEqual(indicator.manual_number_display, True)
def test_non_migrated_long_number_special_chars(self): p = RFProgramFactory(migrated=False) data = self.get_indicator_data(program=p, number=u"1.1å") self.assertEqual(data['number'], u"1.1å")
def test_manual_sorting_rf_always(self): program = Program.objects.get(pk=RFProgramFactory(migrated=None).pk) self.assertEqual(program.manual_numbering, False)
def test_inactive_program(self): p = RFProgramFactory(active=False) self.assertEqual(p.funding_status, "Inactive")