Coverage for tests/test_tutorial/test_advanced_middleware/test_tutorial003.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi.responses import PlainTextResponse 1abcde
2from fastapi.testclient import TestClient 1abcde
4from docs_src.advanced_middleware.tutorial003 import app 1abcde
7@app.get("/large") 1abcde
8async def large(): 1abcde
9 return PlainTextResponse("x" * 4000, status_code=200) 1abcde
12client = TestClient(app) 1abcde
15def test_middleware(): 1abcde
16 response = client.get("/large", headers={"accept-encoding": "gzip"}) 1abcde
17 assert response.status_code == 200, response.text 1abcde
18 assert response.text == "x" * 4000 1abcde
19 assert response.headers["Content-Encoding"] == "gzip" 1abcde
20 assert int(response.headers["Content-Length"]) < 4000 1abcde
21 response = client.get("/") 1abcde
22 assert response.status_code == 200, response.text 1abcde