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

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-13 13:38 +0000

1import importlib 1abcde

2 

3import pytest 1abcde

4from fastapi.testclient import TestClient 1abcde

5 

6from ...utils import needs_py39, needs_py310 1abcde

7 

8 

9@pytest.fixture( 1abcde

10 name="client", 

11 params=[ 

12 "tutorial001", 

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

14 "tutorial001_an", 

15 pytest.param("tutorial001_an_py39", marks=needs_py39), 

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

17 ], 

18) 

19def get_client(request: pytest.FixtureRequest): 1abcde

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

21 

22 client = TestClient(mod.app) 1abcde

23 return client 1abcde

24 

25 

26def test_update(client: TestClient): 1abcde

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

28 assert response.status_code == 200, response.text 1fghij

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

30 

31 

32def test_create(client: TestClient): 1abcde

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

34 assert response.status_code == 201, response.text 1klmno

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