Exemplo n.º 1
0
def test_reload(
    fake_application_context_class,
    fake_service_class,
    another_fake_service_class,
    settings,
):
    context = fake_application_context_class()

    assert type(context.fake_service) == fake_service_class

    settings.reload(
        {
            "FAKE_SERVICE": "another",
        }
    )
    context.reload()
    assert context == fake_application_context_class.instance

    assert len(context.repositories) == 1
    assert len(context.services) == 2

    from fractal.core.utils.string import camel_to_snake

    assert hasattr(context, camel_to_snake(fake_service_class.__name__))
    assert type(context.fake_service) == another_fake_service_class
    def install_service(self, service, *, name=""):
        if not name:
            from fractal.core.utils.string import camel_to_snake

            name = camel_to_snake(service.__name__)
        self.service_names.add(name)
        setattr(ApplicationContext, name,
                property(lambda self: next(service.install(self))))
    def install_repository(self, repository, *, name=""):
        if not name:
            from fractal.core.utils.string import camel_to_snake

            name = camel_to_snake(repository.__class__.__name__)
        self.repository_names.add(name)
        self.repositories.add(repository)
        return repository
Exemplo n.º 4
0
def test_load(fake_application_context_class, fake_service_class):
    assert not fake_application_context_class.instance
    assert not hasattr(
        fake_application_context_class.instance, fake_service_class.__class__.__name__
    )

    context = fake_application_context_class()
    assert context == fake_application_context_class.instance

    assert len(context.repositories) == 1
    assert len(context.services) == 2

    from fractal.core.utils.string import camel_to_snake

    assert hasattr(context, camel_to_snake(fake_service_class.__name__))
Exemplo n.º 5
0
def test_camel_to_snake(camel, snake):
    from fractal.core.utils.string import camel_to_snake

    assert camel_to_snake(camel) == snake