From 7022977b0cf5be87a299a5cadaf1e1010e07d661 Mon Sep 17 00:00:00 2001 From: Ezeudoh Tochukwu Date: Wed, 21 Aug 2024 22:58:06 +0100 Subject: [PATCH 1/3] upgraded to ellar 0.8.1 --- ellar_storage/module.py | 8 ++++---- pyproject.toml | 2 +- samples/ellar_storage_tut/config.py | 29 ++++++++++++++++++++++++----- tests/conftest.py | 7 +++++++ tests/test_module.py | 9 +++++++-- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/ellar_storage/module.py b/ellar_storage/module.py index 93a5cd3..6c20567 100644 --- a/ellar_storage/module.py +++ b/ellar_storage/module.py @@ -2,7 +2,7 @@ from ellar.common import IModuleSetup, Module from ellar.core import Config, ModuleSetup -from ellar.core.modules import DynamicModule, ModuleBase +from ellar.core.modules import DynamicModule, ModuleBase, ModuleRefBase from ellar.di import ProviderConfig from ellar_storage.controller import StorageController @@ -20,7 +20,7 @@ class _StorageSetupKey(t.TypedDict): options: t.Union[_ContainerOptions, t.Dict[str, t.Any]] -@Module() +@Module(exports=[StorageService], name="EllarStorageModule") class StorageModule(ModuleBase, IModuleSetup): @classmethod def setup( @@ -50,12 +50,12 @@ def register_setup(cls) -> ModuleSetup: @staticmethod def __register_setup_factory( - module: t.Type["StorageModule"], config: Config + module_ref: ModuleRefBase, config: Config ) -> DynamicModule: if config.get("STORAGE_CONFIG") and isinstance(config.STORAGE_CONFIG, dict): schema = StorageSetup(**dict(config.STORAGE_CONFIG)) return DynamicModule( - module, + module_ref.module, providers=[ ProviderConfig(StorageService, use_value=StorageService(schema)), ], diff --git a/pyproject.toml b/pyproject.toml index b2a6ec8..2413cfe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ classifiers = [ ] dependencies = [ - "ellar >= 0.7.7", + "ellar >= 0.8.1", "apache-libcloud >=3.6, <3.9", "fasteners ==0.19" ] diff --git a/samples/ellar_storage_tut/config.py b/samples/ellar_storage_tut/config.py index 8902a9d..4be4332 100644 --- a/samples/ellar_storage_tut/config.py +++ b/samples/ellar_storage_tut/config.py @@ -34,6 +34,15 @@ class BaseConfig(ConfigDefaultTypesMixin): # https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api JINJA_TEMPLATES_OPTIONS: t.Dict[str, t.Any] = {} + # Injects context to jinja templating context values + TEMPLATES_CONTEXT_PROCESSORS: t.List[ + t.Union[str, t.Callable[[t.Union[Request]], t.Dict[str, t.Any]]] + ] = [ + "ellar.core.templating.context_processors:request_context", + "ellar.core.templating.context_processors:user", + "ellar.core.templating.context_processors:request_state", + ] + # Application route versioning scheme VERSIONING_SCHEME: BaseAPIVersioning = DefaultAPIVersioning() @@ -56,19 +65,29 @@ class BaseConfig(ConfigDefaultTypesMixin): ALLOWED_HOSTS: t.List[str] = ["*"] # Application middlewares - MIDDLEWARE: t.Sequence[Middleware] = [] + MIDDLEWARE: t.Union[str, Middleware] = [ + "ellar.core.middleware.trusted_host:trusted_host_middleware", + "ellar.core.middleware.cors:cors_middleware", + "ellar.core.middleware.errors:server_error_middleware", + "ellar.core.middleware.versioning:versioning_middleware", + "ellar.auth.middleware.session:session_middleware", + "ellar.auth.middleware.auth:identity_middleware", + "ellar.core.middleware.exceptions:exception_middleware", + ] # A dictionary mapping either integer status codes, # or exception class types onto callables which handle the exceptions. # Exception handler callables should be of the form # `handler(context:IExecutionContext, exc: Exception) -> response` # and may be either standard functions, or async functions. - EXCEPTION_HANDLERS: t.List[IExceptionHandler] = [] + EXCEPTION_HANDLERS: t.Union[str, IExceptionHandler] = [ + "ellar.core.exceptions:error_404_handler" + ] # Object Serializer custom encoders - SERIALIZER_CUSTOM_ENCODER: t.Dict[ - t.Any, t.Callable[[t.Any], t.Any] - ] = encoders_by_type + SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = ( + encoders_by_type + ) STORAGE_CONFIG = dict( storages=dict( diff --git a/tests/conftest.py b/tests/conftest.py index 9e46059..b0e37b3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,15 @@ import pytest +from ellar.reflect import reflect from .utils import clear +@pytest.fixture +def reflect_context(): + with reflect.context(): + yield + + @pytest.fixture def clear_dir(): yield diff --git a/tests/test_module.py b/tests/test_module.py index ec93c62..580314b 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -1,6 +1,7 @@ import os.path import pytest +from ellar.common import Module from ellar.testing import Test from starlette.routing import NoMatchFound @@ -89,9 +90,13 @@ def test_module_register_fails_config_key_absents(): tm.create_application() -def test_disable_storage_controller(): +def test_disable_storage_controller(reflect_context): + @Module() + class StorageModuleModified(StorageModule): + pass + tm = Test.create_test_module( - modules=[StorageModule.register_setup()], + modules=[StorageModuleModified.register_setup()], config_module={ "STORAGE_CONFIG": { "default": "files", From 92c3096a374bca306a920ae56c3d337ac2dbf917 Mon Sep 17 00:00:00 2001 From: Ezeudoh Tochukwu Date: Wed, 21 Aug 2024 22:58:21 +0100 Subject: [PATCH 2/3] 0.1.7 --- ellar_storage/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ellar_storage/__init__.py b/ellar_storage/__init__.py index a5eb057..d10140c 100644 --- a/ellar_storage/__init__.py +++ b/ellar_storage/__init__.py @@ -1,6 +1,6 @@ """Storage Module for Ellar""" -__version__ = "0.1.5" +__version__ = "0.1.7" from .module import StorageModule from .providers import Provider, get_driver From cb4b966b62f0a81f61ef5750f3e80016892134ce Mon Sep 17 00:00:00 2001 From: Ezeudoh Tochukwu Date: Wed, 21 Aug 2024 23:55:28 +0100 Subject: [PATCH 3/3] fixed failing tests --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2413cfe..dae0920 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ classifiers = [ ] dependencies = [ - "ellar >= 0.8.1", + "ellar >= 0.8.2", "apache-libcloud >=3.6, <3.9", "fasteners ==0.19" ]