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-04-06 01:24 +0000

1import importlib 1abcd

2 

3import pytest 1abcd

4from fastapi.testclient import TestClient 1abcd

5 

6from ...utils import needs_py310 1abcd

7 

8 

9@pytest.fixture( 1abcd

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): 1abcd

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

18 

19 client = TestClient(mod.app) 1efghijklmnopq

20 return client 1efghijklmnopq

21 

22 

23def test_update(client: TestClient): 1abcd

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

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

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

27 

28 

29def test_create(client: TestClient): 1abcd

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

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

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