Skip to content

Commit 546a61e

Browse files
authored
Merge pull request #6 from eadwinCode/ellar_refactor_bug_fix
fixed refactor bug
2 parents 8e89938 + 7993aec commit 546a61e

File tree

9 files changed

+22
-24
lines changed

9 files changed

+22
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ The global guard check can be skipped using the `@skip_throttle()` decorator men
7070
Example with `@guards(ThrottlerGuard)`
7171
```python
7272
# project_name/controller.py
73-
from ellar.common import Controller, guards
73+
from ellar.common import Controller, Guards
7474
from ellar_throttler import throttle, ThrottlerGuard
7575

7676
@Controller()
7777
class AppController:
7878

79-
@guards(ThrottlerGuard)
79+
@Guards(ThrottlerGuard)
8080
@throttle(limit=5, ttl=30)
8181
def normal(self):
8282
pass
@@ -178,7 +178,7 @@ To work with Websockets you can extend the `ThrottlerGuard` and override the `ha
178178
```python
179179
from ellar_throttler import ThrottlerGuard
180180
from ellar.di import injectable
181-
from ellar.core import IExecutionContext
181+
from ellar.common import IExecutionContext
182182
from ellar_throttler import ThrottledException
183183

184184
@injectable()

ellar_throttler/exception.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22
import typing as t
33

4-
from ellar.core.exceptions import APIException
4+
from ellar.common import APIException
55
from starlette import status
66

77

ellar_throttler/module.py

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

3-
from ellar.common import Module
4-
from ellar.core import IExecutionContext
5-
from ellar.core.modules import DynamicModule, IModuleSetup, ModuleBase
3+
from ellar.common import IExecutionContext, IModuleSetup, Module
4+
from ellar.core.modules import DynamicModule, ModuleBase
65
from ellar.di import ProviderConfig
76

87
from ellar_throttler.interfaces import IThrottlerStorage
@@ -29,7 +28,7 @@ def setup(
2928
IThrottlerStorage, use_class=ThrottlerStorageService
3029
)
3130

32-
return DynamicModule( # type: ignore
31+
return DynamicModule( # type:ignore
3332
cls,
3433
providers=[
3534
_provider,

ellar_throttler/throttler_guard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import hashlib
22
import typing as t
33

4-
from ellar.core import GuardCanActivate, IExecutionContext, Response
4+
from ellar.common import GuardCanActivate, IExecutionContext, Response
5+
from ellar.common.helper import get_name
56
from ellar.core.connection import HTTPConnection
7+
from ellar.core.services import Reflector
68
from ellar.di import injectable
7-
from ellar.helper import get_name
8-
from ellar.services import Reflector
99

1010
from .constants import THROTTLER_LIMIT, THROTTLER_SKIP, THROTTLER_TTL
1111
from .exception import ThrottledException

ellar_throttler/throttler_module_options.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import typing as t
22

3-
from ellar.core import IExecutionContext
4-
from ellar.serializer import Serializer
3+
from ellar.common import IExecutionContext, Serializer
54

65

76
class ThrottlerModuleOptions(Serializer):

ellar_throttler/throttler_storage_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ellar.serializer import Serializer
1+
from ellar.common import Serializer
22

33

44
class ThrottlerStorageOption(Serializer):

ellar_throttler/throttler_storage_record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ellar.serializer import Serializer
1+
from ellar.common import Serializer
22

33

44
class ThrottlerStorageRecord(Serializer):

pyproject.toml

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

4343
dependencies = [
44-
"ellar >= 0.3.4"
44+
"ellar >= 0.3.8"
4545
]
4646

4747

tests/test_throttler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from app.server import app
66
from ellar.cache import CacheModule
77
from ellar.cache.backends.local_cache import LocalMemCacheBackend
8-
from ellar.core import TestClient, TestClientFactory
8+
from ellar.testing import Test, TestClient
99

1010
from ellar_throttler import (
1111
CacheThrottlerStorageService,
@@ -85,15 +85,15 @@ def test_default_controller_index(self):
8585

8686
class TestSkipIfConfigure:
8787
def test_skip_configure(self):
88-
test_module = TestClientFactory.create_test_module(
88+
test_module = Test.create_test_module(
8989
modules=(
9090
ThrottlerModule.setup(limit=5, ttl=100, skip_if=lambda ctx: True),
9191
ControllerModule,
9292
),
9393
global_guards=[ThrottlerGuard],
9494
)
9595

96-
_client = test_module.get_client()
96+
_client = test_module.get_test_client()
9797
for i in range(15):
9898
res = _client.get("/")
9999

@@ -106,7 +106,7 @@ def test_skip_configure(self):
106106

107107

108108
class TestThrottlerStorageServiceConfiguration:
109-
test_module_cache = TestClientFactory.create_test_module(
109+
test_module_cache = Test.create_test_module(
110110
modules=(
111111
ThrottlerModule.setup(
112112
limit=5, ttl=100, storage=CacheThrottlerStorageService
@@ -118,7 +118,7 @@ class TestThrottlerStorageServiceConfiguration:
118118
config_module=dict(CACHES={"default": LocalMemCacheBackend()}),
119119
)
120120

121-
test_module_use_value = TestClientFactory.create_test_module(
121+
test_module_use_value = Test.create_test_module(
122122
modules=(
123123
ThrottlerModule.setup(limit=5, ttl=100, storage=ThrottlerStorageService()),
124124
ControllerModule,
@@ -138,7 +138,7 @@ def request_for_limit(self, app_client, url, limit):
138138

139139
@pytest.mark.parametrize("test_module", [test_module_cache, test_module_use_value])
140140
def test_limit_index(self, test_module):
141-
_client = test_module.get_client()
141+
_client = test_module.get_test_client()
142142

143143
for url, limit in [("/limit/", 2), ("/limit/higher", 5)]:
144144
self.request_for_limit(_client, url, limit)
@@ -151,7 +151,7 @@ def test_limit_index(self, test_module):
151151

152152
@pytest.mark.parametrize("test_module", [test_module_cache, test_module_use_value])
153153
def test_limit_get_shorter(self, test_module):
154-
_client = test_module.get_client()
154+
_client = test_module.get_test_client()
155155
limit, url = (
156156
5,
157157
"/limit/shorter",
@@ -167,7 +167,7 @@ def test_limit_get_shorter(self, test_module):
167167

168168
@pytest.mark.parametrize("test_module", [test_module_use_value])
169169
def test_limit_get_shorter_cache_clear(self, test_module):
170-
_client = test_module.get_client()
170+
_client = test_module.get_test_client()
171171
limit, url = (
172172
5,
173173
"/limit/shorter-2",

0 commit comments

Comments
 (0)