예제 #1
0
 def test_has_two_site_pks_two_results(self):
     i = RFIndicatorFactory(
         program=RFProgramFactory(), target_frequency=Indicator.LOP,
         targets=1000, results=True, results__count=2)
     site1 = SiteProfileFactory()
     site2 = SiteProfileFactory()
     i.result_set.all()[0].site.add(site1)
     i.result_set.all()[1].site.add(site2)
     data = get_serialized_data(i.pk)
     self.assertEqual(data['site_pks'], sorted([site1.pk, site2.pk]))
예제 #2
0
    def test_get_sites(self):
        """It should return all and only the sites for a given program"""

        expected = SiteProfileFactory()
        expected2 = SiteProfileFactory()
        ResultFactory(indicator=self.indicator, sites=[expected, expected2])
        sites = self.program.get_sites()

        IndicatorFactory.create_batch(3)
        ResultFactory.create_batch(3)
        SiteProfileFactory.create_batch(3)

        self.assertEqual(len(sites), 2)
        self.assertEqual(len(SiteProfile.objects.all()), 5)
예제 #3
0
 def test_has_one_site_pk(self):
     i = RFIndicatorFactory(
         program=RFProgramFactory(), target_frequency=Indicator.LOP,
         targets=1000, results=True)
     site = SiteProfileFactory()
     i.result_set.first().site.add(site)
     data = get_serialized_data(i.pk)
     self.assertEqual(data['site_pks'], [site.pk])
 def test_site_count_non_zero(self):
     p = RFProgramFactory()
     i = RFIndicatorFactory(
         program=p, target_frequency=Indicator.LOP, targets=1000,
         results=800, results__count=10
     )
     for result in i.result_set.all():
         result.site.add(
             SiteProfileFactory()
         )
     i2 = RFIndicatorFactory(
         program=p, target_frequency=Indicator.ANNUAL, targets=50,
         results=80, results__count=3
     )
     for result in i2.result_set.all():
         result.site.add(
             SiteProfileFactory()
         )
     data = ProgramPageProgramSerializer.get_for_pk(p.pk).data
     self.assertEqual(data['site_count'], 13)
예제 #5
0
 def test_one_site(self):
     program = RFProgramFactory()
     site = SiteProfileFactory()
     indicator = RFIndicatorFactory(program=program,
                                    target_frequency=Indicator.LOP,
                                    targets=500,
                                    results=100,
                                    results__count=1)
     indicator.result_set.first().site.add(site)
     data = get_serialized_data(program.pk)
     self.assertEqual(len(data['sites']), 1)
     self.assertEqual(data['sites'][0]['pk'], site.pk)
     self.assertEqual(data['sites'][0]['name'], site.name)
예제 #6
0
 def test_multiple_sites(self):
     program = RFProgramFactory()
     site = SiteProfileFactory(name='One')
     site1 = SiteProfileFactory(name='Two')
     site2 = SiteProfileFactory(name='Three')
     indicator = RFIndicatorFactory(program=program,
                                    target_frequency=Indicator.LOP,
                                    targets=500,
                                    results=400,
                                    results__count=2)
     for result, this_site in zip(indicator.result_set.all(),
                                  [site, site1]):
         result.site.add(this_site)
     indicator = RFIndicatorFactory(program=program,
                                    target_frequency=Indicator.LOP,
                                    targets=500,
                                    results=400,
                                    results__count=2)
     for result in indicator.result_set.all():
         result.site.add(site2)
     data = get_serialized_data(program.pk)
     self.assertEqual(len(data['sites']), 3)
     self.assertEqual(set(std['pk'] for std in data['sites']),
                      set([site.pk, site1.pk, site2.pk]))
예제 #7
0
 def test_rf_program_two_indicators(self):
     p = RFProgramFactory(tiers=['Tier1', 'Tier2'],
                          levels=1,
                          reporting_period_start=datetime.date(2014, 5, 1))
     site = SiteProfileFactory()
     it = IndicatorTypeFactory()
     sector = SectorFactory()
     indicators = [
         RFIndicatorFactory(program=p,
                            level=level,
                            target_frequency=Indicator.LOP,
                            targets=500,
                            results=400) for level in p.levels.all()
     ]
     levels = sorted(p.levels.all(), key=lambda l: l.level_depth)
     level_pks = [{
         'pk': level.pk,
         'indicator_pks': [indicator.pk]
     } for level, indicator in zip(levels, indicators)]
     indicators[0].indicator_type.add(it)
     indicators[1].sector = sector
     indicators[1].save()
     indicators[0].result_set.first().site.add(site)
     indicators[1].result_set.first().site.add(site)
     with self.assertNumQueries(IPTT_QUERY_COUNT):
         data = get_serialized_data(p.pk)
     self.assertEqual(data['pk'], p.pk)
     self.assertEqual(data['name'], p.name)
     self.assertTrue(data['results_framework'])
     self.assertEqual(data['by_result_chain'], 'by Tier2 chain')
     self.assertEqual(data['reporting_period_start_iso'], '2014-05-01')
     self.assertEqual(data['frequencies'], [Indicator.LOP])
     self.assertEqual(data['sites'], [{'pk': site.pk, 'name': site.name}])
     self.assertEqual(data['sectors'], [{
         'pk': sector.pk,
         'name': sector.sector
     }])
     self.assertEqual(data['indicator_types'], [{
         'pk': it.pk,
         'name': it.indicator_type
     }])
     self.assertEqual(data['unassigned_indicator_pks'], [])
     self.assertEqual(data['level_pks_level_order'], [l.pk for l in levels])
     self.assertEqual(data['level_pks_chain_order'], [l.pk for l in levels])
     self.assertEqual(data['indicator_pks_for_level'], level_pks)
예제 #8
0
 def test_one_site_duplicated(self):
     program = RFProgramFactory()
     site = SiteProfileFactory()
     indicator = RFIndicatorFactory(program=program,
                                    target_frequency=Indicator.LOP,
                                    targets=500,
                                    results=200,
                                    results__count=2)
     for result in indicator.result_set.all():
         result.site.add(site)
     indicator = RFIndicatorFactory(program=program,
                                    target_frequency=Indicator.LOP,
                                    targets=500,
                                    results=200,
                                    results__count=2)
     for result in indicator.result_set.all():
         result.site.add(site)
     data = get_serialized_data(program.pk)
     self.assertEqual(len(data['sites']), 1)
예제 #9
0
 def test_rollups(self):
     p = RFProgramFactory()
     incomplete_i = RFIndicatorFactory(
         program=p, target_frequency=Indicator.MONTHLY, targets=300
     )
     incomplete_i.periodictargets.order_by('-end_date').first().delete()
     targets_i = RFIndicatorFactory(
         program=p, target_frequency=Indicator.QUARTERLY, targets=400
     )
     results_i = RFIndicatorFactory(
         program=p, target_frequency=Indicator.SEMI_ANNUAL, targets=400,
         results=200, results__count=10
     )
     sites = itertools.cycle([SiteProfileFactory() for _ in range(8)])
     for result in results_i.result_set.all():
         result.site.add(next(sites))
     evidence_i = RFIndicatorFactory(
         program=p, target_frequency=Indicator.ANNUAL, targets=40,
         results=100, results__count=12, results__evidence=8
     )
     for result in evidence_i.result_set.all():
         result.site.add(next(sites))
     evidence_i2 = RFIndicatorFactory(
         program=p, target_frequency=Indicator.ANNUAL, targets=40,
         results=10, results__count=4, results__evidence=4
     )
     with self.assertNumQueries(4):
         data = ProgramPageProgramSerializer.get_for_pk(p.pk).data
     self.assertTrue(data['needs_additional_target_periods'])
     self.assertEqual(data['site_count'], 8)
     self.assertFalse(data['indicators'][incomplete_i.pk]['has_all_targets_defined'])
     self.assertTrue(data['indicators'][targets_i.pk]['has_all_targets_defined'])
     self.assertFalse(data['indicators'][targets_i.pk]['has_results'])
     self.assertEqual(data['indicators'][results_i.pk]['results_count'], 10)
     self.assertTrue(data['indicators'][results_i.pk]['has_results'])
     self.assertEqual(data['indicators'][evidence_i.pk]['results_with_evidence_count'], 8)
     self.assertTrue(data['indicators'][evidence_i.pk]['missing_evidence'])
     self.assertFalse(data['indicators'][evidence_i2.pk]['missing_evidence'])