| 1 |
from fastapi.testclient import TestClient |
| 2 |
|
| 3 |
from docs_src.advanced_middleware.tutorial002_py310 import app |
| 4 |
|
| 5 |
|
| 6 |
def test_middleware(): |
| 7 |
client = TestClient(app, base_url="http://example.com") |
| 8 |
response = client.get("/") |
| 9 |
assert response.status_code == 200, response.text |
| 10 |
client = TestClient(app, base_url="http://subdomain.example.com") |
| 11 |
response = client.get("/") |
| 12 |
assert response.status_code == 200, response.text |
| 13 |
client = TestClient(app, base_url="http://invalidhost") |
| 14 |
response = client.get("/") |
| 15 |
assert response.status_code == 400, response.text |