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

21 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

1import importlib 1abcdef

2 

3import pytest 1abcdef

4from fastapi.testclient import TestClient 1abcdef

5 

6from ...utils import needs_py39 1abcdef

7 

8 

9@pytest.fixture( 1abcdef

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

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

19 

20 client = TestClient(mod.app) 1abcdef

21 return client 1abcdef

22 

23 

24def test_get_no_item(client: TestClient): 1abcdef

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

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

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

28 

29 

30def test_owner_error(client: TestClient): 1abcdef

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

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

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

34 

35 

36def test_get_item(client: TestClient): 1abcdef

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

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

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