Debian Codegraph @

tests/test_tutorial/test_additional_status_codes/test_tutorial001.py

raw
1 import importlib
2
3 import pytest
4 from fastapi.testclient import TestClient
5
6 from ...utils import needs_py310
7
8
9 @pytest.fixture(
10 name="client",
11 params=[
12 pytest.param("tutorial001_py310", marks=needs_py310),
13 pytest.param("tutorial001_an_py310", marks=needs_py310),
14 ],
15 )
16 def get_client(request: pytest.FixtureRequest):
17 mod = importlib.import_module(f"docs_src.additional_status_codes.{request.param}")
18
19 client = TestClient(mod.app)
20 return client
21
22
23 def test_update(client: TestClient):
24 response = client.put("/items/foo", json={"name": "Wrestlers"})
25 assert response.status_code == 200, response.text
26 assert response.json() == {"name": "Wrestlers", "size": None}
27
28
29 def test_create(client: TestClient):
30 response = client.put("/items/red", json={"name": "Chillies"})
31 assert response.status_code == 201, response.text
32 assert response.json() == {"name": "Chillies", "size": None}