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