| 1 |
from fastapi.responses import PlainTextResponse |
| 2 |
from fastapi.testclient import TestClient |
| 3 |
|
| 4 |
from docs_src.advanced_middleware.tutorial003_py310 import app |
| 5 |
|
| 6 |
|
| 7 |
@app.get("/large") |
| 8 |
async def large(): |
| 9 |
return PlainTextResponse("x" * 4000, status_code=200) |
| 10 |
|
| 11 |
|
| 12 |
client = TestClient(app) |
| 13 |
|
| 14 |
|
| 15 |
def test_middleware(): |
| 16 |
response = client.get("/large", headers={"accept-encoding": "gzip"}) |
| 17 |
assert response.status_code == 200, response.text |
| 18 |
assert response.text == "x" * 4000 |
| 19 |
assert response.headers["Content-Encoding"] == "gzip" |
| 20 |
assert int(response.headers["Content-Length"]) < 4000 |
| 21 |
response = client.get("/") |
| 22 |
assert response.status_code == 200, response.text |