class TestBase(object): fixtures = ['indicatortype.json', 'levels.json'] def setUp(self): self.user = UserFactory(first_name="Indicator", last_name="CreateTest", username="******") self.user.set_password('password') self.user.save() self.tola_user = TolaUserFactory(user=self.user) self.country = self.tola_user.country self.program = ProgramFactory(funding_status='Funded', reporting_period_start='2016-03-01', reporting_period_end='2020-05-01') self.program.country.add(self.country) self.program.save() self.indicator = IndicatorFactory( program=self.program, unit_of_measure_type=Indicator.NUMBER, is_cumulative=False, direction_of_change=Indicator.DIRECTION_OF_CHANGE_NONE, target_frequency=Indicator.ANNUAL) self.request_factory = RequestFactory() self.client = Client() self.client.login(username="******", password='******')
class PinnedReportTestCase(TestCase): """ Set up some base entities in the DB """ def setUp(self): self.user = UserFactory(first_name="PeterPeter", last_name="PumpkinEater", username="******") self.user.set_password('orangethumb') self.user.save() self.tola_user = TolaUserFactory(user=self.user) self.country = self.tola_user.country self.program = ProgramFactory( funding_status='Funded', reporting_period_start='2016-03-01', reporting_period_end='2020-05-01') self.program.country.add(self.country) self.program.save() # TolaUser not available on User if not logged in self.client.login(username=self.user.username, password='******')
class TestIPTTReportviewURL(test.TestCase): def setUp(self): self.user = UserFactory(first_name="PeterPeter", last_name="PumpkinEater", username="******") self.user.set_password('orangethumb') self.user.save() self.tola_user = TolaUserFactory(user=self.user) self.country = self.tola_user.country self.program = ProgramFactory(funding_status='Funded', reporting_period_start='2016-03-01', reporting_period_end='2020-05-01') self.program.country.add(self.country) self.program.save() self.indicator = IndicatorFactory( program=self.program, unit_of_measure_type=Indicator.NUMBER, is_cumulative=False, direction_of_change=Indicator.DIRECTION_OF_CHANGE_NONE, target_frequency=Indicator.ANNUAL) self.request_factory = test.RequestFactory() self.client = test.Client() self.client.login(username=self.user.username, password='******') def test_get(self): """Does get return 200 and the right template?""" url_kwargs = { 'program': self.program.id, 'reporttype': 'targetperiods', } filterdata = {'frequency': 3, 'timeframe': 1} path = reverse_lazy('iptt_report', kwargs=url_kwargs) response = self.client.get(path, data=filterdata, follow=True) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, template_name=IPTTReport.template_name)
class TestIPTTTimePeriodsReportResponseBase(test.TestCase): timeperiods = Indicator.ANNUAL def setUp(self): self.user = UserFactory(first_name="FN", last_name="LN", username="******", is_superuser=True) self.user.set_password('password') self.user.save() self.tola_user = TolaUserFactory(user=self.user) self.tola_user.save() self.client = test.Client(enforce_csrf_checks=False) self.client.login(username='******', password='******') self.response = None startdate = datetime.strptime('2017-02-04', '%Y-%m-%d') enddate = datetime.strptime('2019-10-01', '%Y-%m-%d') self.program = ProgramFactory(reporting_period_start=startdate, reporting_period_end=enddate) self.request_params = { 'csrfmiddlewaretoken': 'asdf', 'program': self.program.id } def tearDown(self): Indicator.objects.all().delete() self.response = None def set_dates(self, start, end): self.program.reporting_period_start = datetime.strptime( start, '%Y-%m-%d') self.program.reporting_period_end = datetime.strptime(end, '%Y-%m-%d') self.program.save() def get_indicator_for_program(self, **kwargs): make_kwargs = {'program': self.program} make_kwargs.update(kwargs) indicator = IndicatorFactory(**make_kwargs) return indicator def add_indicator(self, frequency=Indicator.ANNUAL, **kwargs): kwargs['target_frequency'] = frequency return self.get_indicator_for_program(**kwargs) def add_indicator_with_data(self, frequency, values): indicator = self.add_indicator(frequency=frequency) collect_date = self.program.reporting_period_start + timedelta(days=1) for value in values: _ = ResultFactory(indicator=indicator, date_collected=collect_date, achieved=value) if frequency == Indicator.ANNUAL: collect_date = datetime(collect_date.year + 1, collect_date.month, collect_date.day) elif frequency == Indicator.SEMI_ANNUAL: collect_date = datetime( collect_date.year if collect_date.month < 7 else collect_date.year + 1, collect_date.month + 6 if collect_date.month < 7 else collect_date.month - 6, collect_date.day) elif frequency == Indicator.TRI_ANNUAL: collect_date = datetime( collect_date.year if collect_date.month < 9 else collect_date.year + 1, collect_date.month + 4 if collect_date.month < 9 else collect_date.month - 8, collect_date.day) elif frequency == Indicator.QUARTERLY: collect_date = datetime( collect_date.year if collect_date.month < 10 else collect_date.year + 1, collect_date.month + 3 if collect_date.month < 10 else collect_date.month - 9, collect_date.day) elif frequency == Indicator.MONTHLY: collect_date = datetime( collect_date.year if collect_date.month < 12 else collect_date.year + 1, collect_date.month + 1 if collect_date.month < 12 else collect_date.month - 11, collect_date.day) def get_showall_response(self): self.request_params['timeframe'] = 1 self.request_params['numrecentperiods'] = None return self.get_response() def get_recent_periods(self, numrecent): self.request_params['timeframe'] = 2 self.request_params['numrecentperiods'] = numrecent return self.get_response() def get_date_range_periods(self, start, end): self.request_params['start_period'] = start.strftime( '%Y-%m-%d') if isinstance(start, datetime) else start self.request_params['end_period'] = end.strftime( '%Y-%m-%d') if isinstance(end, datetime) else end return self.get_response() def get_response(self, reporttype=IPTT_Mixin.REPORT_TYPE_TIMEPERIODS): self.request_params['timeperiods'] = self.timeperiods response = self.client.post( '/indicators/iptt_report/{program}/{reporttype}/'.format( program=self.program.id, reporttype=reporttype), self.request_params, follow=True) self.assertEqual( response.status_code, 200, "response gave status code {0} instead of 200".format( response.status_code)) self.response = IPTTResponse(response.content, timeperiods=True) return self.response def get_indicator_results(self, response, indicator_row=0): indicator = response.indicators[indicator_row]['ranges'] return indicator[0], indicator[1:] def format_assert_message(self, msg): return "{0}:\n{1} timeperiods, {2}".format(self.response, { k: v for k, v in Indicator.TARGET_FREQUENCIES }[self.timeperiods], msg) def number_of_ranges_test(self, start, end, expected_ranges): self.set_dates(start, end) self.add_indicator() response = self.get_showall_response() ranges = response.indicators[0]['ranges'][1:] self.assertEqual( len(ranges), expected_ranges, self.format_assert_message( "expected {0} ranges for {1} to {2}, got {3}".format( expected_ranges, start, end, len(ranges))))
class IPTTReportQuickstartViewTests(TestCase): """Unit tests to valid the IPTTReportQuickStartView""" def setUp(self): self.user = UserFactory(first_name="Indicator", last_name="CreateTest", username="******") self.user.set_password('password') self.user.save() self.tola_user = TolaUserFactory(user=self.user) self.country = self.tola_user.country self.program = ProgramFactory(funding_status='Funded', reporting_period_start='2016-03-01', reporting_period_end='2020-05-01') self.program.country.add(self.country) self.program.save() self.indicator = IndicatorFactory( program=self.program, unit_of_measure_type=Indicator.NUMBER, is_cumulative=False, direction_of_change=Indicator.DIRECTION_OF_CHANGE_NONE, target_frequency=Indicator.ANNUAL) lop_indicator = IndicatorFactory(program=self.program, target_frequency=Indicator.LOP) self.request_factory = RequestFactory() self.client = Client() self.client.login(username="******", password='******') def test_page_load_returns_200(self): """Do we return 200?""" response = self.client.get(reverse_lazy('iptt_quickstart')) self.assertEqual(response.status_code, 200) def test_page_load_does_not_redirect(self): """This page should not redirect""" response = self.client.get(reverse_lazy('iptt_quickstart'), follow=True) self.assertEqual(len(response.redirect_chain), 0) def test_page_loads_correct_template(self): """Do we load the right template?""" response = self.client.get(reverse_lazy('iptt_quickstart'), follow=True) self.assertTemplateUsed(response, 'indicators/iptt_quickstart.html') self.assertContains(response, 'Indicator Performance Tracking Table') def test_get_form_kwargs(self): """Do we get the correct form kwargs?""" data = { 'csrfmiddlewaretoken': 'lolwut', 'targetperiods-program': self.program.id, 'targetperiods-formprefix': IPTTReportQuickstartView.FORM_PREFIX_TARGET, 'targetperiods-timeframe': Indicator.LOP, 'targetperiods-targetperiods': 1, 'targetperiods-numrecentperiods': 1, } path = reverse_lazy('iptt_quickstart') response = self.client.post(path, data=data, follow=True) kwargs = response.resolver_match.kwargs self.assertEqual(kwargs['reporttype'], IPTTReportQuickstartView.FORM_PREFIX_TARGET) self.assertEqual(int(kwargs['program_id']), self.program.id) def test_get_context_data(self): """Do we get the correct context data?""" data = { 'csrfmiddlewaretoken': 'lolwut', 'targetperiods-program': self.program.id, 'targetperiods-formprefix': IPTTReportQuickstartView.FORM_PREFIX_TARGET, 'targetperiods-timeframe': Indicator.LOP, 'targetperiods-targetperiods': 1, 'targetperiods-numrecentperiods': 1, } path = reverse_lazy('iptt_quickstart') response = self.client.post(path, data=data, follow=True) context_data = response.context_data self.assertEqual(int(context_data['program_id']), self.program.id) # self.assertEqual(context['report_wide'], ?) # self.assertEqual(context['report_date_ranges'], ?) # self.assertEqual(context['indicators'], ?) self.assertRegex(str(context_data['program']), self.program.name) self.assertEqual(str(context_data['reporttype']), IPTTReportQuickstartView.FORM_PREFIX_TARGET) self.assertEqual(str(context_data['report_end_date']), self.program.reporting_period_end) self.assertEqual(str(context_data['report_end_date_actual']), self.program.reporting_period_end) self.assertEqual(str(context_data['report_start_date']), self.program.reporting_period_start) def test_post_with_valid_form(self): """Does POSTing to iptt_quickstart with valid form data redirect to the correct view (iptt_report)?""" data = { 'csrfmiddlewaretoken': 'lolwut', 'targetperiods-program': self.program.id, 'targetperiods-formprefix': IPTTReportQuickstartView.FORM_PREFIX_TARGET, 'targetperiods-timeframe': Indicator.LOP, 'targetperiods-targetperiods': 1, 'targetperiods-numrecentperiods': 1, } path = reverse_lazy('iptt_quickstart') response = self.client.post(path, data=data, follow=True) self.assertEqual(len(response.redirect_chain), 1) self.assertTemplateUsed(response, 'indicators/iptt_report.html') self.assertEqual(response.status_code, 200) def test_post_with_invalid_form(self): """Does POSTing to iptt_quickstart with crap form data leave us at iptt_quickstart?""" path = reverse_lazy('iptt_quickstart') response = self.client.post(path, data={'foo': 'bar'}) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'indicators/iptt_quickstart.html')
class IPTT_ReportViewTests(TestCase): """Unit tests to validate IPTT_ReportView""" def setUp(self): self.user = UserFactory(first_name="PeterPeter", last_name="PumpkinEater", username="******") self.user.set_password('orangethumb') self.user.save() self.tola_user = TolaUserFactory(user=self.user) self.country = self.tola_user.country self.program = ProgramFactory(funding_status='Funded', reporting_period_start='2016-03-01', reporting_period_end='2020-05-01') self.program.country.add(self.country) self.program.save() self.indicator = IndicatorFactory( program=self.program, unit_of_measure_type=Indicator.NUMBER, is_cumulative=False, direction_of_change=Indicator.DIRECTION_OF_CHANGE_NONE, target_frequency=Indicator.ANNUAL) self.request_factory = RequestFactory() self.client = Client() self.client.login(username=self.user.username, password='******') def test_get(self): """Does get return 200 and the right template?""" url_kwargs = { 'program_id': self.program.id, 'reporttype': 'targetperiods', } filterdata = {'targetperiods': 1, 'timeframe': 1} path = reverse_lazy('iptt_report', kwargs=url_kwargs) response = self.client.get(path, data=filterdata, follow=True) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, template_name=IPTT_ReportView.template_name) # Verify that real program and indicator data are present self.assertIn(self.program.name, response.content) self.assertIn(self.indicator.name, response.content) # Dates come out the database as '2016-03-01' # Those dates are formatted as 'Mar 01, 2016' in the content expected_start = datetime.datetime.strptime( self.program.reporting_period_start, '%Y-%m-%d') expected_end = datetime.datetime.strptime( self.program.reporting_period_end, '%Y-%m-%d') # TODO: fails because l10n: self.assertIn(expected_start.strftime('%b %d, %Y'), response.content) # TODO: fails because l10n: self.assertIn(expected_end.strftime('%b %d, %Y'), response.content) def test_post(self): """Does post return 200 show the requested report?""" url_kwargs = { 'program_id': self.program.id, 'reporttype': 'targetperiods', } data = { 'csrfmiddlewaretoken': 'lolwut', 'program': self.program.id, 'targetperiods': 1, 'timeframe': 1, } path = reverse_lazy('iptt_report', kwargs=url_kwargs) response = self.client.post(path, data=data, follow=True) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.redirect_chain), 1) # Verify that real program and indicator data are present self.assertIn(self.program.name, response.content) self.assertIn(self.indicator.name, response.content) # Dates returned as '2016-03-01' # Present in content as 'Mar 01, 2016' exp_start = datetime.datetime.strptime( self.program.reporting_period_start, '%Y-%m-%d') exp_end = datetime.datetime.strptime(self.program.reporting_period_end, '%Y-%m-%d')
class IPTT_MixinTests(TestCase): """Test private methods not specifically tested in other test cases""" freqs = { Indicator.ANNUAL: 12, Indicator.SEMI_ANNUAL: IPTT_Mixin.MONTHS_PER_SEMIANNUAL, Indicator.TRI_ANNUAL: IPTT_Mixin.MONTHS_PER_TRIANNUAL, Indicator.QUARTERLY: IPTT_Mixin.MONTHS_PER_QUARTER, Indicator.MONTHLY: IPTT_Mixin.MONTHS_PER_MONTH, # Indicator.LOP, Indicator.MID_END, Indicator.EVENT } def setUp(self): self.mixin = IPTT_Mixin() self.user = UserFactory(first_name="Indy", last_name="Cater", username="******") self.user.set_password('password') self.user.save() self.tola_user = TolaUserFactory(user=self.user) self.country = self.tola_user.country self.program = ProgramFactory(funding_status='Funded', reporting_period_start='2016-04-01', reporting_period_end='2020-06-01') self.program.country.add(self.country) self.program.save() self.indicator = IndicatorFactory( program=self.program, unit_of_measure_type=Indicator.NUMBER, is_cumulative=False, direction_of_change=Indicator.DIRECTION_OF_CHANGE_NONE, target_frequency=Indicator.LOP) self.request_factory = RequestFactory() self.client = Client() self.client.login(username="******", password='******') def test__get_num_months(self): """Do we return the right number of months per period?""" for freq in IPTT_MixinTests.freqs: num_months_in_period = self.mixin._get_num_months(freq) self.assertEqual(num_months_in_period, IPTT_MixinTests.freqs[freq]) def test__get_num_periods_returns_0_for_reversed_date_range(self): """Do we return if end date is before start date?""" _get_num_periods = IPTT_Mixin._get_num_periods start_date = date(2020, 1, 1) end_date = date(2019, 1, 1) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.ANNUAL), 0) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.SEMI_ANNUAL), 0) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.TRI_ANNUAL), 0) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.QUARTERLY), 0) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.MONTHLY), 0) def test__get_period_name(self): """Do we return the correct period names?""" _get_period_name = IPTT_Mixin._get_period_name self.assertEqual(_get_period_name(Indicator.ANNUAL), "Year") self.assertEqual(_get_period_name(Indicator.SEMI_ANNUAL), "Semi-annual") self.assertEqual(_get_period_name(Indicator.TRI_ANNUAL), "Tri-annual") self.assertEqual(_get_period_name(Indicator.QUARTERLY), "Quarter") self.assertEqual(_get_period_name(Indicator.MONTHLY), "Month") def test__get_first_period(self): """Do we calculate the first period of a date range correctly?""" real_start_date = date(2016, 7, 15) for freq in IPTT_MixinTests.freqs: num_months = self.mixin._get_num_months(freq) _get_first_period = self.mixin._get_first_period( real_start_date, num_months) if freq == Indicator.ANNUAL: self.assertEqual(_get_first_period, date(2016, 1, 1)) elif freq == Indicator.SEMI_ANNUAL: self.assertEqual(_get_first_period, date(2016, 7, 1)) elif freq == Indicator.TRI_ANNUAL: self.assertEqual(_get_first_period, date(2016, 5, 1)) elif freq == Indicator.QUARTERLY: self.assertEqual(_get_first_period, date(2016, 7, 1)) elif freq == Indicator.MONTHLY: self.assertEqual(_get_first_period, date(2016, 7, 1)) else: self.fail('Unexpected target frequency' + freq) def test__generate_annotations(self): """Do we generate queryset annotations correctly?""" reporttype = 'timeperiods' filter_start_date = date(2018, 1, 1) filter_end_date = date(2019, 12, 31) num_recents = 0 show_all = True self.mixin.program = Program() self.mixin.program.reporting_period_start = filter_start_date self.mixin.program.reporting_period_end = filter_end_date freqs = (Indicator.LOP, Indicator.MID_END, Indicator.EVENT, Indicator.ANNUAL, Indicator.SEMI_ANNUAL, Indicator.TRI_ANNUAL, Indicator.QUARTERLY, Indicator.MONTHLY) for freq in freqs: (report_end_date, all_date_ranges, periods_date_ranges) = self.mixin._generate_targetperiods( Indicator.MONTHLY) self.assertEqual(self.mixin.program.reporting_period_end, report_end_date) self.assertEqual(self.mixin.program.reporting_period_end, filter_end_date) annotations = self.mixin._generate_annotations( periods_date_ranges, freq, reporttype) if freq == Indicator.LOP: self.assertEqual(annotations, {}) else: self.assertNotEqual(annotations, {}) def test__get_num_periods(self): """Do we return the correct number of periods""" _get_num_periods = IPTT_Mixin._get_num_periods start_date = date(2016, 1, 15) end_date = date(2017, 12, 16) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.ANNUAL), 2) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.SEMI_ANNUAL), 4) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.TRI_ANNUAL), 6) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.QUARTERLY), 8) self.assertEqual( _get_num_periods(start_date, end_date, Indicator.MONTHLY), 24) @unittest.skip('outdated test') def test__generate_targetperiods(self): """Can we generate target periods correctly""" freqs = (Indicator.LOP, Indicator.MID_END, Indicator.EVENT, Indicator.ANNUAL, Indicator.SEMI_ANNUAL, Indicator.TRI_ANNUAL, Indicator.QUARTERLY, Indicator.MONTHLY) self.mixin.filter_form_initial_data = { 'timeframe': 1, 'numrecentperiods': 0, 'period_start': '2018-01-01', 'period_end': '2019-12-31' } filter_start_date = date(2018, 1, 1) filter_end_date = date(2019, 12, 31) num_recents = 0 show_all = True self.mixin.program = Program() self.mixin.program.reporting_period_start = filter_start_date self.mixin.program.reporting_period_end = filter_end_date for freq in freqs: report_end_date, all_date_ranges, targetperiods = self.mixin._generate_targetperiods( freq) self.assertEqual(filter_end_date, report_end_date) self.assertEqual(len(all_date_ranges), 0) self.assertEqual(len(targetperiods), 0) @unittest.skip('outdated test') def test__generate_timeperiods(self): """Can we generate time periods correctly?""" freqs = (Indicator.LOP, Indicator.MID_END, Indicator.EVENT, Indicator.ANNUAL, Indicator.SEMI_ANNUAL, Indicator.TRI_ANNUAL, Indicator.QUARTERLY, Indicator.MONTHLY) filter_start_date = date(2018, 1, 1) filter_end_date = date(2019, 12, 31) num_recents = 0 self.mixin.filter_form_initial_data = { 'timeframe': 1, 'numrecentperiods': num_recents, 'period_start': '2018-01-01', 'period_end': '2019-12-31' } self.mixin.program = Program() self.mixin.program.reporting_period_start = filter_start_date self.mixin.program.reporting_period_end = filter_end_date for freq in freqs: report_end_date, all_date_ranges, timeperiods = self.mixin._generate_targetperiods( Indicator.MONTHLY) self.assertEqual(report_end_date, filter_end_date, 'End dates don\'t match') if freq == Indicator.LOP or freq == Indicator.MID_END or freq == Indicator.EVENT: self.assertEqual(len(all_date_ranges), 0) elif freq == Indicator.ANNUAL: self.assertEqual( len(all_date_ranges), 2, 'Unexpected number of date ranges for {0}: {1}'.format( freq, len(all_date_ranges))) self.assertEqual( len(timeperiods), 2, 'Unexpected number of timeperiods for {0}: {1}'.format( freq, len(timeperiods))) elif freq == Indicator.SEMI_ANNUAL: self.assertEqual( len(all_date_ranges), 4, 'Unexpected number of date ranges for {0}: {1}'.format( freq, len(all_date_ranges))) self.assertEqual( len(timeperiods), 4, 'Unexpected number of timeperiods for {0}: {1}'.format( freq, len(timeperiods))) elif freq == Indicator.TRI_ANNUAL: self.assertEqual( len(all_date_ranges), 6, 'Unexpected number of date ranges for {0}: {1}'.format( freq, len(all_date_ranges))) self.assertEqual( len(timeperiods), 6, 'Unexpected number of timeperiods for {0}: {1}'.format( freq, len(timeperiods))) elif freq == Indicator.QUARTERLY: self.assertEqual( len(all_date_ranges), 8, 'Unexpected number of date ranges for {0}: {1}'.format( freq, len(all_date_ranges))) self.assertEqual( len(timeperiods), 8, 'Unexpected number of timeperiods for {0}: {1}'.format( freq, len(timeperiods))) elif freq == Indicator.MONTHLY: self.assertEqual( len(all_date_ranges), 24, 'Unexpected number of date ranges for {0}: {1}'.format( freq, len(all_date_ranges))) self.assertEqual( len(timeperiods), 24, 'Unexpected number of timeperiods for {0}: {1}'.format( freq, len(timeperiods))) def test__update_filter_form_initial(self): """Do we populate the initial filter form properly?""" data = { 'csrfmiddlewaretoken': 'lolwut', 'program': self.program.id, 'formprefix': IPTTReportQuickstartView.FORM_PREFIX_TARGET, 'timeframe': Indicator.LOP, 'targetperiods': 1, 'numrecentperiods': 1, } query_string = urllib.urlencode(data) formdata = QueryDict(query_string=query_string, mutable=True) self.mixin._update_filter_form_initial(formdata=formdata) filter_form_initial_data = self.mixin.filter_form_initial_data self.assertEqual(len(filter_form_initial_data), 4) self.assertNotIn('csrfmiddlewaretokeen', filter_form_initial_data) self.assertNotIn('program', filter_form_initial_data) # Dicts should have the same key/value pairs; the method first # strips off program and csrfmiddlewaretoken, so do that, too. del (data['csrfmiddlewaretoken']) del (data['program']) for k in data.keys(): self.assertIn(k, formdata) # Coercing both to str because the data arg is an int # and the formdata arg is a unicode value self.assertEqual(str(data[k]), str(formdata[k])) def test__get_filters_with_no_periods(self): data = { 'level': 3, 'sector': 'Conflict Management', # TODO: Load fixtures for level, indicators 'ind_type': 'Custom', 'site': self.program.country.name, 'indicators': self.indicator.id, } filters = self.mixin._get_filters(data) # Assert things about the returned filters self.assertEqual(len(filters), len(data)) self.assertIn(data['level'], filters['level__in']) self.assertIn(data['sector'], filters['sector__in']) self.assertIn(data['ind_type'], filters['indicator_type__in']) self.assertIn(data['site'], filters['result__site__in']) self.assertIn(data['indicators'], filters['id__in']) self.assertEqual(data['level'], *filters['level__in']) self.assertEqual(data['sector'], *filters['sector__in']) self.assertEqual(data['ind_type'], *filters['indicator_type__in']) self.assertEqual(data['site'], *filters['result__site__in']) self.assertEqual(data['indicators'], *filters['id__in']) # TODO: Is it possible to make assertions about the filtered report # TODO: without a GET or POST? def test_prepare_indicators(self): self.skipTest('TODO: Test not implemented') def test_prepare_iptt_period_dateranges(self): self.skipTest('TODO: Test not implemented') # TODO: Mock the super call that invokes a non-existent get_context_data # call on IPTT_Mixin. def test_get_context_data(self): '''Does get_context_data return existing data untouched and without inserting new data?''' self.skipTest('TODO: Test not implemented')