コード例 #1
0
    def test_caching(self):
        user_case = CaseAccessors(self.cc_domain.name).get_case_by_domain_hq_user_id(self.cc_user.get_id, CASE_TYPE)
        expected_indicators = {'a': 1, 'b': 2}
        cached_data = CachedIndicators(
            user_id=self.cc_user.get_id,
            case_id=user_case.case_id,
            domain=self.cc_domain.name,
            indicators=expected_indicators
        )

        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
        )
        locmem_cache.set(cache_key(self.cc_user.get_id, indicator_set.reference_date), cached_data.to_json())

        self.assertEqual(
            set(indicator_set.user_to_case_map.keys()),
            set([self.cc_user.get_id, self.cc_user_no_data.get_id])
        )
        self.assertEquals(indicator_set.users_needing_data, set([self.cc_user_no_data.get_id]))
        self.assertEqual(indicator_set.owners_needing_data, set([self.cc_user_no_data.get_id]))
        self.check_cc_indicators(indicator_set.get_data(), expected_indicators)
コード例 #2
0
    def test_caching(self, mock):
        user_case = (CaseAccessors(
            self.cc_domain.name).get_case_by_domain_hq_user_id(
                self.cc_user.get_id, CASE_TYPE))
        expected_indicators = {'a': 1, 'b': 2}
        cached_data = CachedIndicators(user_id=self.cc_user.get_id,
                                       case_id=user_case.case_id,
                                       domain=self.cc_domain.name,
                                       indicators=expected_indicators)

        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)
        locmem_cache.set(
            cache_key(self.cc_user.get_id, indicator_set.reference_date),
            cached_data.to_json())

        self.assertEqual(
            set(indicator_set.user_to_case_map),
            set([self.cc_user.get_id, self.cc_user_no_data.get_id]))
        self.assertEquals(indicator_set.users_needing_data,
                          set([self.cc_user_no_data.get_id]))
        self.assertEqual(indicator_set.owners_needing_data,
                         set([self.cc_user_no_data.get_id]))
        self.check_cc_indicators(indicator_set.get_data(), expected_indicators)
コード例 #3
0
    def test_caching(self):
        user_case = get_case_by_domain_hq_user_id(self.cc_domain.name, self.cc_user._id, include_docs=True)
        expected_indicators = {'a': 1, 'b': 2}
        cached_data = CachedIndicators(
            user_id=self.cc_user.get_id,
            case_id=user_case.case_id,
            domain=self.cc_domain.name,
            indicators=expected_indicators
        )
        locmem_cache.set(cache_key(self.cc_user.get_id), cached_data.to_json())

        indicator_set = CallCenterIndicators(self.cc_domain, self.cc_user, custom_cache=locmem_cache)
        self.assertEqual(indicator_set.all_user_ids, set([self.cc_user.get_id, self.cc_user_no_data.get_id]))
        self.assertEquals(indicator_set.users_needing_data, set([self.cc_user_no_data.get_id]))
        self.assertEqual(indicator_set.owners_needing_data, set([self.cc_user_no_data.get_id]))
        self.check_cc_indicators(indicator_set.get_data(), expected_indicators)