Skip to content

Commit 5abaefd

Browse files
committed
Add middleware tests
1 parent 9433af9 commit 5abaefd

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

tests/test_middleware.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
from fastapi import status
2-
from fastapi.testclient import TestClient
1+
from fastapi import FastAPI, Request, status
2+
3+
from debug_toolbar.middleware import show_toolbar
4+
from debug_toolbar.settings import DebugToolbarSettings
5+
6+
from .testclient import TestClient
37

48

59
def test_sync(client: TestClient) -> None:
6-
response = client.get("/sync")
7-
assert response.status_code == status.HTTP_200_OK
10+
assert client.get_store_id("/sync")
811

912

1013
def test_async(client: TestClient) -> None:
11-
response = client.get("/async")
12-
assert response.status_code == status.HTTP_200_OK
14+
assert client.get_store_id("/async")
1315

1416

1517
def test_json(client: TestClient) -> None:
16-
response = client.get("/openapi.json")
17-
assert response.status_code == status.HTTP_200_OK
18+
assert client.get_store_id("/openapi.json")
1819

1920

2021
def test_404(client: TestClient) -> None:
2122
response = client.get("/404")
2223
assert response.status_code == status.HTTP_404_NOT_FOUND
24+
25+
26+
def test_show_toolbar_not_allowed(app: FastAPI) -> None:
27+
scope = {
28+
"app": app,
29+
"type": "http",
30+
"client": ("invalid", 80),
31+
}
32+
request = Request(scope=scope)
33+
settings = DebugToolbarSettings(ALLOWED_HOSTS=["test"])
34+
assert not show_toolbar(request, settings)

0 commit comments

Comments
 (0)