Coverage for tests/test_tutorial/test_custom_request_and_route/test_tutorial001.py: 100%
25 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-13 13:38 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-13 13:38 +0000
1import gzip 1abcde
2import json 1abcde
4import pytest 1abcde
5from fastapi import Request 1abcde
6from fastapi.testclient import TestClient 1abcde
8from docs_src.custom_request_and_route.tutorial001 import app 1abcde
11@app.get("/check-class") 1abcde
12async def check_gzip_request(request: Request): 1abcde
13 return {"request_class": type(request).__name__} 1klmno
16client = TestClient(app) 1abcde
19@pytest.mark.parametrize("compress", [True, False]) 1abcde
20def test_gzip_request(compress): 1abcde
21 n = 1000 1fghij
22 headers = {} 1fghij
23 body = [1] * n 1fghij
24 data = json.dumps(body).encode() 1fghij
25 if compress: 1fghij
26 data = gzip.compress(data) 1fghij
27 headers["Content-Encoding"] = "gzip" 1fghij
28 headers["Content-Type"] = "application/json" 1fghij
29 response = client.post("/sum", content=data, headers=headers) 1fghij
30 assert response.json() == {"sum": n} 1fghij
33def test_request_class(): 1abcde
34 response = client.get("/check-class") 1klmno
35 assert response.json() == {"request_class": "GzipRequest"} 1klmno