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