Coverage for tests/test_tutorial/test_dependencies/test_tutorial008d_an_py39.py: 100%
31 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-13 13:38 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-13 13:38 +0000
1import pytest 1eabcd
2from fastapi.testclient import TestClient 1eabcd
4from ...utils import needs_py39 1eabcd
7@pytest.fixture(name="client") 1eabcd
8def get_client(): 1eabcd
9 from docs_src.dependencies.tutorial008d_an_py39 import app 1abcd
11 client = TestClient(app) 1abcd
12 return client 1abcd
15@needs_py39 1eabcd
16def test_get_no_item(client: TestClient): 1eabcd
17 response = client.get("/items/foo") 1nopq
18 assert response.status_code == 404, response.text 1nopq
19 assert response.json() == {"detail": "Item not found, there's only a plumbus here"} 1nopq
22@needs_py39 1eabcd
23def test_get(client: TestClient): 1eabcd
24 response = client.get("/items/plumbus") 1rstu
25 assert response.status_code == 200, response.text 1rstu
26 assert response.json() == "plumbus" 1rstu
29@needs_py39 1eabcd
30def test_internal_error(client: TestClient): 1eabcd
31 from docs_src.dependencies.tutorial008d_an_py39 import InternalError 1jklm
33 with pytest.raises(InternalError) as exc_info: 1jklm
34 client.get("/items/portal-gun") 1jklm
35 assert ( 1jklm
36 exc_info.value.args[0] == "The portal gun is too dangerous to be owned by Rick"
37 )
40@needs_py39 1eabcd
41def test_internal_server_error(): 1eabcd
42 from docs_src.dependencies.tutorial008d_an_py39 import app 1fghi
44 client = TestClient(app, raise_server_exceptions=False) 1fghi
45 response = client.get("/items/portal-gun") 1fghi
46 assert response.status_code == 500, response.text 1fghi
47 assert response.text == "Internal Server Error" 1fghi