Skip to content

Commit b27aa1f

Browse files
committed
Add e2e test for callback parsing
1 parent 1b34880 commit b27aa1f

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
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
@@ -3,6 +3,7 @@
33
import types
44

55
from . import (
6+
callback_test,
67
defaults_tests_defaults_post,
78
get_basic_list_of_booleans,
89
get_basic_list_of_floats,
@@ -150,3 +151,10 @@ def token_with_cookie_auth_token_with_cookie_get(cls) -> types.ModuleType:
150151
Test optional cookie parameters
151152
"""
152153
return token_with_cookie_auth_token_with_cookie_get
154+
155+
@classmethod
156+
def callback_test(cls) -> types.ModuleType:
157+
"""
158+
Try sending a request related to a callback
159+
"""
160+
return callback_test
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
from typing import Any, Dict, Optional, Union, cast
2+
3+
import httpx
4+
5+
from ...client import Client
6+
from ...models.a_model import AModel
7+
from ...models.http_validation_error import HTTPValidationError
8+
from ...types import Response
9+
10+
11+
def _get_kwargs(
12+
*,
13+
client: Client,
14+
json_body: AModel,
15+
) -> Dict[str, Any]:
16+
url = "{}/tests/callback".format(client.base_url)
17+
18+
headers: Dict[str, str] = client.get_headers()
19+
cookies: Dict[str, Any] = client.get_cookies()
20+
21+
json_json_body = json_body.to_dict()
22+
23+
return {
24+
"method": "post",
25+
"url": url,
26+
"headers": headers,
27+
"cookies": cookies,
28+
"timeout": client.get_timeout(),
29+
"json": json_json_body,
30+
}
31+
32+
33+
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
34+
if response.status_code == 200:
35+
response_200 = cast(Any, response.json())
36+
return response_200
37+
if response.status_code == 422:
38+
response_422 = HTTPValidationError.from_dict(response.json())
39+
40+
return response_422
41+
return None
42+
43+
44+
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
45+
return Response(
46+
status_code=response.status_code,
47+
content=response.content,
48+
headers=response.headers,
49+
parsed=_parse_response(response=response),
50+
)
51+
52+
53+
def sync_detailed(
54+
*,
55+
client: Client,
56+
json_body: AModel,
57+
) -> Response[Union[Any, HTTPValidationError]]:
58+
"""Path with callback
59+
60+
Try sending a request related to a callback
61+
62+
Args:
63+
json_body (AModel): A Model for testing all the ways custom objects can be used
64+
65+
Returns:
66+
Response[Union[Any, HTTPValidationError]]
67+
"""
68+
69+
kwargs = _get_kwargs(
70+
client=client,
71+
json_body=json_body,
72+
)
73+
74+
response = httpx.request(
75+
verify=client.verify_ssl,
76+
**kwargs,
77+
)
78+
79+
return _build_response(response=response)
80+
81+
82+
def sync(
83+
*,
84+
client: Client,
85+
json_body: AModel,
86+
) -> Optional[Union[Any, HTTPValidationError]]:
87+
"""Path with callback
88+
89+
Try sending a request related to a callback
90+
91+
Args:
92+
json_body (AModel): A Model for testing all the ways custom objects can be used
93+
94+
Returns:
95+
Response[Union[Any, HTTPValidationError]]
96+
"""
97+
98+
return sync_detailed(
99+
client=client,
100+
json_body=json_body,
101+
).parsed
102+
103+
104+
async def asyncio_detailed(
105+
*,
106+
client: Client,
107+
json_body: AModel,
108+
) -> Response[Union[Any, HTTPValidationError]]:
109+
"""Path with callback
110+
111+
Try sending a request related to a callback
112+
113+
Args:
114+
json_body (AModel): A Model for testing all the ways custom objects can be used
115+
116+
Returns:
117+
Response[Union[Any, HTTPValidationError]]
118+
"""
119+
120+
kwargs = _get_kwargs(
121+
client=client,
122+
json_body=json_body,
123+
)
124+
125+
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
126+
response = await _client.request(**kwargs)
127+
128+
return _build_response(response=response)
129+
130+
131+
async def asyncio(
132+
*,
133+
client: Client,
134+
json_body: AModel,
135+
) -> Optional[Union[Any, HTTPValidationError]]:
136+
"""Path with callback
137+
138+
Try sending a request related to a callback
139+
140+
Args:
141+
json_body (AModel): A Model for testing all the ways custom objects can be used
142+
143+
Returns:
144+
Response[Union[Any, HTTPValidationError]]
145+
"""
146+
147+
return (
148+
await asyncio_detailed(
149+
client=client,
150+
json_body=json_body,
151+
)
152+
).parsed

end_to_end_tests/openapi.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,62 @@
11731173
}
11741174
}
11751175
}
1176+
},
1177+
"/tests/callback": {
1178+
"post": {
1179+
"tags": [
1180+
"tests"
1181+
],
1182+
"summary": "Path with callback",
1183+
"description": "Try sending a request related to a callback",
1184+
"operationId": "callback_test",
1185+
"requestBody": {
1186+
"content": {
1187+
"application/json": {
1188+
"schema": {
1189+
"$ref": "#/components/schemas/AModel"
1190+
}
1191+
}
1192+
},
1193+
"required": true
1194+
},
1195+
"responses": {
1196+
"200": {
1197+
"description": "Successful Response",
1198+
"content": {
1199+
"application/json": {
1200+
"schema": {}
1201+
}
1202+
}
1203+
},
1204+
"422": {
1205+
"description": "Validation Error",
1206+
"content": {
1207+
"application/json": {
1208+
"schema": {
1209+
"$ref": "#/components/schemas/HTTPValidationError"
1210+
}
1211+
}
1212+
}
1213+
}
1214+
},
1215+
"callbacks": {
1216+
"event": {
1217+
"callback": {
1218+
"post": {
1219+
"responses": {
1220+
"200": {
1221+
"description": "Success"
1222+
},
1223+
"503": {
1224+
"description": "Unavailable"
1225+
}
1226+
}
1227+
}
1228+
}
1229+
}
1230+
}
1231+
}
11761232
}
11771233
},
11781234
"components": {

0 commit comments

Comments
 (0)