Skip to content

Commit a9d1e1e

Browse files
authored
Merge pull request #21 from python-ellar/ellar_081_upgrade
Ellar 081 upgrade
2 parents 6093f5c + cb4b966 commit a9d1e1e

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

ellar_storage/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Storage Module for Ellar"""
22

3-
__version__ = "0.1.5"
3+
__version__ = "0.1.7"
44

55
from .module import StorageModule
66
from .providers import Provider, get_driver

ellar_storage/module.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ellar.common import IModuleSetup, Module
44
from ellar.core import Config, ModuleSetup
5-
from ellar.core.modules import DynamicModule, ModuleBase
5+
from ellar.core.modules import DynamicModule, ModuleBase, ModuleRefBase
66
from ellar.di import ProviderConfig
77

88
from ellar_storage.controller import StorageController
@@ -20,7 +20,7 @@ class _StorageSetupKey(t.TypedDict):
2020
options: t.Union[_ContainerOptions, t.Dict[str, t.Any]]
2121

2222

23-
@Module()
23+
@Module(exports=[StorageService], name="EllarStorageModule")
2424
class StorageModule(ModuleBase, IModuleSetup):
2525
@classmethod
2626
def setup(
@@ -50,12 +50,12 @@ def register_setup(cls) -> ModuleSetup:
5050

5151
@staticmethod
5252
def __register_setup_factory(
53-
module: t.Type["StorageModule"], config: Config
53+
module_ref: ModuleRefBase, config: Config
5454
) -> DynamicModule:
5555
if config.get("STORAGE_CONFIG") and isinstance(config.STORAGE_CONFIG, dict):
5656
schema = StorageSetup(**dict(config.STORAGE_CONFIG))
5757
return DynamicModule(
58-
module,
58+
module_ref.module,
5959
providers=[
6060
ProviderConfig(StorageService, use_value=StorageService(schema)),
6161
],

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ classifiers = [
4040
]
4141

4242
dependencies = [
43-
"ellar >= 0.7.7",
43+
"ellar >= 0.8.2",
4444
"apache-libcloud >=3.6, <3.9",
4545
"fasteners ==0.19"
4646
]

samples/ellar_storage_tut/config.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ class BaseConfig(ConfigDefaultTypesMixin):
3434
# https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api
3535
JINJA_TEMPLATES_OPTIONS: t.Dict[str, t.Any] = {}
3636

37+
# Injects context to jinja templating context values
38+
TEMPLATES_CONTEXT_PROCESSORS: t.List[
39+
t.Union[str, t.Callable[[t.Union[Request]], t.Dict[str, t.Any]]]
40+
] = [
41+
"ellar.core.templating.context_processors:request_context",
42+
"ellar.core.templating.context_processors:user",
43+
"ellar.core.templating.context_processors:request_state",
44+
]
45+
3746
# Application route versioning scheme
3847
VERSIONING_SCHEME: BaseAPIVersioning = DefaultAPIVersioning()
3948

@@ -56,19 +65,29 @@ class BaseConfig(ConfigDefaultTypesMixin):
5665
ALLOWED_HOSTS: t.List[str] = ["*"]
5766

5867
# Application middlewares
59-
MIDDLEWARE: t.Sequence[Middleware] = []
68+
MIDDLEWARE: t.Union[str, Middleware] = [
69+
"ellar.core.middleware.trusted_host:trusted_host_middleware",
70+
"ellar.core.middleware.cors:cors_middleware",
71+
"ellar.core.middleware.errors:server_error_middleware",
72+
"ellar.core.middleware.versioning:versioning_middleware",
73+
"ellar.auth.middleware.session:session_middleware",
74+
"ellar.auth.middleware.auth:identity_middleware",
75+
"ellar.core.middleware.exceptions:exception_middleware",
76+
]
6077

6178
# A dictionary mapping either integer status codes,
6279
# or exception class types onto callables which handle the exceptions.
6380
# Exception handler callables should be of the form
6481
# `handler(context:IExecutionContext, exc: Exception) -> response`
6582
# and may be either standard functions, or async functions.
66-
EXCEPTION_HANDLERS: t.List[IExceptionHandler] = []
83+
EXCEPTION_HANDLERS: t.Union[str, IExceptionHandler] = [
84+
"ellar.core.exceptions:error_404_handler"
85+
]
6786

6887
# Object Serializer custom encoders
69-
SERIALIZER_CUSTOM_ENCODER: t.Dict[
70-
t.Any, t.Callable[[t.Any], t.Any]
71-
] = encoders_by_type
88+
SERIALIZER_CUSTOM_ENCODER: t.Dict[t.Any, t.Callable[[t.Any], t.Any]] = (
89+
encoders_by_type
90+
)
7291

7392
STORAGE_CONFIG = dict(
7493
storages=dict(

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import pytest
2+
from ellar.reflect import reflect
23

34
from .utils import clear
45

56

7+
@pytest.fixture
8+
def reflect_context():
9+
with reflect.context():
10+
yield
11+
12+
613
@pytest.fixture
714
def clear_dir():
815
yield

tests/test_module.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os.path
22

33
import pytest
4+
from ellar.common import Module
45
from ellar.testing import Test
56
from starlette.routing import NoMatchFound
67

@@ -89,9 +90,13 @@ def test_module_register_fails_config_key_absents():
8990
tm.create_application()
9091

9192

92-
def test_disable_storage_controller():
93+
def test_disable_storage_controller(reflect_context):
94+
@Module()
95+
class StorageModuleModified(StorageModule):
96+
pass
97+
9398
tm = Test.create_test_module(
94-
modules=[StorageModule.register_setup()],
99+
modules=[StorageModuleModified.register_setup()],
95100
config_module={
96101
"STORAGE_CONFIG": {
97102
"default": "files",

0 commit comments

Comments
 (0)