Skip to content

Commit c11de57

Browse files
Fix some tests
1 parent e906b1a commit c11de57

14 files changed

+104
-82
lines changed

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/defaults_tests_defaults_post.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ def httpx_request(
5555
enum_prop: Union[Unset, None, AnEnum] = UNSET,
5656
) -> Response[Union[None, HTTPValidationError]]:
5757

58-
json_not_required_not_nullable_datetime_prop: Union[Unset, str] = UNSET
59-
if (
60-
not isinstance(not_required_not_nullable_datetime_prop, Unset)
61-
and not_required_not_nullable_datetime_prop is not None
62-
):
63-
json_not_required_not_nullable_datetime_prop = not_required_not_nullable_datetime_prop.isoformat()
64-
65-
json_not_required_nullable_datetime_prop: Union[Unset, str] = UNSET
66-
if not isinstance(not_required_nullable_datetime_prop, Unset) and not_required_nullable_datetime_prop is not None:
58+
json_not_required_not_nullable_datetime_prop: Union[Unset, None, str] = UNSET
59+
if not isinstance(not_required_not_nullable_datetime_prop, Unset):
60+
json_not_required_not_nullable_datetime_prop = (
61+
not_required_not_nullable_datetime_prop.isoformat() if not_required_not_nullable_datetime_prop else None
62+
)
63+
64+
json_not_required_nullable_datetime_prop: Union[Unset, None, str] = UNSET
65+
if not isinstance(not_required_nullable_datetime_prop, Unset):
6766
json_not_required_nullable_datetime_prop = (
6867
not_required_nullable_datetime_prop.isoformat() if not_required_nullable_datetime_prop else None
6968
)
@@ -74,27 +73,34 @@ def httpx_request(
7473
required_nullable_datetime_prop.isoformat() if required_nullable_datetime_prop else None
7574
)
7675

77-
json_date_prop: Union[Unset, str] = UNSET
78-
if not isinstance(date_prop, Unset) and date_prop is not None:
79-
json_date_prop = date_prop.isoformat()
76+
json_date_prop: Union[Unset, None, str] = UNSET
77+
if not isinstance(date_prop, Unset):
78+
json_date_prop = date_prop.isoformat() if date_prop else None
8079

81-
json_list_prop: Union[Unset, List[Any]] = UNSET
82-
if not isinstance(list_prop, Unset) and list_prop is not None:
83-
json_list_prop = []
84-
for list_prop_item_data in list_prop:
85-
list_prop_item = list_prop_item_data.value
80+
json_list_prop: Union[Unset, None, List[Any]] = UNSET
81+
if not isinstance(list_prop, Unset):
82+
if list_prop is None:
83+
json_list_prop = None
84+
else:
85+
json_list_prop = []
86+
for list_prop_item_data in list_prop:
87+
list_prop_item = list_prop_item_data.value
8688

87-
json_list_prop.append(list_prop_item)
89+
json_list_prop.append(list_prop_item)
8890

89-
json_union_prop: Union[Unset, float, str]
90-
if isinstance(union_prop, Unset) or union_prop is None:
91+
json_union_prop: Union[Unset, None, float, str]
92+
if isinstance(union_prop, Unset):
9193
json_union_prop = UNSET
94+
elif union_prop is None:
95+
json_union_prop: Union[Unset, None, float, str] = None
9296
else:
9397
json_union_prop = union_prop
9498

95-
json_union_prop_with_ref: Union[Unset, float, AnEnum]
96-
if isinstance(union_prop_with_ref, Unset) or union_prop_with_ref is None:
99+
json_union_prop_with_ref: Union[Unset, None, float, AnEnum]
100+
if isinstance(union_prop_with_ref, Unset):
97101
json_union_prop_with_ref = UNSET
102+
elif union_prop_with_ref is None:
103+
json_union_prop_with_ref: Union[Unset, None, float, AnEnum] = None
98104
elif isinstance(union_prop_with_ref, AnEnum):
99105
json_union_prop_with_ref = UNSET
100106
if not isinstance(union_prop_with_ref, Unset):
@@ -103,9 +109,9 @@ def httpx_request(
103109
else:
104110
json_union_prop_with_ref = union_prop_with_ref
105111

106-
json_enum_prop: Union[Unset, AnEnum] = UNSET
107-
if not isinstance(enum_prop, Unset) and enum_prop is not None:
108-
json_enum_prop = enum_prop
112+
json_enum_prop: Union[Unset, None, AnEnum] = UNSET
113+
if not isinstance(enum_prop, Unset):
114+
json_enum_prop = enum_prop if enum_prop else None
109115

110116
params: Dict[str, Any] = {
111117
"required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop,
@@ -116,7 +122,7 @@ def httpx_request(
116122
params["not_required_not_nullable_datetime_prop"] = json_not_required_not_nullable_datetime_prop
117123
if not_required_nullable_datetime_prop is not UNSET and not_required_nullable_datetime_prop is not None:
118124
params["not_required_nullable_datetime_prop"] = json_not_required_nullable_datetime_prop
119-
if required_nullable_datetime_prop is not UNSET and required_nullable_datetime_prop is not None:
125+
if required_nullable_datetime_prop is not None:
120126
params["required_nullable_datetime_prop"] = json_required_nullable_datetime_prop
121127
if date_prop is not UNSET and date_prop is not None:
122128
params["date_prop"] = json_date_prop

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/get_user_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def httpx_request(
5353

5454
json_an_enum_value.append(an_enum_value_item)
5555

56+
if some_date is None:
57+
json_some_date: Union[datetime.date, datetime.datetime] = None
5658
if isinstance(some_date, datetime.date):
5759
json_some_date = some_date.isoformat()
5860
else:

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/optional_value_tests_optional_query_param.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ def httpx_request(
3939
query_param: Union[Unset, None, List[str]] = UNSET,
4040
) -> Response[Union[None, HTTPValidationError]]:
4141

42-
json_query_param: Union[Unset, List[Any]] = UNSET
43-
if not isinstance(query_param, Unset) and query_param is not None:
44-
json_query_param = query_param
42+
json_query_param: Union[Unset, None, List[Any]] = UNSET
43+
if not isinstance(query_param, Unset):
44+
if query_param is None:
45+
json_query_param = None
46+
else:
47+
json_query_param = query_param
4548

4649
params: Dict[str, Any] = {}
4750
if query_param is not UNSET and query_param is not None:

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ def _get_kwargs(
3131

3232
headers: Dict[str, Any] = client.get_headers()
3333

34-
json_not_required_not_nullable_datetime_prop: Union[Unset, str] = UNSET
35-
if (
36-
not isinstance(not_required_not_nullable_datetime_prop, Unset)
37-
and not_required_not_nullable_datetime_prop is not None
38-
):
39-
json_not_required_not_nullable_datetime_prop = not_required_not_nullable_datetime_prop.isoformat()
40-
41-
json_not_required_nullable_datetime_prop: Union[Unset, str] = UNSET
42-
if not isinstance(not_required_nullable_datetime_prop, Unset) and not_required_nullable_datetime_prop is not None:
34+
json_not_required_not_nullable_datetime_prop: Union[Unset, None, str] = UNSET
35+
if not isinstance(not_required_not_nullable_datetime_prop, Unset):
36+
json_not_required_not_nullable_datetime_prop = (
37+
not_required_not_nullable_datetime_prop.isoformat() if not_required_not_nullable_datetime_prop else None
38+
)
39+
40+
json_not_required_nullable_datetime_prop: Union[Unset, None, str] = UNSET
41+
if not isinstance(not_required_nullable_datetime_prop, Unset):
4342
json_not_required_nullable_datetime_prop = (
4443
not_required_nullable_datetime_prop.isoformat() if not_required_nullable_datetime_prop else None
4544
)
@@ -50,27 +49,34 @@ def _get_kwargs(
5049
required_nullable_datetime_prop.isoformat() if required_nullable_datetime_prop else None
5150
)
5251

53-
json_date_prop: Union[Unset, str] = UNSET
54-
if not isinstance(date_prop, Unset) and date_prop is not None:
55-
json_date_prop = date_prop.isoformat()
52+
json_date_prop: Union[Unset, None, str] = UNSET
53+
if not isinstance(date_prop, Unset):
54+
json_date_prop = date_prop.isoformat() if date_prop else None
5655

57-
json_list_prop: Union[Unset, List[Any]] = UNSET
58-
if not isinstance(list_prop, Unset) and list_prop is not None:
59-
json_list_prop = []
60-
for list_prop_item_data in list_prop:
61-
list_prop_item = list_prop_item_data.value
56+
json_list_prop: Union[Unset, None, List[Any]] = UNSET
57+
if not isinstance(list_prop, Unset):
58+
if list_prop is None:
59+
json_list_prop = None
60+
else:
61+
json_list_prop = []
62+
for list_prop_item_data in list_prop:
63+
list_prop_item = list_prop_item_data.value
6264

63-
json_list_prop.append(list_prop_item)
65+
json_list_prop.append(list_prop_item)
6466

65-
json_union_prop: Union[Unset, float, str]
66-
if isinstance(union_prop, Unset) or union_prop is None:
67+
json_union_prop: Union[Unset, None, float, str]
68+
if isinstance(union_prop, Unset):
6769
json_union_prop = UNSET
70+
elif union_prop is None:
71+
json_union_prop: Union[Unset, None, float, str] = None
6872
else:
6973
json_union_prop = union_prop
7074

71-
json_union_prop_with_ref: Union[Unset, float, AnEnum]
72-
if isinstance(union_prop_with_ref, Unset) or union_prop_with_ref is None:
75+
json_union_prop_with_ref: Union[Unset, None, float, AnEnum]
76+
if isinstance(union_prop_with_ref, Unset):
7377
json_union_prop_with_ref = UNSET
78+
elif union_prop_with_ref is None:
79+
json_union_prop_with_ref: Union[Unset, None, float, AnEnum] = None
7480
elif isinstance(union_prop_with_ref, AnEnum):
7581
json_union_prop_with_ref = UNSET
7682
if not isinstance(union_prop_with_ref, Unset):
@@ -79,9 +85,9 @@ def _get_kwargs(
7985
else:
8086
json_union_prop_with_ref = union_prop_with_ref
8187

82-
json_enum_prop: Union[Unset, AnEnum] = UNSET
83-
if not isinstance(enum_prop, Unset) and enum_prop is not None:
84-
json_enum_prop = enum_prop
88+
json_enum_prop: Union[Unset, None, AnEnum] = UNSET
89+
if not isinstance(enum_prop, Unset):
90+
json_enum_prop = enum_prop if enum_prop else None
8591

8692
params: Dict[str, Any] = {
8793
"required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop,
@@ -92,7 +98,7 @@ def _get_kwargs(
9298
params["not_required_not_nullable_datetime_prop"] = json_not_required_not_nullable_datetime_prop
9399
if not_required_nullable_datetime_prop is not UNSET and not_required_nullable_datetime_prop is not None:
94100
params["not_required_nullable_datetime_prop"] = json_not_required_nullable_datetime_prop
95-
if required_nullable_datetime_prop is not UNSET and required_nullable_datetime_prop is not None:
101+
if required_nullable_datetime_prop is not None:
96102
params["required_nullable_datetime_prop"] = json_required_nullable_datetime_prop
97103
if date_prop is not UNSET and date_prop is not None:
98104
params["date_prop"] = json_date_prop

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def _get_kwargs(
2626

2727
json_an_enum_value.append(an_enum_value_item)
2828

29+
if some_date is None:
30+
json_some_date: Union[datetime.date, datetime.datetime] = None
2931
if isinstance(some_date, datetime.date):
3032
json_some_date = some_date.isoformat()
3133
else:

end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ def _get_kwargs(
1616

1717
headers: Dict[str, Any] = client.get_headers()
1818

19-
json_query_param: Union[Unset, List[Any]] = UNSET
20-
if not isinstance(query_param, Unset) and query_param is not None:
21-
json_query_param = query_param
19+
json_query_param: Union[Unset, None, List[Any]] = UNSET
20+
if not isinstance(query_param, Unset):
21+
if query_param is None:
22+
json_query_param = None
23+
else:
24+
json_query_param = query_param
2225

2326
params: Dict[str, Any] = {}
2427
if query_param is not UNSET and query_param is not None:

openapi_python_client/templates/endpoint_macros.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ params: Dict[str, Any] = {
3333
}
3434
{% for property in endpoint.query_parameters %}
3535
{% if not property.required or property.nullable %}
36-
if {{ property.python_name }} is not UNSET and {{ property.python_name }} is not None:
36+
if {% if not property.required %}{{ property.python_name }} is not UNSET and {% endif %}{{ property.python_name }} is not None:
3737
{% if property.template %}
3838
params["{{ property.name }}"] = {{ "json_" + property.python_name }}
3939
{% else %}

openapi_python_client/templates/property_templates/date_property.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ if _{{ property.python_name }} is not None:
1313
{% if property.required %}
1414
{{ destination }} = {{ source }}.isoformat() {% if property.nullable %}if {{ source }} else None {%endif%}
1515
{% else %}
16-
{{ destination }}{% if declare_type %}: Union[Unset, str]{% endif %} = UNSET
17-
if not isinstance({{ source }}, Unset){%if query_parameter %} and {{ source }} is not None{% endif %}:
18-
{% if property.nullable %}
16+
{{ destination }}{% if declare_type %}: Union[Unset, {% if property.nullable or query_parameter %}None, {% endif %}str]{% endif %} = UNSET
17+
if not isinstance({{ source }}, Unset):
18+
{% if property.nullable or query_parameter %}
1919
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
2020
{% else %}
2121
{{ destination }} = {{ source }}.isoformat()

openapi_python_client/templates/property_templates/datetime_property.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ if _{{ property.python_name }} is not None:
2222
{{ destination }} = {{ source }}.isoformat()
2323
{% endif %}
2424
{% else %}
25-
{{ destination }}{% if declare_type %}: Union[Unset, str]{% endif %} = UNSET
26-
if not isinstance({{ source }}, Unset){%if query_parameter %} and {{ source }} is not None{% endif %}:
27-
{% if property.nullable %}
25+
{{ destination }}{% if declare_type %}: Union[Unset, {% if property.nullable or query_parameter %}None, {% endif %}str]{% endif %} = UNSET
26+
if not isinstance({{ source }}, Unset):
27+
{% if property.nullable or query_parameter %}
2828
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
2929
{% else %}
3030
{{ destination }} = {{ source }}.isoformat()

openapi_python_client/templates/property_templates/enum_property.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ if _{{ property.python_name }} is not None:
1717
{{ destination }} = {{ source }}.value
1818
{% endif %}
1919
{% else %}
20-
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = UNSET
21-
if not isinstance({{ source }}, Unset){%if query_parameter %} and {{ source }} is not None{% endif %}:
22-
{% if property.nullable %}
20+
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter) }}{% endif %} = UNSET
21+
if not isinstance({{ source }}, Unset):
22+
{% if property.nullable or query_parameter %}
2323
{{ destination }} = {{ source }} if {{ source }} else None
2424
{% else %}
2525
{{ destination }} = {{ source }}

openapi_python_client/templates/property_templates/file_property.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
{{ destination }} = {{ source }}.to_tuple()
1313
{% endif %}
1414
{% else %}
15-
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = UNSET
16-
if not isinstance({{ source }}, Unset){%if query_parameter %} and {{ source }} is not None{% endif %}:
17-
{% if property.nullable %}
15+
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter) }}{% endif %} = UNSET
16+
if not isinstance({{ source }}, Unset):
17+
{% if property.nullable or query_parameter %}
1818
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
1919
{% else %}
2020
{{ destination }} = {{ source }}.to_tuple()

openapi_python_client/templates/property_templates/list_property.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ else:
4444
{{ _transform(property, source, destination) }}
4545
{% endif %}
4646
{% else %}
47-
{{ destination }}{% if declare_type %}: Union[Unset, List[Any]]{% endif %} = UNSET
48-
if not isinstance({{ source }}, Unset){%if query_parameter %} and {{ source }} is not None{% endif %}:
49-
{% if property.nullable %}
47+
{{ destination }}{% if declare_type %}: Union[Unset, {% if property.nullable or query_parameter %}None, {% endif %}List[Any]]{% endif %} = UNSET
48+
if not isinstance({{ source }}, Unset):
49+
{% if property.nullable or query_parameter %}
5050
if {{ source }} is None:
5151
{{ destination }} = None
5252
else:
53-
{{ _transform(property, source, destination) | indent(4)}}
53+
{{ _transform(property, source, destination) | indent(8)}}
5454
{% else %}
5555
{{ _transform(property, source, destination) | indent(4)}}
5656
{% endif %}

openapi_python_client/templates/property_templates/model_property.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ if _{{ property.python_name }} is not None and not isinstance(_{{ property.pytho
2323
{{ destination }} = {{ source }}.to_dict()
2424
{% endif %}
2525
{% else %}
26-
{{ destination }}{% if declare_type %}: Union[{% if property.nullable %}None, {% endif %}Unset, Dict[str, Any]]{% endif %} = UNSET
27-
if not isinstance({{ source }}, Unset){%if query_parameter %} and {{ source }} is not None{% endif %}:
28-
{% if property.nullable %}
26+
{{ destination }}{% if declare_type %}: Union[{% if property.nullable or query_parameter %}None, {% endif %}Unset, Dict[str, Any]]{% endif %} = UNSET
27+
if not isinstance({{ source }}, Unset):
28+
{% if property.nullable or query_parameter %}
2929
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
3030
{% else %}
3131
{{ destination }} = {{ source }}.to_dict()

openapi_python_client/templates/property_templates/union_property.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ def _parse_{{ property.python_name }}(data: Any) -> {{ property.get_type_string(
2626

2727
{% macro transform(property, source, destination, declare_type=True, query_parameter=False) %}
2828
{% if not property.required %}
29-
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %}
29+
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter) }}{% endif %}
3030

31-
if isinstance({{ source }}, Unset){%if query_parameter %} or {{ source }} is None{% endif %}:
31+
if isinstance({{ source }}, Unset):
3232
{{ destination }} = UNSET
3333
{% endif %}
34-
{% if property.nullable %}
34+
{% if property.nullable or query_parameter %}
3535
{% if property.required %}
3636
if {{ source }} is None:
3737
{% else %}{# There's an if UNSET statement before this #}
3838
elif {{ source }} is None:
3939
{% endif %}
40-
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = None
40+
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter) }}{% endif %} = None
4141
{% endif %}
4242
{% for inner_property in property.inner_properties_with_template() %}
4343
{% if loop.first and property.required and not property.nullable %}{# No if UNSET or if None statement before this #}

0 commit comments

Comments
 (0)