Coverage for tests / test_tutorial / test_additional_status_codes / test_tutorial001.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import importlib 1abdc

2 

3import pytest 1abdc

4from fastapi.testclient import TestClient 1abdc

5 

6from ...utils import needs_py310 1abdc

7 

8 

9@pytest.fixture( 1abdc

10 name="client", 

11 params=[ 

12 pytest.param("tutorial001_py310", marks=needs_py310), 

13 pytest.param("tutorial001_an_py310", marks=needs_py310), 

14 ], 

15) 

16def get_client(request: pytest.FixtureRequest): 1abdc

17 mod = importlib.import_module(f"docs_src.additional_status_codes.{request.param}") 1abc

18 

19 client = TestClient(mod.app) 1abc

20 return client 1abc

21 

22 

23def test_update(client: TestClient): 1abdc

24 response = client.put("/items/foo", json={"name": "Wrestlers"}) 1efg

25 assert response.status_code == 200, response.text 1efg

26 assert response.json() == {"name": "Wrestlers", "size": None} 1efg

27 

28 

29def test_create(client: TestClient): 1abdc

30 response = client.put("/items/red", json={"name": "Chillies"}) 1hij

31 assert response.status_code == 201, response.text 1hij

32 assert response.json() == {"name": "Chillies", "size": None} 1hij