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 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +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") 1abcd
18 assert response.status_code == 404, response.text 1abcd
19 assert response.json() == {"detail": "Item not found, there's only a plumbus here"} 1abcd
22@needs_py39 1eabcd
23def test_get(client: TestClient): 1eabcd
24 response = client.get("/items/plumbus") 1abcd
25 assert response.status_code == 200, response.text 1abcd
26 assert response.json() == "plumbus" 1abcd
29@needs_py39 1eabcd
30def test_internal_error(client: TestClient): 1eabcd
31 from docs_src.dependencies.tutorial008d_an_py39 import InternalError 1abcd
33 with pytest.raises(InternalError) as exc_info: 1abcd
34 client.get("/items/portal-gun") 1abcd
35 assert ( 1abcd
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 1abcd
44 client = TestClient(app, raise_server_exceptions=False) 1abcd
45 response = client.get("/items/portal-gun") 1abcd
46 assert response.status_code == 500, response.text 1abcd
47 assert response.text == "Internal Server Error" 1abcd