Coverage for tests/test_tutorial/test_extra_models/test_tutorial004_py39.py: 100%
18 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.extra_models.tutorial004_py39 import app 1abcd
11 client = TestClient(app) 1abcd
12 return client 1abcd
15@needs_py39 1eabcd
16def test_get_items(client: TestClient): 1eabcd
17 response = client.get("/items/") 1abcd
18 assert response.status_code == 200, response.text 1abcd
19 assert response.json() == [ 1abcd
20 {"name": "Foo", "description": "There comes my hero"},
21 {"name": "Red", "description": "It's my aeroplane"},
22 ]
25@needs_py39 1eabcd
26def test_openapi_schema(client: TestClient): 1eabcd
27 response = client.get("/openapi.json") 1abcd
28 assert response.status_code == 200, response.text 1abcd
29 assert response.json() == { 1abcd
30 "openapi": "3.1.0",
31 "info": {"title": "FastAPI", "version": "0.1.0"},
32 "paths": {
33 "/items/": {
34 "get": {
35 "responses": {
36 "200": {
37 "description": "Successful Response",
38 "content": {
39 "application/json": {
40 "schema": {
41 "title": "Response Read Items Items Get",
42 "type": "array",
43 "items": {"$ref": "#/components/schemas/Item"},
44 }
45 }
46 },
47 }
48 },
49 "summary": "Read Items",
50 "operationId": "read_items_items__get",
51 }
52 }
53 },
54 "components": {
55 "schemas": {
56 "Item": {
57 "title": "Item",
58 "required": ["name", "description"],
59 "type": "object",
60 "properties": {
61 "name": {"title": "Name", "type": "string"},
62 "description": {"title": "Description", "type": "string"},
63 },
64 }
65 }
66 },
67 }