1
- from fastapi import Depends , HTTPException
2
- from fastapi .security import OAuth2PasswordBearer
3
-
4
1
import pytest
5
2
6
3
from fastapi_crudrouter .core import CRUDGenerator
7
4
8
5
from tests .implementations import implementations
9
- from tests .conftest import yield_test_client
6
+ from tests .conftest import yield_test_client , label_func
7
+ from tests import test_router
8
+
10
9
11
10
URLS = ["/potato" , "/carrot" ]
12
11
AUTH = {"Authorization" : "Bearer my_token" }
13
12
KEY_WORDS = {f"{ r } _route" for r in CRUDGenerator .get_routes ()}
14
13
DISABLE_KWARGS = {k : False for k in KEY_WORDS }
15
14
16
15
17
- @pytest .fixture (params = implementations , scope = "class" )
16
+ @pytest .fixture (params = implementations , ids = label_func , scope = "class" )
18
17
def client (request ):
19
18
impl , dsn = request .param
20
19
@@ -24,6 +23,19 @@ def client(request):
24
23
yield from yield_test_client (app , impl )
25
24
26
25
26
+ @pytest .fixture (params = implementations , ids = label_func , scope = "class" )
27
+ def delete_all_client (request ):
28
+ impl , dsn = request .param
29
+
30
+ app , router , settings = impl (db_uri = dsn )
31
+ [
32
+ app .include_router (router (** s , delete_all_route = False , update_route = False ))
33
+ for s in settings
34
+ ]
35
+
36
+ yield from yield_test_client (app , impl )
37
+
38
+
27
39
@pytest .mark .parametrize ("url" , URLS )
28
40
def test_route_disable (client , url ):
29
41
assert client .get (url ).status_code == 404
@@ -34,3 +46,13 @@ def test_route_disable(client, url):
34
46
assert client .get (f"{ url } /{ id_ } " ).status_code == 404
35
47
assert client .put (f"{ url } /{ id_ } " ).status_code == 404
36
48
assert client .delete (f"{ url } /{ id_ } " ).status_code == 404
49
+
50
+
51
+ def test_route_disable_single (delete_all_client ):
52
+ url = "/potato"
53
+
54
+ assert delete_all_client .delete (url ).status_code == 405
55
+
56
+ test_router .test_post (delete_all_client , url )
57
+ assert delete_all_client .put (f"{ url } /{ 1 } " ).status_code == 405
58
+ assert delete_all_client .delete (f"{ url } /{ 1 } " ).status_code == 200
0 commit comments