Skip to content

Commit fec6151

Browse files
committed
fixed failing tests
1 parent 009c2fa commit fec6151

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+889
-495
lines changed

ellar/app/core_module.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ
4444
@Module(
4545
modules=[app_module],
4646
providers=[
47-
ProviderConfig(
48-
IExceptionMiddlewareService,
49-
use_class=ExceptionMiddlewareService,
50-
export=True,
51-
),
5247
ProviderConfig(
5348
Config,
5449
use_value=config,
@@ -61,6 +56,11 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ
6156
),
6257
export=True,
6358
),
59+
ProviderConfig(
60+
IExceptionMiddlewareService,
61+
use_class=ExceptionMiddlewareService,
62+
export=True,
63+
),
6464
ProviderConfig(
6565
IExecutionContextFactory, use_class=ExecutionContextFactory, export=True
6666
),
@@ -91,7 +91,6 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ
9191
ProviderConfig(
9292
IInterceptorsConsumer, use_value=EllarInterceptorConsumer, export=True
9393
),
94-
ProviderConfig(Reflector, use_value=reflector, export=True),
9594
ProviderConfig(IGuardsConsumer, use_class=GuardConsumer, export=True),
9695
ProviderConfig(IIdentitySchemes, use_class=AppIdentitySchemes, export=True),
9796
ProviderConfig(
@@ -105,8 +104,8 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ
105104
],
106105
)
107106
class EllarCoreModule(IApplicationReady, IApplicationStartup, IApplicationShutdown):
108-
def __init__(self, config: Config, injector: EllarInjector) -> None:
109-
self.config = config
107+
def __init__(self, _config: Config, injector: EllarInjector) -> None:
108+
self.config = _config
110109
self.injector = injector
111110

112111
def on_ready(self, app: "App") -> None:

ellar/app/factory.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
from ellar.app.core_module import get_core_module
66
from ellar.common import IApplicationReady, Module
77
from ellar.common.constants import MODULE_METADATA
8+
from ellar.common.exceptions import ImproperConfiguration
89
from ellar.common.models import GuardCanActivate
9-
from ellar.core import Config, DynamicModule, LazyModuleImport, ModuleBase, ModuleSetup
10+
from ellar.core import (
11+
Config,
12+
DynamicModule,
13+
ForwardRefModule,
14+
LazyModuleImport,
15+
ModuleBase,
16+
ModuleSetup,
17+
)
1018
from ellar.core.modules import ModuleRefBase, ModuleTemplateRef
1119
from ellar.di import EllarInjector, ProviderConfig
1220
from ellar.di.injector.tree_manager import ModuleTreeManager
@@ -49,6 +57,10 @@ def read_all_module(
4957
reflect.get_metadata(MODULE_METADATA.MODULES, module_config.module) or []
5058
)
5159
for module in modules:
60+
if isinstance(module, ForwardRefModule):
61+
# will be initialized using module_config moduleRef setup
62+
continue
63+
5264
if isinstance(module, LazyModuleImport):
5365
module = module.get_module(global_module_config.module.__name__)
5466

@@ -131,6 +143,15 @@ def _get_config_kwargs() -> t.Dict:
131143
routes = core_module_ref.get_routes()
132144
app.router.extend(routes)
133145

146+
for item in config.OVERRIDE_CORE_SERVICE:
147+
provider_type = item.get_type()
148+
if provider_type not in core_module_ref.providers:
149+
raise ImproperConfiguration(
150+
f"There is not core service identify as {provider_type}"
151+
)
152+
153+
core_module_ref.add_provider(item, export=True)
154+
134155
# app.setup_jinja_environment
135156
app.setup_jinja_environment()
136157

ellar/app/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def use_global_interceptors(
132132
self, *interceptors: t.Union[EllarInterceptor, t.Type[EllarInterceptor]]
133133
) -> None:
134134
self._global_interceptors.extend(interceptors)
135+
self._ensure_available_in_providers(*interceptors)
135136

136137
@property
137138
def injector(self) -> EllarInjector:
@@ -303,6 +304,9 @@ def _finalize_app_initialization(self) -> None:
303304
if isinstance(item, EllarMiddleware)
304305
]
305306
)
307+
self.injector.owner.add_provider(
308+
ProviderConfig(App, use_value=self, tag=self.__class__.__name__)
309+
)
306310

307311
def add_exception_handler(
308312
self,

ellar/auth/policy/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ def __init__(self, policy_1: PolicyType, requirement: t.Any) -> None:
139139
self._policy_1 = policy_1
140140
self.requirement = requirement
141141

142+
@property
143+
def policy_type(self) -> PolicyType:
144+
return self._policy_1
145+
142146
@t.no_type_check
143147
def __call__(
144148
self, *args: t.Any, **kwargs: t.Any

ellar/cache/module.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import typing as t
22

33
from ellar.common import IModuleSetup, Module
4-
from ellar.core import Config, DynamicModule, ModuleBase, ModuleSetup
4+
from ellar.core.conf import Config
5+
from ellar.core.modules import DynamicModule, ModuleBase, ModuleRefBase, ModuleSetup
56
from ellar.di import ProviderConfig
67

78
from .interface import ICacheService
@@ -38,20 +39,21 @@ def setup(
3839

3940
@classmethod
4041
def register_setup(cls) -> ModuleSetup:
41-
return ModuleSetup(cls, inject=[Config], factory=cls.register_setup_factory)
42+
return ModuleSetup(cls, inject=[Config], factory=cls.__register_setup_factory)
4243

4344
@staticmethod
44-
def register_setup_factory(
45-
module: t.Type["CacheModule"], config: Config
45+
def __register_setup_factory(
46+
module_ref: "ModuleRefBase", config: Config
4647
) -> DynamicModule:
4748
if config.CACHES:
4849
schema = CacheModuleSchemaSetup(**{"CACHES": config.CACHES})
50+
module = t.cast(t.Type[CacheModule], module_ref.module)
4951
return module._create_dynamic_module(schema)
5052

5153
cache_service = CacheService()
5254

5355
return DynamicModule(
54-
module,
56+
module_ref.module,
5557
providers=[
5658
ProviderConfig(CacheService, use_value=cache_service),
5759
ProviderConfig(ICacheService, use_value=cache_service),

ellar/common/interfaces/interceptor_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .context import IExecutionContext
55

66
if t.TYPE_CHECKING: # pragma: no cover
7-
from ellar.common.routing import RouteOperationBase
7+
from ellar.core.routing import RouteOperationBase
88

99

1010
class IInterceptorsConsumer(ABC):

ellar/common/models/controller.py

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

1212
@dataclasses.dataclass
1313
class NestedRouterInfo:
14-
router: t.Union["ModuleRouter", "ControllerBase"]
14+
router: t.Union["ModuleRouter", t.Type["ControllerBase"]]
1515
prefix: t.Optional[str] = None
1616

1717

@@ -30,7 +30,7 @@ def full_view_name(cls, name: str) -> str:
3030

3131
def add_router(
3232
cls,
33-
router: t.Union["ControllerBase", "ModuleRouter"],
33+
router: t.Union[t.Type["ControllerBase"], "ModuleRouter"],
3434
prefix: t.Optional[str] = None,
3535
) -> None:
3636
if prefix:

ellar/common/operations/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def control_type(self) -> t.Type[t.Any]:
5252

5353
def add_router(
5454
self,
55-
router: t.Union["ModuleRouter", "ControllerBase"],
55+
router: t.Union["ModuleRouter", t.Type["ControllerBase"]],
5656
prefix: t.Optional[str] = None,
5757
) -> None:
5858
if prefix:

ellar/core/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
from .execution_context import ExecutionContext, HostContext
77
from .guards import GuardConsumer
88
from .interceptors import EllarInterceptorConsumer
9-
from .modules import DynamicModule, LazyModuleImport, ModuleBase, ModuleSetup
9+
from .modules import (
10+
DynamicModule,
11+
ForwardRefModule,
12+
LazyModuleImport,
13+
ModuleBase,
14+
ModuleSetup,
15+
)
1016
from .services import Reflector, reflector
1117
from .shortcuts import host, mount
1218
from .versioning import VersioningSchemes
@@ -33,6 +39,7 @@
3339
"current_injector",
3440
"config",
3541
"ApplicationContext",
42+
"ForwardRefModule",
3643
]
3744

3845

ellar/core/conf/app_settings_models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
from ellar.common.templating import JinjaLoaderType
1313
from ellar.common.types import ASGIApp, TReceive, TScope, TSend
1414
from ellar.core.conf.mixins import ConfigDefaultTypesMixin
15+
from ellar.di import ProviderConfig
1516
from ellar.di.injector.tree_manager import ModuleTreeManager
1617
from ellar.pydantic import ENCODERS_BY_TYPE as encoders_by_type
17-
from ellar.pydantic import field_validator
18+
from ellar.pydantic import AllowTypeOfSource, field_validator
1819
from starlette.exceptions import HTTPException as StarletteHTTPException
1920
from starlette.websockets import WebSocketClose
21+
from typing_extensions import Annotated
2022

2123
if t.TYPE_CHECKING: # pragma: no cover
2224
from ellar.app.main import App
@@ -52,6 +54,8 @@ class ConfigValidationSchema(Serializer, ConfigDefaultTypesMixin):
5254

5355
model_config = {"validate_assignment": True, "from_attributes": True}
5456

57+
OVERRIDE_CORE_SERVICE: t.List[Annotated[ProviderConfig, AllowTypeOfSource()]] = []
58+
5559
DEBUG: bool = False
5660

5761
DEFAULT_JSON_CLASS: t.Type[JSONResponse] = JSONResponse

0 commit comments

Comments
 (0)