Skip to content

Commit e74ca6d

Browse files
committed
test: added non standard exit code e2e test
1 parent d401b51 commit e74ca6d

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

end_to_end_tests/baseline_openapi_3.0.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,27 @@
17361736
}
17371737
}
17381738
},
1739+
"/tests/nonstandard-response-code": {
1740+
"get": {
1741+
"tags": [
1742+
"tests"
1743+
],
1744+
"summary": "Test nonstandard response code",
1745+
"description": "Test endpoint with nonstandard response code",
1746+
"operationId": "nonstandard_response_code",
1747+
"responses": {
1748+
"200": {
1749+
"description": "Successful response"
1750+
},
1751+
"499": {
1752+
"description": "Nonstandard response code"
1753+
},
1754+
"99999": {
1755+
"description": "Nonstandard response code"
1756+
}
1757+
}
1758+
}
1759+
},
17391760
"/config/content-type-override": {
17401761
"post": {
17411762
"tags": [

end_to_end_tests/baseline_openapi_3.1.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,27 @@ info:
17061706
}
17071707
}
17081708
},
1709+
"/tests/nonstandard-response-code": {
1710+
"get": {
1711+
"tags": [
1712+
"tests"
1713+
],
1714+
"summary": "Test nonstandard response code",
1715+
"description": "Test endpoint with nonstandard response code",
1716+
"operationId": "nonstandard_response_code",
1717+
"responses": {
1718+
"200": {
1719+
"description": "Successful response"
1720+
},
1721+
"499": {
1722+
"description": "Nonstandard response code"
1723+
},
1724+
"99999": {
1725+
"description": "Nonstandard response code"
1726+
}
1727+
}
1728+
}
1729+
},
17091730
"/config/content-type-override": {
17101731
"post": {
17111732
"tags": [

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
@@ -12,6 +12,7 @@
1212
get_user_list,
1313
json_body_tests_json_body_post,
1414
no_response_tests_no_response_get,
15+
nonstandard_response_code,
1516
octet_stream_tests_octet_stream_get,
1617
octet_stream_tests_octet_stream_post,
1718
post_form_data,
@@ -150,3 +151,10 @@ def description_with_backslash(cls) -> types.ModuleType:
150151
Test description with \
151152
"""
152153
return description_with_backslash
154+
155+
@classmethod
156+
def nonstandard_response_code(cls) -> types.ModuleType:
157+
"""
158+
Test endpoint with nonstandard response code
159+
"""
160+
return nonstandard_response_code
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from typing import Any
2+
3+
import httpx
4+
5+
from ... import errors
6+
from ...client import AuthenticatedClient, Client
7+
from ...types import Response
8+
9+
HTTPStatus = int
10+
11+
12+
def _get_kwargs() -> dict[str, Any]:
13+
_kwargs: dict[str, Any] = {
14+
"method": "get",
15+
"url": "/tests/nonstandard-response-code",
16+
}
17+
18+
return _kwargs
19+
20+
21+
def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None:
22+
if response.status_code == 200:
23+
return None
24+
25+
if response.status_code == 499:
26+
return None
27+
28+
if response.status_code == 99999:
29+
return None
30+
31+
if client.raise_on_unexpected_status:
32+
raise errors.UnexpectedStatus(response.status_code, response.content)
33+
else:
34+
return None
35+
36+
37+
def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any, HTTPStatus]:
38+
return Response(
39+
status_code=HTTPStatus(response.status_code),
40+
content=response.content,
41+
headers=response.headers,
42+
parsed=_parse_response(client=client, response=response),
43+
)
44+
45+
46+
def sync_detailed(
47+
*,
48+
client: AuthenticatedClient | Client,
49+
) -> Response[Any, HTTPStatus]:
50+
"""Test nonstandard response code
51+
52+
Test endpoint with nonstandard response code
53+
54+
Raises:
55+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
56+
httpx.TimeoutException: If the request takes longer than Client.timeout.
57+
58+
Returns:
59+
Response[Any]
60+
"""
61+
62+
kwargs = _get_kwargs()
63+
64+
response = client.get_httpx_client().request(
65+
**kwargs,
66+
)
67+
68+
return _build_response(client=client, response=response)
69+
70+
71+
async def asyncio_detailed(
72+
*,
73+
client: AuthenticatedClient | Client,
74+
) -> Response[Any, HTTPStatus]:
75+
"""Test nonstandard response code
76+
77+
Test endpoint with nonstandard response code
78+
79+
Raises:
80+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
81+
httpx.TimeoutException: If the request takes longer than Client.timeout.
82+
83+
Returns:
84+
Response[Any]
85+
"""
86+
87+
kwargs = _get_kwargs()
88+
89+
response = await client.get_async_httpx_client().request(**kwargs)
90+
91+
return _build_response(client=client, response=response)

0 commit comments

Comments
 (0)