def test_call_center_data_source_provider(self, get_call_center_domains): get_call_center_domains.return_value = [ DomainLite('domain1', None, None, True), DomainLite('domain2', None, None, True), DomainLite('domain3', None, None, False) ] data_source_configs = [ config for config, _ in call_center_data_source_configuration_provider() ] self.assertEqual(3, len(data_source_configs)) domains = set( itertools.chain( *[config.domains for config in data_source_configs])) self.assertEqual(set((['domain1'] * 3) + (['domain2'] * 3)), domains) table_ids = [ config.config['table_id'] for config in data_source_configs ] self.assertEqual(['cc_forms', 'cc_cases', 'cc_case_actions'], table_ids)
def test_midnight_for_domain(self): midnight_past = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) midnight_future = midnight_past + timedelta(days=1) timezones = [ ('Asia/Kolkata', 5.5), ('UTC', 0), ('Africa/Lagos', 1), ('America/New_York', -5), ('US/Eastern', -5), ('Europe/London', 0), ('Asia/Baghdad', 3), ('America/Port-au-Prince', -5), ('Africa/Porto-Novo', 1), ('Africa/Nairobi', 3), ] for tz, offset in timezones: # account for DST offset += datetime.now(pytz.timezone(tz)).dst().total_seconds() / 3600 dom = DomainLite(name='', default_timezone=tz, cc_case_type='') self.assertEqual(dom.midnights[0], midnight_past - timedelta(hours=offset), tz) self.assertEqual(dom.midnights[1], midnight_future - timedelta(hours=offset), tz)
def domain_lite(name): from corehq.apps.callcenter.utils import DomainLite return DomainLite(name, None, None, True)
def _test_midnights(self, utcnow, test_cases): for tz, offset, expected in test_cases: dom = DomainLite('', tz, '', True) self.assertEqual(dom.midnights(utcnow), expected, (tz, offset))
from corehq.apps.callcenter.data_source import ( call_center_data_source_configuration_provider, ) from corehq.apps.callcenter.utils import DomainLite from corehq.util.test_utils import generate_cases class TestCallCenterDataSources(SimpleTestCase): pass @generate_cases([ (DomainLite( name='d', default_timezone=None, cc_case_type=None, use_fixtures=True, form_datasource_enabled=True, case_datasource_enabled=False, case_actions_datasource_enabled=False), ['cc_forms']), (DomainLite( name='d', default_timezone=None, cc_case_type=None, use_fixtures=True, form_datasource_enabled=False, case_datasource_enabled=True, case_actions_datasource_enabled=False), ['cc_cases']), (DomainLite( name='d', default_timezone=None, cc_case_type=None, use_fixtures=True, form_datasource_enabled=False, case_datasource_enabled=False, case_actions_datasource_enabled=True), ['cc_case_actions']), (DomainLite( name='d', default_timezone=None, cc_case_type=None, use_fixtures=True, form_datasource_enabled=True,