Coverage for tests/test_tutorial/test_extra_models/test_tutorial004.py: 100%
11 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
1from fastapi.testclient import TestClient 1abcde
3from docs_src.extra_models.tutorial004 import app 1abcde
5client = TestClient(app) 1abcde
8def test_get_items(): 1abcde
9 response = client.get("/items/") 1abcde
10 assert response.status_code == 200, response.text 1abcde
11 assert response.json() == [ 1abcde
12 {"name": "Foo", "description": "There comes my hero"},
13 {"name": "Red", "description": "It's my aeroplane"},
14 ]
17def test_openapi_schema(): 1abcde
18 response = client.get("/openapi.json") 1abcde
19 assert response.status_code == 200, response.text 1abcde
20 assert response.json() == { 1abcde
21 "openapi": "3.1.0",
22 "info": {"title": "FastAPI", "version": "0.1.0"},
23 "paths": {
24 "/items/": {
25 "get": {
26 "responses": {
27 "200": {
28 "description": "Successful Response",
29 "content": {
30 "application/json": {
31 "schema": {
32 "title": "Response Read Items Items Get",
33 "type": "array",
34 "items": {"$ref": "#/components/schemas/Item"},
35 }
36 }
37 },
38 }
39 },
40 "summary": "Read Items",
41 "operationId": "read_items_items__get",
42 }
43 }
44 },
45 "components": {
46 "schemas": {
47 "Item": {
48 "title": "Item",
49 "required": ["name", "description"],
50 "type": "object",
51 "properties": {
52 "name": {"title": "Name", "type": "string"},
53 "description": {"title": "Description", "type": "string"},
54 },
55 }
56 }
57 },
58 }