def setup_method(self, method): if not self._service_id: raise RuntimeError('Attribute _service_id cannot be empty') # clear service instance PylaasCore.get_container().clear(self._service_id) self._service = PylaasCore.get_service(self._service_id)
def test_set_adapter_success(self): self.init_container() dummy = PylaasCore.get_service('dummy') assert not dummy.has_adapter() dummy.set_adapter(DummyAdapterAdapter) assert dummy.has_adapter() assert issubclass(dummy.get_adapter(), DummyAdapterAdapter)
def get_service(service_id) -> ServiceInterface: """ Get service Args: service_id (string): service id to instantiate from container Returns: ServiceInterface """ return PylaasCore.get_service(service_id)
def setup_method(self, method) -> None: """ setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. Args: method (str): test method name Returns: None """ if not self._service_id: raise RuntimeError('Attribute _service_id cannot be empty') self._service = PylaasCore.get_service(self._service_id) # init adapter as a mock if necessary if self._service.has_adapter(): self._service.set_adapter(ServiceMock())
def get_service(): return PylaasCore.get_service(service_id)
def test_get_adapter_with_adapter_return_adapter(self): self.init_container() assert isinstance( PylaasCore.get_service('dummy_adapter').get_adapter(), DummyAdapterAdapter)
def test_get_adapter_with_no_adapter_return_none(self): self.init_container() assert PylaasCore.get_service('dummy').get_adapter() is None
def test_has_adapter_with_adapter_return_true(self): self.init_container() dummy_adapter = PylaasCore.get_service('dummy_adapter') assert dummy_adapter.has_adapter()
def test_has_adapter_with_no_adapter_return_false(self): self.init_container() dummy = PylaasCore.get_service('dummy') assert not dummy.has_adapter()
def test_get_attr_success_return_service(self): PylaasCore._init(self.datasets_path + '/container/definitions.yml') dummy = PylaasCore.get_service('dummy') dummyC = dummy.test_magic_service_injection() assert isinstance(dummyC, DummyConfigurable)
def test_get_service(self): PylaasCore._init(self.datasets_path + '/container/definitions.yml') assert isinstance(PylaasCore.get_service('dummy'), Dummy)