Skip to content

Commit 318329a

Browse files
authored
Merge pull request #96 from awtkns/95_delete_endpoint_disable_test
Add test for disabling a single route
2 parents 355dd73 + e5e9c8f commit 318329a

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
from fastapi import Depends, HTTPException
2-
from fastapi.security import OAuth2PasswordBearer
3-
41
import pytest
52

63
from fastapi_crudrouter.core import CRUDGenerator
74

85
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+
109

1110
URLS = ["/potato", "/carrot"]
1211
AUTH = {"Authorization": "Bearer my_token"}
1312
KEY_WORDS = {f"{r}_route" for r in CRUDGenerator.get_routes()}
1413
DISABLE_KWARGS = {k: False for k in KEY_WORDS}
1514

1615

17-
@pytest.fixture(params=implementations, scope="class")
16+
@pytest.fixture(params=implementations, ids=label_func, scope="class")
1817
def client(request):
1918
impl, dsn = request.param
2019

@@ -24,6 +23,19 @@ def client(request):
2423
yield from yield_test_client(app, impl)
2524

2625

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+
2739
@pytest.mark.parametrize("url", URLS)
2840
def test_route_disable(client, url):
2941
assert client.get(url).status_code == 404
@@ -34,3 +46,13 @@ def test_route_disable(client, url):
3446
assert client.get(f"{url}/{id_}").status_code == 404
3547
assert client.put(f"{url}/{id_}").status_code == 404
3648
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

Comments
 (0)