示例#1
0
 def test_get_location_filter_state(self):
     config = get_location_filter(self.state.location_id, self.domain_name)
     self.assertEqual(config, {
         'aggregation_level': 2,
         u'state_id': self.state.location_id
     })
     self.assertEqual(get_location_level(config['aggregation_level']),
                      'district')
 def test_get_location_filter_district(self):
     config = get_location_filter(self.district.location_id, self.domain_name)
     self.assertEqual(config, {
         'aggregation_level': 3,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id
     })
     self.assertEqual(get_location_level(config['aggregation_level']), 'block')
 def test_get_location_filter_supervisor(self):
     config = get_location_filter(self.supervisor.location_id, self.domain_name)
     self.assertEqual(config, {
         'aggregation_level': 5,
         'supervisor_id': self.supervisor.location_id,
         'block_id': self.block.location_id,
         'district_id': self.district.location_id,
         'state_id': self.state.location_id
     })
     self.assertEqual(get_location_level(config['aggregation_level']), 'awc')
示例#4
0
 def test_get_location_filter_block(self):
     config = get_location_filter(self.block.location_id, self.domain_name)
     self.assertEqual(
         config, {
             'aggregation_level': 4,
             u'block_id': self.block.location_id,
             u'district_id': self.district.location_id,
             u'state_id': self.state.location_id
         })
     self.assertEqual(get_location_level(config['aggregation_level']),
                      'supervisor')
    def test_compare_not_called(self, experiment):
        config = {
            'aggregation_level': 1,
            'month': datetime(2017, 6, 1).date(),
            'previous_month': datetime(2017, 5, 1).date(),
            'two_before': datetime(2017, 4, 1).date(),
            'category': 'maternal_and_child_nutrition',
            'domain': 'icds-cas'
        }

        loc_level = get_location_level(config.get('aggregation_level'))
        FactSheetsReport(config=config, loc_level=loc_level).get_data()
        experiment.assert_not_called()
示例#6
0
 def test_get_location_filter_awc(self):
     config = get_location_filter(self.awc.location_id, self.domain_name)
     self.assertEqual(
         config, {
             'aggregation_level': 6,
             'awc_id': self.awc.location_id,
             'supervisor_id': self.supervisor.location_id,
             'block_id': self.block.location_id,
             'district_id': self.district.location_id,
             'state_id': self.state.location_id
         })
     self.assertEqual(get_location_level(config['aggregation_level']),
                      'awc')
示例#7
0
    def test_compare_called(self, experiment):
        config = {
            'aggregation_level': 1,
            'month': datetime(2017, 6, 1).date(),
            'previous_month': datetime(2017, 5, 1).date(),
            'two_before': datetime(2017, 4, 1).date(),
            'category': 'maternal_and_child_nutrition',
            'domain': 'icds-cas'
        }

        loc_level = get_location_level(config.get('aggregation_level'))
        FactSheetsReport(config=config, loc_level=loc_level).get_data()
        self.assertEqual(len(experiment.call_args_list), 2)

        second_call = experiment.call_args_list[1]
        self.assertEqual(
            second_call[0][1],
            {
                'domain': 'icds-cas',
                'age_12': '12',
                'age_72': '72',
                'previous_month': '2017-05-01',
                'age_24': '24',
                'age_36': '36',
                'age_48': '48',
                'age_60': '60',
                'age_0': '0',
                'aggregation_level': 1,
                'excluded_states_0': 'test_state',
                'age_6': '6'
            },
        )
        self.assertEqual(second_call[1]['data_source'],
                         'NationalAggregationDataSource')

        # small selection of parts of query
        query = second_call[0][0]
        self.assertIn(
            'sum(CASE WHEN age_tranche != %(age_72)s THEN wer_eligible END',
            query)
        self.assertIn('FROM agg_child_health_monthly', query)
        self.assertIn(
            'WHERE aggregation_level = %(aggregation_level)s AND month = %(previous_month)s',
            query)
        self.assertIn('GROUP BY month', query)