Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ellar_storage/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions ellar_storage/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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)),
],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ classifiers = [
]

dependencies = [
"ellar >= 0.7.7",
"ellar >= 0.8.2",
"apache-libcloud >=3.6, <3.9",
"fasteners ==0.19"
]
Expand Down
29 changes: 24 additions & 5 deletions samples/ellar_storage_tut/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 7 additions & 2 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path

import pytest
from ellar.common import Module
from ellar.testing import Test
from starlette.routing import NoMatchFound

Expand Down Expand Up @@ -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",
Expand Down