Skip to content

Commit e5a6455

Browse files
committed
✅ Add test for disabling a single route
1 parent d408341 commit e5a6455

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed
Lines changed: 24 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,16 @@ 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+
[app.include_router(router(**s, delete_all_route=False, update_route=False)) for s in settings]
32+
33+
yield from yield_test_client(app, impl)
34+
35+
2736
@pytest.mark.parametrize("url", URLS)
2837
def test_route_disable(client, url):
2938
assert client.get(url).status_code == 404
@@ -34,3 +43,13 @@ def test_route_disable(client, url):
3443
assert client.get(f"{url}/{id_}").status_code == 404
3544
assert client.put(f"{url}/{id_}").status_code == 404
3645
assert client.delete(f"{url}/{id_}").status_code == 404
46+
47+
48+
def test_route_disable_single(delete_all_client):
49+
url = "/potato"
50+
51+
assert delete_all_client.delete(url).status_code == 405
52+
53+
test_router.test_post(delete_all_client, url)
54+
assert delete_all_client.put(f"{url}/{1}").status_code == 405
55+
assert delete_all_client.delete(f"{url}/{1}").status_code == 200

0 commit comments

Comments
 (0)