Coverage for tests/test_modules_same_name_body/test_main.py: 100%
25 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 .app.main import app 1abcde
5client = TestClient(app) 1abcde
8def test_post_a(): 1abcde
9 data = {"a": 2, "b": "foo"} 1abcde
10 response = client.post("/a/compute", json=data) 1abcde
11 assert response.status_code == 200, response.text 1abcde
12 data = response.json() 1abcde
15def test_post_a_invalid(): 1abcde
16 data = {"a": "bar", "b": "foo"} 1abcde
17 response = client.post("/a/compute", json=data) 1abcde
18 assert response.status_code == 422, response.text 1abcde
21def test_post_b(): 1abcde
22 data = {"a": 2, "b": "foo"} 1abcde
23 response = client.post("/b/compute/", json=data) 1abcde
24 assert response.status_code == 200, response.text 1abcde
25 data = response.json() 1abcde
28def test_post_b_invalid(): 1abcde
29 data = {"a": "bar", "b": "foo"} 1abcde
30 response = client.post("/b/compute/", json=data) 1abcde
31 assert response.status_code == 422, response.text 1abcde
34def test_openapi_schema(): 1abcde
35 response = client.get("/openapi.json") 1abcde
36 assert response.status_code == 200, response.text 1abcde
37 assert response.json() == { 1abcde
38 "openapi": "3.1.0",
39 "info": {"title": "FastAPI", "version": "0.1.0"},
40 "paths": {
41 "/a/compute": {
42 "post": {
43 "responses": {
44 "200": {
45 "description": "Successful Response",
46 "content": {"application/json": {"schema": {}}},
47 },
48 "422": {
49 "description": "Validation Error",
50 "content": {
51 "application/json": {
52 "schema": {
53 "$ref": "#/components/schemas/HTTPValidationError"
54 }
55 }
56 },
57 },
58 },
59 "summary": "Compute",
60 "operationId": "compute_a_compute_post",
61 "requestBody": {
62 "content": {
63 "application/json": {
64 "schema": {
65 "$ref": "#/components/schemas/Body_compute_a_compute_post"
66 }
67 }
68 },
69 "required": True,
70 },
71 }
72 },
73 "/b/compute/": {
74 "post": {
75 "responses": {
76 "200": {
77 "description": "Successful Response",
78 "content": {"application/json": {"schema": {}}},
79 },
80 "422": {
81 "description": "Validation Error",
82 "content": {
83 "application/json": {
84 "schema": {
85 "$ref": "#/components/schemas/HTTPValidationError"
86 }
87 }
88 },
89 },
90 },
91 "summary": "Compute",
92 "operationId": "compute_b_compute__post",
93 "requestBody": {
94 "content": {
95 "application/json": {
96 "schema": {
97 "$ref": "#/components/schemas/Body_compute_b_compute__post"
98 }
99 }
100 },
101 "required": True,
102 },
103 }
104 },
105 },
106 "components": {
107 "schemas": {
108 "Body_compute_b_compute__post": {
109 "title": "Body_compute_b_compute__post",
110 "required": ["a", "b"],
111 "type": "object",
112 "properties": {
113 "a": {"title": "A", "type": "integer"},
114 "b": {"title": "B", "type": "string"},
115 },
116 },
117 "Body_compute_a_compute_post": {
118 "title": "Body_compute_a_compute_post",
119 "required": ["a", "b"],
120 "type": "object",
121 "properties": {
122 "a": {"title": "A", "type": "integer"},
123 "b": {"title": "B", "type": "string"},
124 },
125 },
126 "ValidationError": {
127 "title": "ValidationError",
128 "required": ["loc", "msg", "type"],
129 "type": "object",
130 "properties": {
131 "loc": {
132 "title": "Location",
133 "type": "array",
134 "items": {
135 "anyOf": [{"type": "string"}, {"type": "integer"}]
136 },
137 },
138 "msg": {"title": "Message", "type": "string"},
139 "type": {"title": "Error Type", "type": "string"},
140 },
141 },
142 "HTTPValidationError": {
143 "title": "HTTPValidationError",
144 "type": "object",
145 "properties": {
146 "detail": {
147 "title": "Detail",
148 "type": "array",
149 "items": {"$ref": "#/components/schemas/ValidationError"},
150 }
151 },
152 },
153 }
154 },
155 }