Coverage for tests / test_tutorial / test_advanced_middleware / test_tutorial003.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from fastapi.responses import PlainTextResponse 1efgh

2from fastapi.testclient import TestClient 1efgh

3 

4from docs_src.advanced_middleware.tutorial003_py310 import app 1efgh

5 

6 

7@app.get("/large") 1efgh

8async def large(): 1efgh

9 return PlainTextResponse("x" * 4000, status_code=200) 1abcd

10 

11 

12client = TestClient(app) 1efgh

13 

14 

15def test_middleware(): 1efgh

16 response = client.get("/large", headers={"accept-encoding": "gzip"}) 1abcd

17 assert response.status_code == 200, response.text 1abcd

18 assert response.text == "x" * 4000 1abcd

19 assert response.headers["Content-Encoding"] == "gzip" 1abcd

20 assert int(response.headers["Content-Length"]) < 4000 1abcd

21 response = client.get("/") 1abcd

22 assert response.status_code == 200, response.text 1abcd