Пример #1
0
    def test_real_example(self):
        config = CallCenterIndicatorConfig(
            domain='domain',
            forms_submitted=BasicIndicator(enabled=True, date_ranges={MONTH0}),
            cases_total=ByTypeWithTotal(
                totals=BasicIndicator(enabled=False),
                by_type=[
                    TypedIndicator(enabled=True, date_ranges={MONTH0}, type='caregiver'),
                    TypedIndicator(enabled=True, date_ranges={MONTH0}, type='beneficiary'),
                ]
            ),
            cases_active=ByTypeWithTotal(
                totals=BasicIndicator(enabled=False),
                by_type=[
                    TypedIndicator(enabled=True, date_ranges={MONTH0}, type='caregiver'),
                    TypedIndicator(enabled=True, date_ranges={MONTH0}, type='beneficiary'),
                ]
            )
        )

        self.assertEqual(set(get_indicator_slugs_from_config(config)), {
            'forms_submitted_month0',
            'cases_total_caregiver_month0',
            'cases_active_caregiver_month0',
            'cases_total_beneficiary_month0',
            'cases_active_beneficiary_month0'
        })
Пример #2
0
    def test_custom_indicators_limited(self, mock):
        expected = {}

        # custom
        expected.update(
            get_indicators('motherForms', [3, None, 9, None],
                           is_legacy=True,
                           limit_ranges=[WEEK0, MONTH0]))
        expected.update(
            get_indicators('childForms', [None, 0, None, None],
                           is_legacy=True,
                           limit_ranges=[WEEK1]))
        expected.update(
            get_indicators('motherDuration', [None, None, None, 0],
                           is_legacy=True,
                           limit_ranges=[MONTH1]))

        indicator_config = CallCenterIndicatorConfig()
        indicator_config.custom_form = [
            TypedIndicator(type='motherForms', date_range=WEEK0),
            TypedIndicator(type='motherForms', date_range=MONTH0),
            TypedIndicator(type='childForms', date_range=WEEK1),
            TypedIndicator(type='motherDuration', date_range=MONTH1),
        ]
        indicator_set = CallCenterIndicators(
            self.aarohi_domain.name,
            self.aarohi_domain.default_timezone,
            self.aarohi_domain.call_center_config.case_type,
            self.aarohi_user,
            custom_cache=locmem_cache,
            indicator_config=indicator_config)
        self._test_indicators(self.aarohi_user, indicator_set.get_data(),
                              expected)
Пример #3
0
    def test_types_by_date_range(self):
        by_type = ByTypeWithTotal(by_type=[
            TypedIndicator(enabled=True, date_ranges={WEEK0, WEEK1}, type='dog'),
            TypedIndicator(enabled=True, date_ranges={WEEK0}, type='cat'),
            TypedIndicator(enabled=True, date_ranges={WEEK1}, type='canary'),
            TypedIndicator(enabled=True, date_ranges={WEEK1, MONTH0}, type='fish'),
            TypedIndicator(enabled=False, date_ranges={MONTH0}, type='whale'),
        ])

        self.assertEqual(by_type.types_by_date_range(), {
            WEEK0: {'dog', 'cat'},
            WEEK1: {'dog', 'canary', 'fish'},
            MONTH0: {'fish'},
        })
Пример #4
0
 def dog_only(conf):
     conf.totals.enabled = False
     conf.all_types = False
     conf.by_type = [
         TypedIndicator(enabled=True,
                        date_ranges={WEEK0, MONTH0},
                        type='dog')
     ]
Пример #5
0
        expected.update(
            get_indicators('motherForms', [3L, None, 9L, None],
                           is_legacy=True,
                           limit_ranges=[WEEK0, MONTH0]))
        expected.update(
            get_indicators('childForms', [None, 0L, None, None],
                           is_legacy=True,
                           limit_ranges=[WEEK1]))
        expected.update(
            get_indicators('motherDuration', [None, None, None, 0L],
                           is_legacy=True,
                           limit_ranges=[MONTH1]))

        indicator_config = CallCenterIndicatorConfig()
        indicator_config.custom_form = [
            TypedIndicator(type='motherForms', date_range=WEEK0),
            TypedIndicator(type='motherForms', date_range=MONTH0),
            TypedIndicator(type='childForms', date_range=WEEK1),
            TypedIndicator(type='motherDuration', date_range=MONTH1),
        ]
        indicator_set = CallCenterIndicators(
            self.aarohi_domain.name,
            self.aarohi_domain.default_timezone,
            self.aarohi_domain.call_center_config.case_type,
            self.aarohi_user,
            custom_cache=locmem_cache,
            indicator_config=indicator_config)
        self._test_indicators(self.aarohi_user, indicator_set.get_data(),
                              expected)

    def test_caching(self, mock):