Debian Codegraph @

tests/test_tutorial/test_custom_request_and_route/test_tutorial003.py

raw
1 import importlib
2
3 import pytest
4 from fastapi.testclient import TestClient
5
6 from tests.utils import needs_py310
7
8
9 @pytest.fixture(
10 name="client",
11 params=[
12 pytest.param("tutorial003_py310", marks=needs_py310),
13 ],
14 )
15 def get_client(request: pytest.FixtureRequest):
16 mod = importlib.import_module(f"docs_src.custom_request_and_route.{request.param}")
17
18 client = TestClient(mod.app)
19 return client
20
21
22 def test_get(client: TestClient):
23 response = client.get("/")
24 assert response.json() == {"message": "Not timed"}
25 assert "X-Response-Time" not in response.headers
26
27
28 def test_get_timed(client: TestClient):
29 response = client.get("/timed")
30 assert response.json() == {"message": "It's the time of my life"}
31 assert "X-Response-Time" in response.headers
32 assert float(response.headers["X-Response-Time"]) >= 0