/
optional_value_tests_optional_query_param.py
116 lines (88 loc) · 2.79 KB
/
optional_value_tests_optional_query_param.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from typing import Any, Dict, List, Optional, Union
import httpx
from ...client import Client
from ...models.http_validation_error import HTTPValidationError
from ...types import UNSET, Response, Unset
def _get_kwargs(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Dict[str, Any]:
url = "{}/tests/optional_query_param/".format(client.base_url)
headers: Dict[str, Any] = client.get_headers()
json_query_param: Union[Unset, List[Any]] = UNSET
if not isinstance(query_param, Unset):
json_query_param = query_param
params: Dict[str, Any] = {
"query_param": json_query_param,
}
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
return {
"url": url,
"headers": headers,
"cookies": client.get_cookies(),
"timeout": client.get_timeout(),
"params": params,
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
if response.status_code == 200:
response_200 = None
return response_200
if response.status_code == 422:
response_422 = HTTPValidationError.from_dict(response.json())
return response_422
return None
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Response[Union[None, HTTPValidationError]]:
kwargs = _get_kwargs(
client=client,
query_param=query_param,
)
response = httpx.get(
**kwargs,
)
return _build_response(response=response)
def sync(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Optional[Union[None, HTTPValidationError]]:
""" Test optional query parameters """
return sync_detailed(
client=client,
query_param=query_param,
).parsed
async def asyncio_detailed(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Response[Union[None, HTTPValidationError]]:
kwargs = _get_kwargs(
client=client,
query_param=query_param,
)
async with httpx.AsyncClient() as _client:
response = await _client.get(**kwargs)
return _build_response(response=response)
async def asyncio(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Optional[Union[None, HTTPValidationError]]:
""" Test optional query parameters """
return (
await asyncio_detailed(
client=client,
query_param=query_param,
)
).parsed