def setUpClass(cls): super(UCRMultiDBTest, cls).setUpClass() cls.db2_name = 'cchq_ucr_tests' default_db_url = connections.connection_manager.get_connection_string(DEFAULT_DB_ALIAS) db_conn_parts = default_db_url.split('/') db_conn_parts[-1] = cls.db2_name cls.db2_url = '/'.join(db_conn_parts) cls.context_managers = ExitStack() cls.context_managers.enter_context(connections.override_engine('engine-1', default_db_url, 'default')) cls.context_managers.enter_context(connections.override_engine('engine-2', cls.db2_url, cls.db2_name)) # setup data sources data_source_template = get_sample_data_source() cls.ds_1 = DataSourceConfiguration.wrap(data_source_template.to_json()) cls.ds_1.engine_id = 'engine-1' cls.ds_1.save() cls.ds_2 = DataSourceConfiguration.wrap(data_source_template.to_json()) cls.ds_2.engine_id = 'engine-2' cls.ds_2.save() cls.context_managers.enter_context(temporary_database(cls.db2_name)) cls.ds1_adapter = get_indicator_adapter(cls.ds_1) cls.ds2_adapter = get_indicator_adapter(cls.ds_2)
def test_standard_indicators(self, mock): with override_engine('ucr', self.ucr_db_url): load_data(self.cc_domain.name, self.cc_user.user_id) 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())
def test_standard_indicators(self, mock): with override_engine('ucr', self.ucr_db_url): load_data(self.cc_domain.name, self.cc_user.user_id) 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())
def test_icds_db_citus(self): with override_settings(CUSTOM_DB_ROUTING={}): self.assertIs(True, allow_migrate(DEFAULT_DB_ALIAS, 'icds_reports')) # map to reporting DB alias with override_settings(CUSTOM_DB_ROUTING={'custom_app': 'icds-ucr-citus'}), \ override_engine('icds-ucr-citus', '', db_alias='icds-ucr'): self.assertIs(False, allow_migrate(DEFAULT_DB_ALIAS, 'custom_app')) self.assertIs(True, allow_migrate('icds-ucr', 'custom_app')) # map to DB alias with override_settings(CUSTOM_DB_ROUTING={'custom_app': 'icds-ucr'}): self.assertIs(True, allow_migrate('icds-ucr', 'custom_app'))
def setUpClass(cls): super(UCRMultiDBTest, cls).setUpClass() cls.db2_name = 'cchq_ucr_tests' db_conn_parts = connections.connection_manager.get_connection_string('default').split('/') db_conn_parts[-1] = cls.db2_name cls.db2_url = '/'.join(db_conn_parts) cls.context_manager = connections.override_engine('engine-2', cls.db2_url, cls.db2_name) cls.context_manager.__enter__() # setup data sources data_source_template = get_sample_data_source() cls.ds_1 = DataSourceConfiguration.wrap(data_source_template.to_json()) cls.ds_1.engine_id = 'engine-1' cls.ds_1.save() cls.ds_2 = DataSourceConfiguration.wrap(data_source_template.to_json()) cls.ds_2.engine_id = 'engine-2' cls.ds_2.save() cls.db_context = temporary_database(cls.db2_name) cls.db_context.__enter__() cls.ds1_adapter = get_indicator_adapter(cls.ds_1) cls.ds2_adapter = get_indicator_adapter(cls.ds_2)