|
| 1 | +import pytest |
1 | 2 | from ninja_extra.operation import AsyncOperation |
2 | 3 |
|
3 | 4 | from easy import EasyAPI |
@@ -34,31 +35,34 @@ def test_auto_generate_admin_api(): |
34 | 35 |
|
35 | 36 | async def test_auto_apis(transactional_db, user, easy_api_client): |
36 | 37 | for controller_class in controllers: |
37 | | - if not str(controller_class).endswith("ClientAdminAPIController"): |
38 | | - continue |
39 | | - client = easy_api_client(controller_class, api_user=user, has_perm=True) |
40 | | - response = await client.get("/", data={}, json={}, user=user) |
41 | | - assert response.status_code == 403 |
| 38 | + if str(controller_class).endswith("ClientAdminAPIController"): |
| 39 | + client = easy_api_client(controller_class, api_user=user, has_perm=True) |
| 40 | + response = await client.get("/", data={}, json={}, user=user) |
| 41 | + assert response.status_code == 403 |
42 | 42 |
|
43 | | - client = easy_api_client( |
44 | | - controller_class, api_user=user, has_perm=True, is_staff=True |
45 | | - ) |
46 | | - response = await client.get("/", data={}, json={}, user=user) |
47 | | - assert response.status_code == 200 |
48 | | - assert response.json()["data"] == [] |
| 43 | + client = easy_api_client( |
| 44 | + controller_class, api_user=user, has_perm=True, is_staff=True |
| 45 | + ) |
| 46 | + response = await client.get("/", data={}, json={}, user=user) |
| 47 | + assert response.status_code == 200 |
| 48 | + assert response.json()["data"] == [] |
49 | 49 |
|
50 | | - client = easy_api_client( |
51 | | - controller_class, api_user=user, has_perm=True, is_staff=True |
52 | | - ) |
53 | | - response = await client.delete("/20000") |
54 | | - assert response.status_code == 403 |
| 50 | + client = easy_api_client( |
| 51 | + controller_class, api_user=user, has_perm=True, is_staff=True |
| 52 | + ) |
| 53 | + response = await client.delete("/20000") |
| 54 | + assert response.status_code == 403 |
55 | 55 |
|
56 | | - client = easy_api_client( |
57 | | - controller_class, api_user=user, has_perm=True, is_staff=True |
58 | | - ) |
59 | | - response = await client.delete("/20000", data={}, json={}, user=user) |
60 | | - assert response.status_code == 200 |
61 | | - assert response.json()["code"] == 404 |
| 56 | + client = easy_api_client( |
| 57 | + controller_class, api_user=user, has_perm=True, is_staff=True |
| 58 | + ) |
| 59 | + response = await client.delete("/20000", data={}, json={}, user=user) |
| 60 | + assert response.status_code == 200 |
| 61 | + assert response.json()["code"] == 404 |
| 62 | + elif str(controller_class).endswith("CategoryAdminAPIController"): |
| 63 | + client = easy_api_client(controller_class, api_user=user, has_perm=True) |
| 64 | + with pytest.raises(Exception): |
| 65 | + await client.get("/", data={}, json={}, user=user) |
62 | 66 |
|
63 | 67 |
|
64 | 68 | async def test_auto_generation_settings(settings): |
|
0 commit comments