Skip to content

Commit 8cf17fd

Browse files
committed
lint: unit test
1 parent 3b01ad8 commit 8cf17fd

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

easy/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def docs_permission_required(
5454
member, redirecting to the login page if necessary.
5555
"""
5656
actual_decorator = request_passes_test(
57-
lambda r: ((r.user.is_active and r.user.is_staff)),
57+
lambda r: (r.user.is_active and r.user.is_staff),
5858
login_url=login_url,
5959
redirect_field_name=redirect_field_name,
6060
)

easy/response.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
2-
from typing import Any, Dict, Union
2+
from typing import Any, Dict, List, Union
33

4+
from django.db.models import QuerySet
45
from django.http.response import JsonResponse
56

67
from easy.renderer.json import EasyJSONEncoder
@@ -17,7 +18,7 @@ class BaseApiResponse(JsonResponse):
1718

1819
def __init__(
1920
self,
20-
data: Union[Dict, str] = None,
21+
data: Union[Dict, str, bool, List[Any], QuerySet] = None,
2122
code: int = None,
2223
message: str = None,
2324
**kwargs: Any

tests/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import copy
2+
from typing import Callable, Type, Union
23

34
import pytest
45
from django.contrib.auth import get_user_model
6+
from ninja_extra import ControllerBase, Router
57

6-
from easy.controller.base import CrudAPIController
8+
from easy import EasyAPI
79
from easy.testing import EasyTestClient
810

911
from .easy_app.auth import JWTAuthAsync, jwt_auth_async
@@ -23,7 +25,7 @@ def user(db) -> User:
2325

2426

2527
@pytest.fixture
26-
def easy_api_client(user) -> EasyTestClient:
28+
def easy_api_client(user) -> Callable:
2729
orig_func = copy.deepcopy(JWTAuthAsync.__call__)
2830

2931
orig_has_perm_fuc = copy.deepcopy(user.has_perm)
@@ -41,11 +43,11 @@ async def mock_func(self, request):
4143
setattr(JWTAuthAsync, "__call__", mock_func)
4244

4345
def create_client(
44-
api: CrudAPIController,
46+
api: Union[EasyAPI, Router, Type[ControllerBase]],
4547
is_staff: bool = False,
4648
is_superuser: bool = False,
4749
has_perm: bool = False,
48-
):
50+
) -> "EasyTestClient":
4951
setattr(user, "is_staff", is_staff)
5052
setattr(user, "is_superuser", is_superuser)
5153
if is_superuser:

tests/easy_app/controllers.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class AutoGenCrudAPIController(CrudAPIController):
2323
"""
2424
For unit testings of the following auto generated APIs:
25-
get/create/patch/delete/filter/filter_exclude
25+
get/create/patch/delete
2626
"""
2727

2828
def __init__(self, service: EventService):
@@ -36,7 +36,7 @@ class Meta:
3636
@api_controller("unittest", permissions=[BaseApiPermission])
3737
class RecursiveAPIController(CrudAPIController):
3838
"""
39-
For unit testings of no recursive configuration
39+
For unit testings of recursive configuration
4040
"""
4141

4242
def __init__(self, service: EventService):
@@ -52,7 +52,7 @@ class Meta:
5252
@api_controller("unittest", permissions=[BaseApiPermission])
5353
class InheritedRecursiveAPIController(AutoGenCrudAPIController):
5454
"""
55-
For unit testings of no recursive configuration
55+
For unit testings of inherited recursive configuration
5656
"""
5757

5858
def __init__(self, service: EventService):
@@ -181,6 +181,10 @@ async def test_perm_admin_site(self, request, word: str):
181181

182182
@api_controller("unittest", permissions=[AdminSitePermission])
183183
class AdminSitePermissionAPIController(CrudAPIController):
184+
"""
185+
For unit testings of AdminSite permissions class
186+
"""
187+
184188
def __init__(self, service: EventService):
185189
super().__init__(service)
186190
self.service = service
@@ -191,6 +195,10 @@ class Meta:
191195

192196
@api_controller("unittest", permissions=[AdminSitePermission])
193197
class NoCrudAPIController(CrudAPIController):
198+
"""
199+
For unit testings of no crud configuration
200+
"""
201+
194202
def __init__(self, service: EventService):
195203
super().__init__(service)
196204
self.service = service
@@ -202,6 +210,10 @@ class Meta:
202210

203211
@api_controller("unittest", permissions=[AdminSitePermission])
204212
class NoCrudInheritedAPIController(AdminSitePermissionAPIController):
213+
"""
214+
For unit testings of no crud configuration (Inherited Class)
215+
"""
216+
205217
def __init__(self, service: EventService):
206218
super().__init__(service)
207219
self.service = service

tests/easy_app/urls.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
from django.contrib import admin
22
from django.urls import path
33

4-
from easy import EasyAPI
5-
6-
from .controllers import (
7-
AutoGenCrudAPIController,
8-
EasyCrudAPIController,
9-
PermissionAPIController,
10-
)
11-
12-
api = EasyAPI()
13-
api.register_controllers(EasyCrudAPIController)
14-
api.register_controllers(PermissionAPIController)
15-
api.register_controllers(AutoGenCrudAPIController)
16-
4+
from .apis import api_unittest
175

186
urlpatterns = [
197
path("admin/", admin.site.urls),
20-
path("api/", api.urls),
8+
path("api/", api_unittest.urls),
219
]

tests/test_api_base_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_base_api_edit():
4545
)
4646

4747
with pytest.raises(KeyError):
48-
orig_resp.json_data["detail"]
48+
print(orig_resp.json_data["detail"])
4949

5050
data = orig_resp.json_data
5151

0 commit comments

Comments
 (0)