Пример #1
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)
Пример #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 get_call_center_config_from_app(app):
    indicators = get_indicators_used_in_app(app)
    parsed_indicators = {
        parse_indicator(indicator) for indicator in indicators
    }
    config = CallCenterIndicatorConfig()
    for parsed_indicator in parsed_indicators:
        config.set_indicator(parsed_indicator)
    return config
Пример #4
0
def get_call_center_config_from_app(app):
    indicators = get_indicators_used_in_app(app)
    custom_domain_indicators = const.PER_DOMAIN_FORM_INDICATORS.get(app.domain, {})
    parsed_indicators = filter(None, {
        parse_indicator(indicator, custom_domain_indicators) for indicator in indicators
    })
    config = CallCenterIndicatorConfig()
    for parsed_indicator in parsed_indicators:
        config.set_indicator(parsed_indicator)
    return config
Пример #5
0
def get_call_center_config_from_app(app):
    indicators = get_indicators_used_in_app(app)
    custom_domain_indicators = const.PER_DOMAIN_FORM_INDICATORS.get(app.domain, {})
    parsed_indicators = [_f for _f in {
        parse_indicator(indicator, custom_domain_indicators) for indicator in indicators
    } if _f]
    config = CallCenterIndicatorConfig()
    for parsed_indicator in parsed_indicators:
        config.set_indicator(parsed_indicator)
    return config
Пример #6
0
    def test_standard_indicators_case_dog_only(self, mock):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)
        config.forms_submitted.enabled = False

        def dog_only(conf):
            conf.totals.enabled = False
            conf.all_types = False
            conf.by_type = [
                TypedIndicator(enabled=True,
                               date_ranges={WEEK0, MONTH0},
                               type='dog')
            ]

        dog_only(config.cases_total)
        dog_only(config.cases_opened)
        dog_only(config.cases_closed)
        dog_only(config.cases_active)

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config)
        self._test_indicators(
            self.cc_user, indicator_set.get_data(),
            expected_standard_indicators(include_legacy=False,
                                         include_totals=False,
                                         case_types=['dog'],
                                         limit_ranges=[WEEK0, MONTH0]))
Пример #7
0
    def test_standard_indicators_case_dog_only(self):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)
        config.forms_submitted.enabled = False

        def dog_only(conf):
            conf.totals.enabled = False
            conf.all_types = False
            conf.by_type = [TypedIndicator(enabled=True, date_ranges={WEEK0, MONTH0}, type='dog')]

        dog_only(config.cases_total)
        dog_only(config.cases_opened)
        dog_only(config.cases_closed)
        dog_only(config.cases_active)

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config
        )
        self._test_indicators(
            self.cc_user,
            indicator_set.get_data(),
            expected_standard_indicators(
                include_legacy=False,
                include_totals=False,
                case_types=['dog'],
                limit_ranges=[WEEK0, MONTH0])
        )
Пример #8
0
    def __init__(self,
                 domain_name,
                 domain_timezone,
                 cc_case_type,
                 user,
                 custom_cache=None,
                 override_date=None,
                 override_cases=None,
                 override_cache=False,
                 indicator_config=None):
        self.domain = domain_name
        self.user = user
        self.data = defaultdict(dict)
        self.cc_case_type = cc_case_type
        self.cache = custom_cache or cache
        self.override_cases = override_cases
        self.override_cache = override_cache

        self.config = indicator_config or CallCenterIndicatorConfig.default_config(
            domain_name)

        try:
            self.timezone = pytz.timezone(domain_timezone)
        except pytz.UnknownTimeZoneError:
            self.timezone = pytz.utc

        if override_date and isinstance(override_date, datetime):
            override_date = override_date.date()

        self.reference_date = override_date or datetime.now(
            self.timezone).date()
Пример #9
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'
        })
Пример #10
0
    def test_standard_indicators_no_legacy(self, mock):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config)
        self._test_indicators(
            self.cc_user, indicator_set.get_data(),
            expected_standard_indicators(include_legacy=False))
Пример #11
0
    def test_standard_indicators_no_legacy(self):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config
        )
        self._test_indicators(
            self.cc_user,
            indicator_set.get_data(),
            expected_standard_indicators(include_legacy=False))
Пример #12
0
    def test_standard_indicators_load_config_from_db(self):
        config = CallCenterIndicatorConfig.default_config(self.cc_domain.name, include_legacy=False)
        config.save()

        self.addCleanup(config.delete)

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
        )
        self._test_indicators(
            self.cc_user,
            indicator_set.get_data(),
            expected_standard_indicators(include_legacy=False))
Пример #13
0
    def test_standard_indicators_case_totals_only(self, mock):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)
        config.cases_total.all_types = False
        config.cases_opened.all_types = False
        config.cases_closed.all_types = False
        config.cases_active.all_types = False

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config)
        self._test_indicators(
            self.cc_user, indicator_set.get_data(),
            expected_standard_indicators(include_legacy=False,
                                         include_totals=True,
                                         case_types=[]))
Пример #14
0
    def test_standard_indicators_case_week1_only(self, mock):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)
        config.forms_submitted.date_ranges = {WEEK1}
        config.cases_total.totals.date_ranges = {WEEK1}
        config.cases_opened.totals.date_ranges = {WEEK1}
        config.cases_closed.totals.date_ranges = {WEEK1}
        config.cases_active.totals.date_ranges = {WEEK1}

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config)
        self._test_indicators(
            self.cc_user, indicator_set.get_data(),
            expected_standard_indicators(include_legacy=False,
                                         include_totals=True,
                                         limit_ranges=[WEEK1]))
Пример #15
0
    def __init__(self, domain_name, domain_timezone, cc_case_type, user,
                 custom_cache=None, override_date=None, override_cases=None,
                 override_cache=False, indicator_config=None):
        self.domain = domain_name
        self.user = user
        self.data = defaultdict(dict)
        self.cc_case_type = cc_case_type
        self.cache = custom_cache or cache
        self.override_cases = override_cases
        self.override_cache = override_cache

        self.config = indicator_config or CallCenterIndicatorConfig.default_config(domain_name)

        try:
            self.timezone = pytz.timezone(domain_timezone)
        except pytz.UnknownTimeZoneError:
            self.timezone = pytz.utc

        if override_date and isinstance(override_date, datetime):
            override_date = override_date.date()

        self.reference_date = override_date or datetime.now(self.timezone).date()
Пример #16
0
    def test_standard_indicators_case_totals_only(self):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)
        config.cases_total.all_types = False
        config.cases_opened.all_types = False
        config.cases_closed.all_types = False
        config.cases_active.all_types = False

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config
        )
        self._test_indicators(
            self.cc_user,
            indicator_set.get_data(),
            expected_standard_indicators(
                include_legacy=False,
                include_totals=True,
                case_types=[])
        )
Пример #17
0
    def test_standard_indicators_case_week1_only(self):
        config = CallCenterIndicatorConfig.default_config(include_legacy=False)
        config.forms_submitted.date_ranges = {WEEK1}
        config.cases_total.totals.date_ranges = {WEEK1}
        config.cases_opened.totals.date_ranges = {WEEK1}
        config.cases_closed.totals.date_ranges = {WEEK1}
        config.cases_active.totals.date_ranges = {WEEK1}

        indicator_set = CallCenterIndicators(
            self.cc_domain.name,
            self.cc_domain.default_timezone,
            self.cc_domain.call_center_config.case_type,
            self.cc_user,
            custom_cache=locmem_cache,
            indicator_config=config
        )
        self._test_indicators(
            self.cc_user,
            indicator_set.get_data(),
            expected_standard_indicators(
                include_legacy=False,
                include_totals=True,
                limit_ranges=[WEEK1])
        )
Пример #18
0
 def test_empty(self):
     self.assertEqual(get_indicator_slugs_from_config(CallCenterIndicatorConfig()), [])
Пример #19
0
 def test_default(self):
     indicators = get_indicator_slugs_from_config(
         CallCenterIndicatorConfig.default_config(), all_types=['t1', 't2']
     )
     self.assertEqual(len(indicators), 61)
Пример #20
0
        # custom
        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)
Пример #21
0
    def test_custom_indicators_limited(self):
        expected = {}

        # custom
        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(