def test_lop_and_midend_just_mid_reporting(self):
     self.get_closed_program()
     indicator_lop = i_factories.IndicatorFactory(
         target_frequency=Indicator.LOP,
         lop_target=1000,
         program=self.program)
     lop_data = i_factories.CollectedDataFactory(
         indicator=indicator_lop,
         achieved=400,
         date_collected=self.program.reporting_period_end -
         datetime.timedelta(days=10))
     indicator_midend = i_factories.IndicatorFactory(
         target_frequency=Indicator.MID_END, program=self.program)
     mid_target = i_factories.PeriodicTargetFactory(
         indicator=indicator_midend,
         period=PeriodicTarget.MIDLINE,
         target=1000)
     mid_data = i_factories.CollectedDataFactory(
         indicator=indicator_midend,
         periodic_target=mid_target,
         achieved=400,
         date_collected=self.program.reporting_period_start +
         datetime.timedelta(days=20))
     for indicator in MetricsIndicator.objects.with_annotations(
             'reporting').all():
         self.assertTrue(indicator.reporting)
 def setUp(self):
     for _ in range(10):
         program = w_factories.ProgramFactory(
             reporting_period_start=datetime.date(2014, 1, 1),
             reporting_period_end=datetime.date(2014, 12, 31))
         for _ in range(5):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.LOP,
                 lop_target=100,
                 program=program)
             i_factories.CollectedDataFactory(indicator=indicator,
                                              achieved=105)
         for _ in range(5):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.LOP,
                 lop_target=100,
                 program=program)
             evidence = w_factories.DocumentationFactory(program=program)
             i_factories.CollectedDataFactory(indicator=indicator,
                                              achieved=50,
                                              evidence=evidence)
         for _ in range(2):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.LOP, program=program)
         for _ in range(4):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.MID_END, program=program)
             for sort in range(2):
                 i_factories.PeriodicTargetFactory(
                     indicator=indicator,
                     target=40,
                     start_date=datetime.date(2014, 5, 1),
                     end_date=datetime.date(2014, 8, 1),
                     customsort=sort)
 def setUpTestData(cls):
     program = w_factories.ProgramFactory(
         funding_status="funded",
         name="Test program name",
         reporting_period_start=datetime.date(2015, 1, 1),
         reporting_period_end=datetime.date(2017, 12, 31),
         _using_results_framework=Program.MIGRATED,
         auto_number_indicators=True
     )
     i_factories.LevelTierFactory(
         program=program,
         tier_depth=1,
         name="Test Tier 1"
     )
     i_factories.LevelTierFactory(
         program=program,
         tier_depth=2,
         name="Test Tier 2"
     )
     level = i_factories.LevelFactory(
         program=program,
         name="Test Output Level",
         customsort=1,
         parent=i_factories.LevelFactory(
             name="Test Goal Level",
             program=program,
             customsort=1,
             parent=None,
         ),
         assumptions=', '.join(['assuming']*10)
     )
     indicators = [
         i_factories.IndicatorFactory(
             pk=21,
             program=program,
             level=level,
             level_order=0,
             means_of_verification=None,
             number="1.23a"
         ),
         i_factories.IndicatorFactory(
             pk=22,
             program=program,
             level=level,
             level_order=1,
             means_of_verification="some means here",
             number="2.444ab"
         ),
         i_factories.IndicatorFactory(
             pk=23,
             program=program,
             level=None,
             level_order=1,
             means_of_verification=', '.join(["some means here"]*10),
             number="4.444asdf"
         )
     ]
     cls.program = program
     cls.level = level
     cls.indicators = indicators
 def test_lop_and_midend_just_mid_reporting(self):
     self.get_closed_program()
     indicator_lop = i_factories.IndicatorFactory(
         target_frequency=Indicator.LOP,
         lop_target=1000,
         program=self.program
     )
     lop_data = i_factories.CollectedDataFactory(
         indicator=indicator_lop,
         achieved=400,
         date_collected=self.program.reporting_period_end - datetime.timedelta(days=10)
     )
     indicator_midend = i_factories.IndicatorFactory(
         target_frequency=Indicator.MID_END,
         program=self.program
     )
     mid_target = i_factories.PeriodicTargetFactory(
         indicator=indicator_midend,
         period=PeriodicTarget.MIDLINE,
         target=1000
     )
     mid_data = i_factories.CollectedDataFactory(
         indicator=indicator_midend,
         periodic_target=mid_target,
         achieved=400,
         date_collected=self.program.reporting_period_start + datetime.timedelta(days=20)
     )
     program = self.get_annotated_program()
     self.assertEqual(program.scope_counts['nonreporting_count'], 0)
     self.assertEqual(program.scope_counts['indicator_count'], 2)
Пример #5
0
 def test_program_with_multiple_indicators_returns_correct_date(self):
     program = w_factories.ProgramFactory(
         reporting_period_start=datetime.date(2015, 1, 1),
         reporting_period_end=datetime.date(2015, 12, 31)
     )
     indicator1 = i_factories.IndicatorFactory(
         target_frequency=Indicator.ANNUAL,
         program=program
     )
     i_factories.PeriodicTargetFactory(
         indicator=indicator1,
         start_date=datetime.date(2015, 1, 1),
         end_date=datetime.date(2015, 12, 31)
     )
     indicator2 = i_factories.IndicatorFactory(
         target_frequency=Indicator.TRI_ANNUAL,
         program=program
     )
     for start, end in [(datetime.date(2015, 1, 1), datetime.date(2015, 4, 30)),
                        (datetime.date(2015, 5, 1), datetime.date(2015, 8, 31)),
                        (datetime.date(2015, 9, 1), datetime.date(2015, 12, 31))]:
         i_factories.PeriodicTargetFactory(
             indicator=indicator2,
             start_date=start,
             end_date=end
         )
     self.assertEqual(program.last_time_aware_indicator_start_date, datetime.date(2015, 9, 1))
    def add_indicators(self):
        self.indicator_in_country = i_factories.IndicatorFactory(
            program=self.program_in_country, target_frequency=Indicator.LOP)
        self.indicator_out_of_country = i_factories.IndicatorFactory(
            program=self.program_out_of_country,
            target_frequency=Indicator.LOP)

        self.indicator_in_country_target_frequency_type_event = i_factories.IndicatorFactory(
            program=self.program_in_country, target_frequency=Indicator.EVENT)

        self.indicator_out_of_country_target_frequency_type_event = i_factories.IndicatorFactory(
            program=self.program_out_of_country,
            target_frequency=Indicator.EVENT)
Пример #7
0
 def setUp(self):
     program = get_open_program()
     indicator = i_factories.IndicatorFactory(
         program=program,
         target_frequency=Indicator.MID_END,
         unit_of_measure_type=Indicator.PERCENTAGE,
         lop_target=60)
     targets = [
         i_factories.PeriodicTargetFactory(indicator=indicator,
                                           customsort=0,
                                           start_date=None,
                                           end_date=None,
                                           target=80),
         i_factories.PeriodicTargetFactory(indicator=indicator,
                                           customsort=1,
                                           start_date=None,
                                           end_date=None,
                                           target=65)
     ]
     results = [
         i_factories.ResultFactory(indicator=indicator,
                                   periodic_target=targets[0],
                                   date_collected=datetime.date(2018, 1, 1),
                                   achieved=75),
         i_factories.ResultFactory(indicator=indicator,
                                   periodic_target=targets[0],
                                   date_collected=datetime.date(2018, 2, 1),
                                   achieved=70)
     ]
     self.results_indicator = ResultsIndicator.results_view.get(
         pk=indicator.pk)
     self.metrics_indicator = MetricsIndicator.objects.with_annotations(
         'scope').get(pk=indicator.pk)
 def test_start_date_does_change_if_no_time_aware_target_set(self):
     program = w_factories.ProgramFactory(
         reporting_period_start=datetime.date(2015, 1, 1),
         reporting_period_end=datetime.date(2017, 12, 31)
     )
     indicator = i_factories.IndicatorFactory(
         target_frequency=Indicator.MID_END,
         program=program
     )
     i_factories.PeriodicTargetFactory(
         start_date=None,
         end_date=None,
         customsort=0,
         indicator=indicator
     )
     response = self.client.post(reverse('reportingperiod_update', kwargs={'pk': program.pk}),
                                 {'reporting_period_start': '2016-01-01',
                                  'reporting_period_end': '2017-12-31',
                                  'rationale': 'test'})
     self.assertEqual(json.loads(response.content)['msg'], 'success')
     self.assertEqual(len(json.loads(response.content)['failmsg']), 0)
     self.assertEqual(response.status_code, 200)
     refreshed = Program.objects.get(pk=program.pk)
     self.assertEqual(refreshed.reporting_period_start, datetime.date(2016, 1, 1))
     self.assertEqual(refreshed.reporting_period_end, datetime.date(2017, 12, 31))
 def test_end_date_will_change_to_after_last_time_aware_target_set(self):
     program = w_factories.ProgramFactory(
         reporting_period_start=datetime.date(2015, 1, 1),
         reporting_period_end=datetime.date(2017, 12, 31)
     )
     indicator = i_factories.IndicatorFactory(
         target_frequency=Indicator.ANNUAL,
         program=program
     )
     for start, end in [(datetime.date(2015, 1, 1), datetime.date(2015, 12, 31)),
                        (datetime.date(2016, 1, 1), datetime.date(2016, 12, 31)),
                        (datetime.date(2017, 1, 1), datetime.date(2017, 12, 31))]:
         i_factories.PeriodicTargetFactory(
             start_date=start,
             end_date=end,
             indicator=indicator
         )
     response = self.client.post(reverse('reportingperiod_update', kwargs={'pk': program.pk}),
                                 {'reporting_period_start': '2015-01-01',
                                  'reporting_period_end': '2017-10-31',
                                  'rationale': 'test'})
     self.assertEqual(json.loads(response.content)['msg'], 'success')
     self.assertEqual(len(json.loads(response.content)['failmsg']), 0)
     self.assertEqual(response.status_code, 200)
     refreshed = Program.objects.get(pk=program.pk)
     self.assertEqual(refreshed.reporting_period_start, datetime.date(2015, 1, 1))
     self.assertEqual(refreshed.reporting_period_end, datetime.date(2017, 10, 31))
 def setUp(self):
     self.program = w_factories.ProgramFactory(
         reporting_period_start=datetime.date(2016, 10, 1),
         reporting_period_end=datetime.date(2017, 9, 30))
     self.indicator = i_factories.IndicatorFactory(program=self.program)
     self.targets = []
     self.data = []
Пример #11
0
 def get_indicators(self):
     for c, kwargs in enumerate(self.indicator_kwargs):
         indicator = i_factories.IndicatorFactory(program=self.program,
                                                  number=c,
                                                  **kwargs['indicator'])
         for target_kwargs, period in zip(kwargs['targets'],
                                          self.program.get_periods_for_frequency(indicator.target_frequency)):
             target = i_factories.PeriodicTargetFactory(
                 indicator=indicator,
                 target=target_kwargs['target'],
                 start_date=period['start'],
                 end_date=period['end'],
                 customsort=period['customsort']
             )
             for date_collected, achieved in target_kwargs['results']:
                 i_factories.ResultFactory(
                     periodic_target=target,
                     indicator=indicator,
                     date_collected=date_collected,
                     achieved=achieved
                 )
         for date_collected, achieved in kwargs['results']:
             i_factories.ResultFactory(
                 indicator=indicator,
                 date_collected=date_collected,
                 achieved=achieved
             )
 def setUp(self):
     for _ in range(10):
         program = w_factories.ProgramFactory(
             reporting_period_start=datetime.date(2014, 1, 1),
             reporting_period_end=datetime.date(2014, 12, 31))
         for _ in range(5):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.LOP,
                 lop_target=100,
                 program=program)
             target = i_factories.PeriodicTargetFactory(
                 indicator=indicator,
                 target=indicator.lop_target,
                 start_date=indicator.program.reporting_period_start,
                 end_date=indicator.program.reporting_period_end)
             i_factories.ResultFactory(indicator=indicator,
                                       periodic_target=target,
                                       achieved=105)
         for _ in range(5):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.LOP,
                 lop_target=100,
                 program=program)
             target = i_factories.PeriodicTargetFactory(
                 indicator=indicator,
                 target=indicator.lop_target,
                 start_date=indicator.program.reporting_period_start,
                 end_date=indicator.program.reporting_period_end)
             i_factories.ResultFactory(
                 indicator=indicator,
                 periodic_target=target,
                 achieved=50,
                 evidence_url='http://test_evidence_url')
         for _ in range(2):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.LOP, program=program)
         for _ in range(4):
             indicator = i_factories.IndicatorFactory(
                 target_frequency=Indicator.MID_END, program=program)
             for sort in range(2):
                 i_factories.PeriodicTargetFactory(
                     indicator=indicator,
                     target=40,
                     start_date=datetime.date(2014, 5, 1),
                     end_date=datetime.date(2014, 8, 1),
                     customsort=sort)
Пример #13
0
 def get_indicator(self):
     return i_factories.IndicatorFactory(
         program=self.program,
         target_frequency=self.target_frequency,
         unit_of_measure_type=self.unit_of_measure_type,
         direction_of_change=self.direction_of_change,
         is_cumulative=self.is_cumulative,
         lop_target=self.lop_target)
def get_one_target_defined_indicator(program):
    indicator = i_factories.IndicatorFactory(program=program,
                                             target_frequency=Indicator.ANNUAL)
    i_factories.PeriodicTargetFactory(indicator=indicator,
                                      start_date=datetime.date(2015, 1, 1),
                                      end_date=datetime.date(2015, 12, 31),
                                      target=100)
    return indicator
Пример #15
0
 def add_non_lop_indicator(self, program):
     indicator = i_factory.IndicatorFactory(
         target_frequency=Indicator.ANNUAL, lop_target=100, program=program)
     i_factory.PeriodicTargetFactory(
         indicator=indicator,
         target=100,
         start_date=program.reporting_period_start,
         end_date=program.reporting_period_end)
     return indicator
 def test_multiple_time_aware_indicators(self):
     self.get_closed_program()
     for frequency in self.TIME_AWARE_FREQUENCIES:
         indicator = i_factories.IndicatorFactory(
             target_frequency=frequency, program=self.program)
         self.load_targets(indicator=indicator)
         self.load_data(indicator=indicator)
     for indicator in MetricsIndicator.objects.with_annotations(
             'reporting').all():
         self.assertTrue(indicator.reporting)
Пример #17
0
def get_programs_for_country(country):
    two_indicator_program = w_factories.ProgramFactory(
        funding_status="Funded",
        reporting_period_start=start_date,
        reporting_period_end=end_date)
    two_indicator_program.country.set([country])
    one_indicator_program = w_factories.ProgramFactory(
        funding_status="Funded",
        reporting_period_start=start_date,
        reporting_period_end=end_date)
    one_indicator_program.country.set([country])
    zero_indicator_program = w_factories.ProgramFactory(
        funding_status="Funded",
        reporting_period_start=start_date,
        reporting_period_end=end_date)
    zero_indicator_program.country.set([country])
    i_factories.IndicatorFactory(program=two_indicator_program)
    i_factories.IndicatorFactory(program=two_indicator_program)
    i_factories.IndicatorFactory(program=one_indicator_program)
    return two_indicator_program.id, one_indicator_program.id, zero_indicator_program.id
Пример #18
0
 def add_annual_indicators(self, program, dates):
     indicator = i_factory.IndicatorFactory(
         target_frequency=Indicator.ANNUAL, lop_target=100, program=program)
     for c, start_date in enumerate(dates):
         end_date = start_date + datetime.timedelta(days=364)
         i_factory.PeriodicTargetFactory(indicator=indicator,
                                         target=100,
                                         customsort=c,
                                         start_date=start_date,
                                         end_date=end_date)
     return indicator
Пример #19
0
 def test_program_with_non_time_aware_indicators_returns_none(self):
     for frequency in [Indicator.LOP, Indicator.MID_END, Indicator.EVENT]:
         program = w_factories.ProgramFactory(
             reporting_period_start=datetime.date(2015, 1, 1),
             reporting_period_end=datetime.date(2017, 12, 31)
         )
         i_factories.IndicatorFactory(
             target_frequency=frequency,
             program=program
         )
         self.assertIsNone(program.last_time_aware_indicator_start_date)
Пример #20
0
 def test_program_with_all_indicators_returns_true(self):
     program = w_factories.ProgramFactory(
         reporting_period_start=datetime.date(2015, 1, 1),
         reporting_period_end=datetime.date(2017, 12, 31)
     )
     for frequency, _ in Indicator.TARGET_FREQUENCIES:
         i_factories.IndicatorFactory(
             target_frequency=frequency,
             program=program
         )
     self.assertTrue(program.has_time_aware_targets)
 def test_multiple_time_aware_indicators(self):
     self.get_closed_program()
     for frequency in self.TIME_AWARE_FREQUENCIES:
         indicator = i_factories.IndicatorFactory(
             target_frequency=frequency,
             program=self.program
         )
         self.load_targets(indicator=indicator)
         self.load_data(indicator=indicator)
     program = self.get_annotated_program()
     self.assertEqual(program.scope_counts['nonreporting_count'], 0)
     self.assertEqual(program.scope_counts['indicator_count'], len(self.TIME_AWARE_FREQUENCIES))
Пример #22
0
 def add_midend_indicator(self, program):
     indicator = i_factory.IndicatorFactory(
         target_frequency=Indicator.MID_END,
         lop_target=100,
         program=program)
     i_factory.PeriodicTargetFactory(indicator=indicator,
                                     target=100,
                                     start_date=datetime.date(2015, 1, 1),
                                     end_date=datetime.date(2015, 6, 30),
                                     customsort=0)
     i_factory.PeriodicTargetFactory(indicator=indicator,
                                     target=100,
                                     start_date=datetime.date(2015, 7, 1),
                                     end_date=datetime.date(2015, 12, 31),
                                     customsort=1)
     return indicator
    def setUp(self):
        self.program = w_factories.ProgramFactory()
        self.indicator = i_factories.IndicatorFactory(program=self.program)
        self.result = i_factories.ResultFactory(indicator=self.indicator)
        self.user = w_factories.UserFactory(first_name="FN",
                                            last_name="LN",
                                            username="******",
                                            is_superuser=True)
        self.user.set_password('password')
        self.user.save()

        self.tola_user = w_factories.TolaUserFactory(user=self.user)
        self.tola_user.save()

        self.client = test.Client(enforce_csrf_checks=False)
        self.client.login(username='******', password='******')
    def setUp(self):
        self.program = w_factories.ProgramFactory()
        self.indicator = i_factories.IndicatorFactory(
            program=self.program, target_frequency=Indicator.ANNUAL)
        self.result = i_factories.ResultFactory(indicator=self.indicator, )
        self.result.record_name = 'record name'
        self.result.evidence_url = 'evidence url'

        self.blank_result = i_factories.ResultFactory(indicator=self.indicator)

        self.tola_user = w_factories.TolaUserFactory()
        self.user = self.tola_user.user
        self.request = type('Request', (object, ), {
            'has_write_access': True,
            'user': self.user
        })()
    def setUp(self):
        self.program = w_factories.ProgramFactory(
            reporting_period_start=datetime.date(2016, 1, 1),
            reporting_period_end=datetime.date(2016, 12, 31),
        )
        self.indicator = i_factories.IndicatorFactory(
            program=self.program, target_frequency=Indicator.LOP)
        self.tola_user = w_factories.TolaUserFactory()
        self.user = self.tola_user.user

        self.request = type('Request', (object, ), {
            'has_write_access': True,
            'user': self.user
        })()
        self.form_kwargs = {
            'user': self.user,
            'indicator': self.indicator,
            'program': self.program,
            'request': self.request,
        }
Пример #26
0
 def get_indicator_for_program(self, **kwargs):
     kwargs['program'] = self.program
     return i_factories.IndicatorFactory(**kwargs)
 def get_indicator(self):
     return i_factories.IndicatorFactory(program=self.program,
                                         target_frequency=Indicator.LOP,
                                         lop_target=1000)
 def get_indicator(self, frequency=Indicator.LOP):
     indicator = i_factories.IndicatorFactory(target_frequency=frequency,
                                              program=self.program)
     self.indicators.append(indicator)
     return indicator
 def load_base_indicator(self):
     """loads a bare indicator in this program"""
     self.indicator = i_factories.IndicatorFactory()
     if self.program is not None:
         self.indicator.program = self.program
         self.indicator.save()
Пример #30
0
 def get_indicator(self):
     return i_factories.IndicatorFactory()