Coverage for tests/test_tutorial/test_schema_extra_example/test_tutorial001_pv1.py: 100%
17 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 1abcde
2from fastapi.testclient import TestClient 1abcde
4from ...utils import needs_pydanticv1 1abcde
7@pytest.fixture(name="client") 1abcde
8def get_client(): 1abcde
9 from docs_src.schema_extra_example.tutorial001_pv1 import app 1abcde
11 client = TestClient(app) 1abcde
12 return client 1abcde
15@needs_pydanticv1 1abcde
16def test_post_body_example(client: TestClient): 1abcde
17 response = client.put( 1abcde
18 "/items/5",
19 json={
20 "name": "Foo",
21 "description": "A very nice Item",
22 "price": 35.4,
23 "tax": 3.2,
24 },
25 )
26 assert response.status_code == 200 1abcde
29@needs_pydanticv1 1abcde
30def test_openapi_schema(client: TestClient): 1abcde
31 response = client.get("/openapi.json") 1abcde
32 assert response.status_code == 200, response.text 1abcde
33 # insert_assert(response.json())
34 assert response.json() == { 1abcde
35 "openapi": "3.1.0",
36 "info": {"title": "FastAPI", "version": "0.1.0"},
37 "paths": {
38 "/items/{item_id}": {
39 "put": {
40 "summary": "Update Item",
41 "operationId": "update_item_items__item_id__put",
42 "parameters": [
43 {
44 "required": True,
45 "schema": {"type": "integer", "title": "Item Id"},
46 "name": "item_id",
47 "in": "path",
48 }
49 ],
50 "requestBody": {
51 "content": {
52 "application/json": {
53 "schema": {"$ref": "#/components/schemas/Item"}
54 }
55 },
56 "required": True,
57 },
58 "responses": {
59 "200": {
60 "description": "Successful Response",
61 "content": {"application/json": {"schema": {}}},
62 },
63 "422": {
64 "description": "Validation Error",
65 "content": {
66 "application/json": {
67 "schema": {
68 "$ref": "#/components/schemas/HTTPValidationError"
69 }
70 }
71 },
72 },
73 },
74 }
75 }
76 },
77 "components": {
78 "schemas": {
79 "HTTPValidationError": {
80 "properties": {
81 "detail": {
82 "items": {"$ref": "#/components/schemas/ValidationError"},
83 "type": "array",
84 "title": "Detail",
85 }
86 },
87 "type": "object",
88 "title": "HTTPValidationError",
89 },
90 "Item": {
91 "properties": {
92 "name": {"type": "string", "title": "Name"},
93 "description": {"type": "string", "title": "Description"},
94 "price": {"type": "number", "title": "Price"},
95 "tax": {"type": "number", "title": "Tax"},
96 },
97 "type": "object",
98 "required": ["name", "price"],
99 "title": "Item",
100 "examples": [
101 {
102 "name": "Foo",
103 "description": "A very nice Item",
104 "price": 35.4,
105 "tax": 3.2,
106 }
107 ],
108 },
109 "ValidationError": {
110 "properties": {
111 "loc": {
112 "items": {
113 "anyOf": [{"type": "string"}, {"type": "integer"}]
114 },
115 "type": "array",
116 "title": "Location",
117 },
118 "msg": {"type": "string", "title": "Message"},
119 "type": {"type": "string", "title": "Error Type"},
120 },
121 "type": "object",
122 "required": ["loc", "msg", "type"],
123 "title": "ValidationError",
124 },
125 }
126 },
127 }