Coverage for tests/test_tutorial/test_dependencies/test_tutorial008b.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1import importlib 1abcdefg

2 

3import pytest 1abcdefg

4from fastapi.testclient import TestClient 1abcdefg

5 

6from ...utils import needs_py39 1abcdefg

7 

8 

9@pytest.fixture( 1abcdefg

10 name="client", 

11 params=[ 

12 "tutorial008b", 

13 "tutorial008b_an", 

14 pytest.param("tutorial008b_an_py39", marks=needs_py39), 

15 ], 

16) 

17def get_client(request: pytest.FixtureRequest): 1abcdefg

18 mod = importlib.import_module(f"docs_src.dependencies.{request.param}") 1abcdefg

19 

20 client = TestClient(mod.app) 1abcdefg

21 return client 1abcdefg

22 

23 

24def test_get_no_item(client: TestClient): 1abcdefg

25 response = client.get("/items/foo") 1hijklmn

26 assert response.status_code == 404, response.text 1hijklmn

27 assert response.json() == {"detail": "Item not found"} 1hijklmn

28 

29 

30def test_owner_error(client: TestClient): 1abcdefg

31 response = client.get("/items/plumbus") 1opqrstu

32 assert response.status_code == 400, response.text 1opqrstu

33 assert response.json() == {"detail": "Owner error: Rick"} 1opqrstu

34 

35 

36def test_get_item(client: TestClient): 1abcdefg

37 response = client.get("/items/portal-gun") 1vwxyzAB

38 assert response.status_code == 200, response.text 1vwxyzAB

39 assert response.json() == {"description": "Gun to create portals", "owner": "Rick"} 1vwxyzAB