Coverage for tests / test_tutorial / test_dependencies / test_tutorial008b.py: 100%
20 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1import importlib 1abcd
3import pytest 1abcd
4from fastapi.testclient import TestClient 1abcd
7@pytest.fixture( 1abcd
8 name="client",
9 params=[
10 pytest.param("tutorial008b_py310"),
11 pytest.param("tutorial008b_an_py310"),
12 ],
13)
14def get_client(request: pytest.FixtureRequest): 1abcd
15 mod = importlib.import_module(f"docs_src.dependencies.{request.param}") 1efghijklmnopqrstuvwx
17 client = TestClient(mod.app) 1efghijklmnopqrstuvwx
18 return client 1efghijklmnopqrstuvwx
21def test_get_no_item(client: TestClient): 1abcd
22 response = client.get("/items/foo") 1yzABCDEF
23 assert response.status_code == 404, response.text 1yzABCDEF
24 assert response.json() == {"detail": "Item not found"} 1yzABCDEF
27def test_owner_error(client: TestClient): 1abcd
28 response = client.get("/items/plumbus") 1GHIJKLMN
29 assert response.status_code == 400, response.text 1GHIJKLMN
30 assert response.json() == {"detail": "Owner error: Rick"} 1GHIJKLMN
33def test_get_item(client: TestClient): 1abcd
34 response = client.get("/items/portal-gun") 1OPQRSTUV
35 assert response.status_code == 200, response.text 1OPQRSTUV
36 assert response.json() == {"description": "Gun to create portals", "owner": "Rick"} 1OPQRSTUV