Coverage for tests/test_tutorial/test_additional_responses/test_tutorial003.py: 100%
15 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.additional_responses.tutorial003 import app 1abcde
5client = TestClient(app) 1abcde
8def test_path_operation(): 1abcde
9 response = client.get("/items/foo") 1abcde
10 assert response.status_code == 200, response.text 1abcde
11 assert response.json() == {"id": "foo", "value": "there goes my hero"} 1abcde
14def test_path_operation_not_found(): 1abcde
15 response = client.get("/items/bar") 1abcde
16 assert response.status_code == 404, response.text 1abcde
17 assert response.json() == {"message": "Item not found"} 1abcde
20def test_openapi_schema(): 1abcde
21 response = client.get("/openapi.json") 1abcde
22 assert response.status_code == 200, response.text 1abcde
23 assert response.json() == { 1abcde
24 "openapi": "3.1.0",
25 "info": {"title": "FastAPI", "version": "0.1.0"},
26 "paths": {
27 "/items/{item_id}": {
28 "get": {
29 "responses": {
30 "404": {
31 "description": "The item was not found",
32 "content": {
33 "application/json": {
34 "schema": {"$ref": "#/components/schemas/Message"}
35 }
36 },
37 },
38 "200": {
39 "description": "Item requested by ID",
40 "content": {
41 "application/json": {
42 "schema": {"$ref": "#/components/schemas/Item"},
43 "example": {
44 "id": "bar",
45 "value": "The bar tenders",
46 },
47 }
48 },
49 },
50 "422": {
51 "description": "Validation Error",
52 "content": {
53 "application/json": {
54 "schema": {
55 "$ref": "#/components/schemas/HTTPValidationError"
56 }
57 }
58 },
59 },
60 },
61 "summary": "Read Item",
62 "operationId": "read_item_items__item_id__get",
63 "parameters": [
64 {
65 "required": True,
66 "schema": {"title": "Item Id", "type": "string"},
67 "name": "item_id",
68 "in": "path",
69 }
70 ],
71 }
72 }
73 },
74 "components": {
75 "schemas": {
76 "Item": {
77 "title": "Item",
78 "required": ["id", "value"],
79 "type": "object",
80 "properties": {
81 "id": {"title": "Id", "type": "string"},
82 "value": {"title": "Value", "type": "string"},
83 },
84 },
85 "Message": {
86 "title": "Message",
87 "required": ["message"],
88 "type": "object",
89 "properties": {"message": {"title": "Message", "type": "string"}},
90 },
91 "ValidationError": {
92 "title": "ValidationError",
93 "required": ["loc", "msg", "type"],
94 "type": "object",
95 "properties": {
96 "loc": {
97 "title": "Location",
98 "type": "array",
99 "items": {
100 "anyOf": [{"type": "string"}, {"type": "integer"}]
101 },
102 },
103 "msg": {"title": "Message", "type": "string"},
104 "type": {"title": "Error Type", "type": "string"},
105 },
106 },
107 "HTTPValidationError": {
108 "title": "HTTPValidationError",
109 "type": "object",
110 "properties": {
111 "detail": {
112 "title": "Detail",
113 "type": "array",
114 "items": {"$ref": "#/components/schemas/ValidationError"},
115 }
116 },
117 },
118 }
119 },
120 }