|
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 |
3 | 7 |
|
4 | 8 |
|
5 | 9 | 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") |
8 | 11 |
|
9 | 12 |
|
10 | 13 | 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") |
13 | 15 |
|
14 | 16 |
|
15 | 17 | 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") |
18 | 19 |
|
19 | 20 |
|
20 | 21 | def test_404(client: TestClient) -> None: |
21 | 22 | response = client.get("/404") |
22 | 23 | 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