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

20 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 

6 

7@pytest.fixture( 1abdc

8 name="client", 

9 params=[ 

10 pytest.param("tutorial008b_py310"), 

11 pytest.param("tutorial008b_an_py310"), 

12 ], 

13) 

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

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

16 

17 client = TestClient(mod.app) 1abc

18 return client 1abc

19 

20 

21def test_get_no_item(client: TestClient): 1abdc

22 response = client.get("/items/foo") 1efg

23 assert response.status_code == 404, response.text 1efg

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

25 

26 

27def test_owner_error(client: TestClient): 1abdc

28 response = client.get("/items/plumbus") 1hij

29 assert response.status_code == 400, response.text 1hij

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

31 

32 

33def test_get_item(client: TestClient): 1abdc

34 response = client.get("/items/portal-gun") 1klm

35 assert response.status_code == 200, response.text 1klm

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