Skip to content

Commit 87969ab

Browse files
committed
add e2e test for referenced request body
1 parent 966be98 commit 87969ab

File tree

3 files changed

+192
-30
lines changed

3 files changed

+192
-30
lines changed

end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
octet_stream_tests_octet_stream_get,
1717
post_form_data,
1818
post_form_data_inline,
19+
post_form_data_ref,
1920
post_tests_json_body_string,
2021
test_inline_objects,
2122
token_with_cookie_auth_token_with_cookie_get,
@@ -68,6 +69,13 @@ def post_form_data(cls) -> types.ModuleType:
6869
"""
6970
return post_form_data
7071

72+
@classmethod
73+
def post_form_data_ref(cls) -> types.ModuleType:
74+
"""
75+
Post form data (ref request body)
76+
"""
77+
return post_form_data_ref
78+
7179
@classmethod
7280
def post_form_data_inline(cls) -> types.ModuleType:
7381
"""
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from http import HTTPStatus
2+
from typing import Any, Dict
3+
4+
import httpx
5+
6+
from ...client import Client
7+
from ...models.a_form_data import AFormData
8+
from ...types import Response
9+
10+
11+
def _get_kwargs(
12+
*,
13+
client: Client,
14+
form_data: AFormData,
15+
) -> Dict[str, Any]:
16+
url = "{}/tests/post_form_data_ref_body".format(client.base_url)
17+
18+
headers: Dict[str, str] = client.get_headers()
19+
cookies: Dict[str, Any] = client.get_cookies()
20+
21+
return {
22+
"method": "post",
23+
"url": url,
24+
"headers": headers,
25+
"cookies": cookies,
26+
"timeout": client.get_timeout(),
27+
"data": form_data.to_dict(),
28+
}
29+
30+
31+
def _build_response(*, response: httpx.Response) -> Response[Any]:
32+
return Response(
33+
status_code=HTTPStatus(response.status_code),
34+
content=response.content,
35+
headers=response.headers,
36+
parsed=None,
37+
)
38+
39+
40+
def sync_detailed(
41+
*,
42+
client: Client,
43+
form_data: AFormData,
44+
) -> Response[Any]:
45+
"""Post form data (ref request body)
46+
47+
Post form data (ref request body)
48+
49+
Returns:
50+
Response[Any]
51+
"""
52+
53+
kwargs = _get_kwargs(
54+
client=client,
55+
form_data=form_data,
56+
)
57+
58+
response = httpx.request(
59+
verify=client.verify_ssl,
60+
**kwargs,
61+
)
62+
63+
return _build_response(response=response)
64+
65+
66+
async def asyncio_detailed(
67+
*,
68+
client: Client,
69+
form_data: AFormData,
70+
) -> Response[Any]:
71+
"""Post form data (ref request body)
72+
73+
Post form data (ref request body)
74+
75+
Returns:
76+
Response[Any]
77+
"""
78+
79+
kwargs = _get_kwargs(
80+
client=client,
81+
form_data=form_data,
82+
)
83+
84+
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
85+
response = await _client.request(**kwargs)
86+
87+
return _build_response(response=response)

end_to_end_tests/openapi.json

Lines changed: 97 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,29 @@
242242
}
243243
}
244244
},
245+
"/tests/post_form_data_ref_body": {
246+
"post": {
247+
"tags": [
248+
"tests"
249+
],
250+
"summary": "Post form data (ref request body)",
251+
"description": "Post form data (ref request body)",
252+
"operationId": "post_form_data_ref",
253+
"requestBody": {
254+
"$ref": "#/components/requestBodies/AFormBody"
255+
},
256+
"responses": {
257+
"200": {
258+
"description": "Successful Response",
259+
"content": {
260+
"application/json": {
261+
"schema": {}
262+
}
263+
}
264+
}
265+
}
266+
}
267+
},
245268
"/tests/post_form_data_inline": {
246269
"post": {
247270
"tags": [
@@ -756,7 +779,9 @@
756779
},
757780
"/responses/unions/simple_before_complex": {
758781
"post": {
759-
"tags": ["responses"],
782+
"tags": [
783+
"responses"
784+
],
760785
"description": "Regression test for #603",
761786
"responses": {
762787
"200": {
@@ -765,12 +790,18 @@
765790
"application/json": {
766791
"schema": {
767792
"type": "object",
768-
"required": ["a"],
793+
"required": [
794+
"a"
795+
],
769796
"properties": {
770797
"a": {
771798
"oneOf": [
772-
{"type": "string"},
773-
{"type": "object"}
799+
{
800+
"type": "string"
801+
},
802+
{
803+
"type": "object"
804+
}
774805
]
775806
}
776807
}
@@ -877,20 +908,20 @@
877908
},
878909
"parameters": [
879910
{
880-
"name": "param",
881-
"in": "query",
882-
"schema": {
883-
"type": "string"
884-
}
885-
},
886-
{
887-
"name": "param",
888-
"in": "path",
889-
"required": true,
890-
"schema": {
891-
"type": "string"
892-
}
911+
"name": "param",
912+
"in": "query",
913+
"schema": {
914+
"type": "string"
915+
}
916+
},
917+
{
918+
"name": "param",
919+
"in": "path",
920+
"required": true,
921+
"schema": {
922+
"type": "string"
893923
}
924+
}
894925
]
895926
},
896927
"/same-name-multiple-locations/{param}": {
@@ -939,7 +970,9 @@
939970
},
940971
"/tag_with_number": {
941972
"get": {
942-
"tags": ["1"],
973+
"tags": [
974+
"1"
975+
],
943976
"responses": {
944977
"200": {
945978
"description": "Success"
@@ -1163,9 +1196,15 @@
11631196
{
11641197
"$ref": "#/components/parameters/integer-param"
11651198
},
1166-
{"$ref": "#/components/parameters/header-param"},
1167-
{"$ref": "#/components/parameters/cookie-param"},
1168-
{"$ref": "#/components/parameters/path-param"}
1199+
{
1200+
"$ref": "#/components/parameters/header-param"
1201+
},
1202+
{
1203+
"$ref": "#/components/parameters/cookie-param"
1204+
},
1205+
{
1206+
"$ref": "#/components/parameters/path-param"
1207+
}
11691208
],
11701209
"responses": {
11711210
"200": {
@@ -1477,7 +1516,11 @@
14771516
},
14781517
"Body_upload_file_tests_upload_post": {
14791518
"title": "Body_upload_file_tests_upload_post",
1480-
"required": ["some_file", "some_object", "some_nullable_object"],
1519+
"required": [
1520+
"some_file",
1521+
"some_object",
1522+
"some_nullable_object"
1523+
],
14811524
"type": "object",
14821525
"properties": {
14831526
"some_file": {
@@ -1519,7 +1562,10 @@
15191562
"some_object": {
15201563
"title": "Some Object",
15211564
"type": "object",
1522-
"required": ["num", "text"],
1565+
"required": [
1566+
"num",
1567+
"text"
1568+
],
15231569
"properties": {
15241570
"num": {
15251571
"type": "number"
@@ -1532,7 +1578,9 @@
15321578
"some_optional_object": {
15331579
"title": "Some Optional Object",
15341580
"type": "object",
1535-
"required": ["foo"],
1581+
"required": [
1582+
"foo"
1583+
],
15361584
"properties": {
15371585
"foo": {
15381586
"type": "string"
@@ -1755,7 +1803,10 @@
17551803
},
17561804
"type_enum": {
17571805
"type": "integer",
1758-
"enum": [0, 1]
1806+
"enum": [
1807+
0,
1808+
1
1809+
]
17591810
}
17601811
}
17611812
},
@@ -1768,11 +1819,15 @@
17681819
},
17691820
"type": {
17701821
"type": "string",
1771-
"enum": ["submodel"]
1822+
"enum": [
1823+
"submodel"
1824+
]
17721825
},
17731826
"type_enum": {
17741827
"type": "integer",
1775-
"enum": [0]
1828+
"enum": [
1829+
0
1830+
]
17761831
}
17771832
}
17781833
},
@@ -1915,7 +1970,7 @@
19151970
}
19161971
}
19171972
},
1918-
"ModelWithDateTimeProperty" : {
1973+
"ModelWithDateTimeProperty": {
19191974
"type": "object",
19201975
"properties": {
19211976
"datetime": {
@@ -2093,10 +2148,10 @@
20932148
"type": "string",
20942149
"format": "byte"
20952150
},
2096-
"import": {
2151+
"import": {
20972152
"type": "object"
20982153
},
2099-
"None": {
2154+
"None": {
21002155
"type": "object"
21012156
},
21022157
"model.reference.with.Periods": {
@@ -2167,6 +2222,18 @@
21672222
"type": "string"
21682223
}
21692224
}
2225+
},
2226+
"requestBodies": {
2227+
"AFormBody": {
2228+
"required": true,
2229+
"content": {
2230+
"application/x-www-form-urlencoded": {
2231+
"schema": {
2232+
"$ref": "#/components/schemas/AFormData"
2233+
}
2234+
}
2235+
}
2236+
}
21702237
}
21712238
}
21722239
}

0 commit comments

Comments
 (0)