Skip to content

Commit 048ab57

Browse files
committed
fixed failing test
1 parent 366a545 commit 048ab57

File tree

31 files changed

+316
-77
lines changed

31 files changed

+316
-77
lines changed

ellar/cache/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def has_key(self, key: str, version: str = None, backend: str = None) -> bool:
6060
return _backend.has_key(key, version=version)
6161

6262

63-
@injectable # type: ignore
63+
@injectable
6464
class CacheService(_CacheServiceSync, ICacheService):
6565
"""
6666
A Cache Backend Service that wraps Ellar cache backends

ellar/common/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
exception_handler,
1313
extra_args,
1414
file,
15+
interceptors,
1516
middleware,
1617
openapi_info,
1718
render,
@@ -42,6 +43,7 @@
4243
IHTTPHostContext,
4344
IModuleSetup,
4445
IModuleTemplateLoader,
46+
InterceptorConsumer,
4547
IResponseModel,
4648
IWebSocketContextFactory,
4749
IWebSocketHostContext,
@@ -52,6 +54,7 @@
5254
BaseHttpAuth,
5355
ControllerBase,
5456
ControllerType,
57+
EllarInterceptor,
5558
GuardCanActivate,
5659
)
5760
from .params.decorators import (
@@ -191,6 +194,9 @@
191194
"IModuleSetup",
192195
"IResponseModel",
193196
"IModuleTemplateLoader",
197+
"InterceptorConsumer",
198+
"EllarInterceptor",
199+
"interceptors",
194200
]
195201

196202

ellar/common/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
ROUTE_OPENAPI_PARAMETERS = "ROUTE_OPENAPI_PARAMETERS"
5555

5656
OPERATION_ENDPOINT_KEY = "OPERATION_ENDPOINT"
57+
ROUTE_INTERCEPTORS = "ROUTE_INTERCEPTORS"
5758
CONTROLLER_OPERATION_HANDLER_KEY = "CONTROLLER_OPERATION_HANDLER"
5859
CONTROLLER_CLASS_KEY = "CONTROLLER_CLASS_KEY"
5960

ellar/common/decorators/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .file import file
88
from .guards import UseGuards
99
from .html import render, template_filter, template_global
10+
from .interceptor import interceptors
1011
from .middleware import middleware
1112
from .modules import Module
1213
from .openapi import openapi_info
@@ -28,6 +29,7 @@
2829
"openapi_info",
2930
"Module",
3031
"extra_args",
32+
"interceptors",
3133
]
3234

3335

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import typing as t
2+
3+
from ellar.common.constants import ROUTE_INTERCEPTORS
4+
5+
from .base import set_metadata as set_meta
6+
7+
if t.TYPE_CHECKING: # pragma: no cover
8+
from ellar.common import EllarInterceptor
9+
10+
11+
def interceptors(
12+
*args: t.Union[t.Type["EllarInterceptor"], "EllarInterceptor"]
13+
) -> t.Callable:
14+
"""
15+
=========FUNCTION DECORATOR ==============
16+
17+
Programmatically adds extra route function parameter.
18+
see https://github.com/eadwinCode/ellar/blob/main/tests/test_routing/test_extra_args.py for usages
19+
:param args: Collection EllarInterceptor
20+
:return:
21+
"""
22+
return set_meta(ROUTE_INTERCEPTORS, list(args))

ellar/common/interfaces/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
IWebSocketHostContext,
1010
)
1111
from .exceptions import IExceptionHandler, IExceptionMiddlewareService
12+
from .interceptor_consumer import InterceptorConsumer
1213
from .module import IModuleSetup
1314
from .response_model import IResponseModel
1415
from .templating import IModuleTemplateLoader
@@ -27,4 +28,5 @@
2728
"IModuleSetup",
2829
"IResponseModel",
2930
"IModuleTemplateLoader",
31+
"InterceptorConsumer",
3032
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import typing as t
2+
from abc import ABC, abstractmethod
3+
4+
from .context import IExecutionContext
5+
6+
if t.TYPE_CHECKING: # pragma: no cover
7+
from ellar.common.routing import RouteOperationBase
8+
9+
10+
class InterceptorConsumer(ABC):
11+
@abstractmethod
12+
async def execute(
13+
self, context: IExecutionContext, route_operation: "RouteOperationBase"
14+
) -> t.Any:
15+
"""implementation goes here"""

ellar/common/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .controller import ControllerBase, ControllerType
22
from .guard import BaseAPIKey, BaseAuthGuard, BaseHttpAuth, GuardCanActivate
3+
from .interceptor import EllarInterceptor
34

45
__all__ = [
56
"ControllerBase",
@@ -8,4 +9,5 @@
89
"BaseAPIKey",
910
"BaseHttpAuth",
1011
"GuardCanActivate",
12+
"EllarInterceptor",
1113
]

ellar/common/models/interceptor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import typing as t
2+
from abc import ABC, abstractmethod
3+
4+
from ..interfaces import IExecutionContext
5+
6+
7+
class EllarInterceptor(ABC):
8+
@abstractmethod
9+
async def intercept(
10+
self, context: IExecutionContext, next_interceptor: t.Callable[..., t.Coroutine]
11+
) -> t.Any:
12+
"""implementation comes here"""

ellar/common/responses/models/json.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def create_response(
2929
t.Type[JSONResponse],
3030
context.get_app().config.DEFAULT_JSON_CLASS or self._response_type,
3131
)
32-
response_args, headers = self.get_context_response(context=context)
32+
response_args, headers = self.get_context_response(
33+
context=context, status_code=status_code
34+
)
3335
serializer_filter = reflect.get_metadata(
3436
SERIALIZER_FILTER_KEY, context.get_handler()
3537
)

0 commit comments

Comments
 (0)