def test_adapter_config_set(self): ac = AdapterConfig('test_adapter', 'path.to.module') option1_name = 'option1' option1_val = 'value1' option2_name = 'option2' option2_val = 'value2' ac.set(option1_name, option1_val) ac.set(option2_name, option2_val) assert_true(option1_name in ac) assert_true(option2_name in ac) assert_equal(ac.option1, option1_val) assert_equal(ac.option2, option2_val) with assert_raises_regexp(AttributeError, 'Unrecognised option option3'): option3 = ac.option3 ac_options = ac.options() assert_true(type(ac_options) is dict) assert_equal(len(ac_options), 2) assert_true(option1_name in ac_options) assert_true(option2_name in ac_options)
def test_adapter_config_set(self): """Test that an adapter config object with options is populated correctly.""" ac = AdapterConfig('test_adapter', 'path.to.module') option1_name = 'option1' option1_val = 'value1' option2_name = 'option2' option2_val = 'value2' ac.set(option1_name, option1_val) ac.set(option2_name, option2_val) assert option1_name in ac assert option2_name in ac assert ac.option1 == option1_val assert ac.option2 == option2_val with pytest.raises(AttributeError) as excinfo: _ = ac.option3 assert "Unrecognised option option3" in str(excinfo.value) ac_options = ac.options() assert type(ac_options) is dict assert len(ac_options) == 2 assert option1_name in ac_options assert option2_name in ac_options
def test_register_adapter(self, test_api_route): """Test that it is possible to register an adapter with the API route object.""" adapter_config = AdapterConfig('dummy', 'odin.adapters.dummy.DummyAdapter') test_api_route.register_adapter(adapter_config) assert test_api_route.has_adapter('dummy')
def test_register_adapter_badclass(self): adapter_config = AdapterConfig('dummy', 'odin.adapters.dummy.BadAdapter') with assert_raises_regexp(ApiError, 'has no attribute \'BadAdapter\''): self.api_route.register_adapter(adapter_config, fail_ok=False)
def test_register_adapter_badmodule(self): adapter_config = AdapterConfig('dummy', 'odin.adapters.bad_dummy.DummyAdapter') with assert_raises_regexp(ApiError, 'No module named'): self.api_route.register_adapter(adapter_config, fail_ok=False)
def test_register_adapter_badclass(self, test_api_route): """Test that registering an adapter with a bad class name raises an error.""" adapter_config = AdapterConfig('dummy', 'odin.adapters.dummy.BadAdapter') with pytest.raises(ApiError) as excinfo: test_api_route.register_adapter(adapter_config, fail_ok=False) assert 'has no attribute \'BadAdapter\'' in str(excinfo.value)
def test_register_adapter_badmodule(self, test_api_route): """Test that registering an adapter with a bad module name raises an error.""" adapter_name = 'dummy' adapter_config = AdapterConfig(adapter_name, 'odin.adapters.bad_dummy.DummyAdapter') with pytest.raises(ApiError) as excinfo: test_api_route.register_adapter(adapter_config, fail_ok=False) assert 'No module named {}'.format(adapter_name) in str(excinfo.value)
def test_basic_adapter_config(self): """Test that a basic adapter config object has the correct fields.""" name = 'test_adapter' module = 'path.to.module' ac = AdapterConfig(name, module) assert ac.name == name assert ac.module == module
def test_register_adapter_no_cleanup(self): adapter_name = 'dummy_no_clean' adapter_config = AdapterConfig(adapter_name, 'odin.adapters.dummy.DummyAdapter') self.api_route.register_adapter(adapter_config) self.api_route.adapters[adapter_name].cleanup = Mock(side_effect=AttributeError()) raised = False try: self.api_route.cleanup_adapters() except: raised = True assert_false(raised)
def __init__(self): self.route = ApiRoute() self.adapter_name = 'async_dummy' self.adapter_module = 'odin.adapters.async_dummy.AsyncDummyAdapter' self.adapter_config = AdapterConfig(self.adapter_name, self.adapter_module) self.route.register_adapter(self.adapter_config) self.initialize_mock = AsyncMock() self.route.adapters[ self.adapter_name].initialize = self.initialize_mock self.cleanup_mock = AsyncMock() self.route.adapters[self.adapter_name].cleanup = self.cleanup_mock
def test_register_adapter_no_initialize(self, test_api_route): """ Test that attempting to inialize an adapter without an initialize method doesn't raise an error. """ adapter_name = 'dummy_no_clean' adapter_config = AdapterConfig(adapter_name, 'odin.adapters.dummy.DummyAdapter') test_api_route.register_adapter(adapter_config) test_api_route.adapters[adapter_name].initialize = Mock(side_effect=AttributeError()) raised = False try: test_api_route.initialize_adapters() except: raised = True assert not raised
def test_register_adapter(self): adapter_config = AdapterConfig('dummy', 'odin.adapters.dummy.DummyAdapter') self.api_route.register_adapter(adapter_config)