Exemplo n.º 1
0
    def init(cls):
        """
        init Pylaas

        """
        current_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
        PylaasCore._init("{}/conf/definitions.yml".format(current_path))
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 def __init__(self) -> None:
     """ Init service """
     module_name = self.__module__
     filename = sys.modules[module_name].__file__
     if path.exists(filename.replace('.py', '_adapter.py')):
         module_name += "_adapter"
         class_name = "{}Adapter".format(self.__class__.__name__)
         __import__(module_name)
         adapter = getattr(sys.modules[module_name], class_name)
         adapter = adapter()
         self._adapter = adapter
     else:
         self._adapter = None
     list_services = PylaasCore.get_container().get_definitions(
     )['services']
     for service in list_services:
         setattr(self, '{}_service'.format(service),
                 self._make_service_method(service))
    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())
Exemplo n.º 7
0
 def get_service():
     return PylaasCore.get_service(service_id)
Exemplo n.º 8
0
 def test__init_success(self):
     PylaasCore._init({'services': {'a service': 'data'}})
     expected = {'configurations': {}, 'services': {'a service': 'data'}}
     assert expected == PylaasCore._container._definitions
Exemplo n.º 9
0
 def test_get_adapter_with_no_adapter_return_none(self):
     self.init_container()
     assert PylaasCore.get_service('dummy').get_adapter() is None
Exemplo n.º 10
0
 def test_has_adapter_with_adapter_return_true(self):
     self.init_container()
     dummy_adapter = PylaasCore.get_service('dummy_adapter')
     assert dummy_adapter.has_adapter()
Exemplo n.º 11
0
 def test_has_adapter_with_no_adapter_return_false(self):
     self.init_container()
     dummy = PylaasCore.get_service('dummy')
     assert not dummy.has_adapter()
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 def test_get_service(self):
     PylaasCore._init(self.datasets_path + '/container/definitions.yml')
     assert isinstance(PylaasCore.get_service('dummy'), Dummy)
Exemplo n.º 14
0
 def test_get_container(self):
     PylaasCore._init({'services': {'a service': 'data'}})
     assert isinstance(PylaasCore.get_container(), Container)
Exemplo n.º 15
0
 def test_get_adapter_with_adapter_return_adapter(self):
     self.init_container()
     assert isinstance(
         PylaasCore.get_service('dummy_adapter').get_adapter(),
         DummyAdapterAdapter)
 def init_container(self):
     PylaasCore._init(self.datasets_path + '/container/definitions.yml')
Exemplo n.º 17
0
 def test_new_raise_TypeError(self):
     """Test unique instance creation"""
     with pytest.raises(TypeError):
         PylaasCore()