Skip to content

Commit f02e943

Browse files
Add tests for union
1 parent 67bce41 commit f02e943

File tree

3 files changed

+346
-1
lines changed

3 files changed

+346
-1
lines changed

end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from ..models.a_model_nullable_model import AModelNullableModel
1111
from ..models.an_enum import AnEnum
1212
from ..models.different_enum import DifferentEnum
13+
from ..models.free_form_model import FreeFormModel
14+
from ..models.model_with_union_property import ModelWithUnionProperty
1315
from ..types import UNSET, Unset
1416

1517

@@ -22,15 +24,19 @@ class AModel:
2224
a_date: datetime.date
2325
required_not_nullable: str
2426
model: AModelModel
27+
one_of_models: Union[FreeFormModel, ModelWithUnionProperty]
2528
a_nullable_date: Optional[datetime.date]
2629
required_nullable: Optional[str]
2730
nullable_model: Optional[AModelNullableModel]
31+
nullable_one_of_models: Union[None, FreeFormModel, ModelWithUnionProperty]
2832
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
2933
attr_1_leading_digit: Union[Unset, str] = UNSET
3034
not_required_nullable: Union[Unset, None, str] = UNSET
3135
not_required_not_nullable: Union[Unset, str] = UNSET
3236
not_required_model: Union[Unset, AModelNotRequiredModel] = UNSET
3337
not_required_nullable_model: Union[Unset, None, AModelNotRequiredNullableModel] = UNSET
38+
not_required_one_of_models: Union[Unset, FreeFormModel, ModelWithUnionProperty] = UNSET
39+
not_required_nullable_one_of_models: Union[Unset, None, FreeFormModel, ModelWithUnionProperty] = UNSET
3440

3541
def to_dict(self) -> Dict[str, Any]:
3642
an_enum_value = self.an_enum_value.value
@@ -45,6 +51,12 @@ def to_dict(self) -> Dict[str, Any]:
4551
required_not_nullable = self.required_not_nullable
4652
model = self.model.to_dict()
4753

54+
if isinstance(self.one_of_models, FreeFormModel):
55+
one_of_models = self.one_of_models.to_dict()
56+
57+
else:
58+
one_of_models = self.one_of_models.to_dict()
59+
4860
nested_list_of_enums: Union[Unset, List[Any]] = UNSET
4961
if not isinstance(self.nested_list_of_enums, Unset):
5062
nested_list_of_enums = []
@@ -74,6 +86,45 @@ def to_dict(self) -> Dict[str, Any]:
7486
self.not_required_nullable_model.to_dict() if self.not_required_nullable_model else None
7587
)
7688

89+
nullable_one_of_models: Union[None, Dict[str, Any]]
90+
if isinstance(self.nullable_one_of_models, Unset):
91+
nullable_one_of_models = UNSET
92+
if self.nullable_one_of_models is None:
93+
nullable_one_of_models = None
94+
elif isinstance(self.nullable_one_of_models, FreeFormModel):
95+
nullable_one_of_models = self.nullable_one_of_models.to_dict()
96+
97+
else:
98+
nullable_one_of_models = self.nullable_one_of_models.to_dict()
99+
100+
not_required_one_of_models: Union[Unset, Dict[str, Any]]
101+
if isinstance(self.not_required_one_of_models, Unset):
102+
not_required_one_of_models = UNSET
103+
elif isinstance(self.not_required_one_of_models, FreeFormModel):
104+
not_required_one_of_models = UNSET
105+
if not isinstance(self.not_required_one_of_models, Unset):
106+
not_required_one_of_models = self.not_required_one_of_models.to_dict()
107+
108+
else:
109+
not_required_one_of_models = UNSET
110+
if not isinstance(self.not_required_one_of_models, Unset):
111+
not_required_one_of_models = self.not_required_one_of_models.to_dict()
112+
113+
not_required_nullable_one_of_models: Union[Unset, None, Dict[str, Any]]
114+
if isinstance(self.not_required_nullable_one_of_models, Unset):
115+
not_required_nullable_one_of_models = UNSET
116+
elif self.not_required_nullable_one_of_models is None:
117+
not_required_nullable_one_of_models = None
118+
elif isinstance(self.not_required_nullable_one_of_models, FreeFormModel):
119+
not_required_nullable_one_of_models = UNSET
120+
if not isinstance(self.not_required_nullable_one_of_models, Unset):
121+
not_required_nullable_one_of_models = self.not_required_nullable_one_of_models.to_dict()
122+
123+
else:
124+
not_required_nullable_one_of_models = UNSET
125+
if not isinstance(self.not_required_nullable_one_of_models, Unset):
126+
not_required_nullable_one_of_models = self.not_required_nullable_one_of_models.to_dict()
127+
77128
field_dict: Dict[str, Any] = {}
78129
field_dict.update(
79130
{
@@ -82,9 +133,11 @@ def to_dict(self) -> Dict[str, Any]:
82133
"a_date": a_date,
83134
"required_not_nullable": required_not_nullable,
84135
"model": model,
136+
"one_of_models": one_of_models,
85137
"a_nullable_date": a_nullable_date,
86138
"required_nullable": required_nullable,
87139
"nullable_model": nullable_model,
140+
"nullable_one_of_models": nullable_one_of_models,
88141
}
89142
)
90143
if nested_list_of_enums is not UNSET:
@@ -99,6 +152,10 @@ def to_dict(self) -> Dict[str, Any]:
99152
field_dict["not_required_model"] = not_required_model
100153
if not_required_nullable_model is not UNSET:
101154
field_dict["not_required_nullable_model"] = not_required_nullable_model
155+
if not_required_one_of_models is not UNSET:
156+
field_dict["not_required_one_of_models"] = not_required_one_of_models
157+
if not_required_nullable_one_of_models is not UNSET:
158+
field_dict["not_required_nullable_one_of_models"] = not_required_nullable_one_of_models
102159

103160
return field_dict
104161

@@ -128,6 +185,21 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
128185

129186
model = AModelModel.from_dict(d.pop("model"))
130187

188+
def _parse_one_of_models(data: Any) -> Union[FreeFormModel, ModelWithUnionProperty]:
189+
data = None if isinstance(data, Unset) else data
190+
one_of_models: Union[FreeFormModel, ModelWithUnionProperty]
191+
try:
192+
one_of_models = FreeFormModel.from_dict(data)
193+
194+
return one_of_models
195+
except: # noqa: E722
196+
pass
197+
one_of_models = ModelWithUnionProperty.from_dict(data)
198+
199+
return one_of_models
200+
201+
one_of_models = _parse_one_of_models(d.pop("one_of_models"))
202+
131203
nested_list_of_enums = []
132204
_nested_list_of_enums = d.pop("nested_list_of_enums", UNSET)
133205
for nested_list_of_enums_item_data in _nested_list_of_enums or []:
@@ -170,12 +242,82 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
170242
cast(Dict[str, Any], _not_required_nullable_model)
171243
)
172244

245+
def _parse_nullable_one_of_models(data: Any) -> Union[None, FreeFormModel, ModelWithUnionProperty]:
246+
data = None if isinstance(data, Unset) else data
247+
nullable_one_of_models: Union[None, FreeFormModel, ModelWithUnionProperty]
248+
try:
249+
nullable_one_of_models = FreeFormModel.from_dict(data)
250+
251+
return nullable_one_of_models
252+
except: # noqa: E722
253+
pass
254+
nullable_one_of_models = ModelWithUnionProperty.from_dict(data)
255+
256+
return nullable_one_of_models
257+
258+
nullable_one_of_models = _parse_nullable_one_of_models(d.pop("nullable_one_of_models"))
259+
260+
def _parse_not_required_one_of_models(data: Any) -> Union[Unset, FreeFormModel, ModelWithUnionProperty]:
261+
data = None if isinstance(data, Unset) else data
262+
not_required_one_of_models: Union[Unset, FreeFormModel, ModelWithUnionProperty]
263+
try:
264+
not_required_one_of_models = UNSET
265+
_not_required_one_of_models = data
266+
if not isinstance(_not_required_one_of_models, Unset):
267+
not_required_one_of_models = FreeFormModel.from_dict(
268+
cast(Dict[str, Any], _not_required_one_of_models)
269+
)
270+
271+
return not_required_one_of_models
272+
except: # noqa: E722
273+
pass
274+
not_required_one_of_models = UNSET
275+
_not_required_one_of_models = data
276+
if not isinstance(_not_required_one_of_models, Unset):
277+
not_required_one_of_models = ModelWithUnionProperty.from_dict(
278+
cast(Dict[str, Any], _not_required_one_of_models)
279+
)
280+
281+
return not_required_one_of_models
282+
283+
not_required_one_of_models = _parse_not_required_one_of_models(d.pop("not_required_one_of_models", UNSET))
284+
285+
def _parse_not_required_nullable_one_of_models(
286+
data: Any,
287+
) -> Union[Unset, None, FreeFormModel, ModelWithUnionProperty]:
288+
data = None if isinstance(data, Unset) else data
289+
not_required_nullable_one_of_models: Union[Unset, None, FreeFormModel, ModelWithUnionProperty]
290+
try:
291+
not_required_nullable_one_of_models = UNSET
292+
_not_required_nullable_one_of_models = data
293+
if not isinstance(_not_required_nullable_one_of_models, Unset):
294+
not_required_nullable_one_of_models = FreeFormModel.from_dict(
295+
cast(Dict[str, Any], _not_required_nullable_one_of_models)
296+
)
297+
298+
return not_required_nullable_one_of_models
299+
except: # noqa: E722
300+
pass
301+
not_required_nullable_one_of_models = UNSET
302+
_not_required_nullable_one_of_models = data
303+
if not isinstance(_not_required_nullable_one_of_models, Unset):
304+
not_required_nullable_one_of_models = ModelWithUnionProperty.from_dict(
305+
cast(Dict[str, Any], _not_required_nullable_one_of_models)
306+
)
307+
308+
return not_required_nullable_one_of_models
309+
310+
not_required_nullable_one_of_models = _parse_not_required_nullable_one_of_models(
311+
d.pop("not_required_nullable_one_of_models", UNSET)
312+
)
313+
173314
a_model = AModel(
174315
an_enum_value=an_enum_value,
175316
a_camel_date_time=a_camel_date_time,
176317
a_date=a_date,
177318
required_not_nullable=required_not_nullable,
178319
model=model,
320+
one_of_models=one_of_models,
179321
nested_list_of_enums=nested_list_of_enums,
180322
a_nullable_date=a_nullable_date,
181323
attr_1_leading_digit=attr_1_leading_digit,
@@ -185,6 +327,9 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
185327
nullable_model=nullable_model,
186328
not_required_model=not_required_model,
187329
not_required_nullable_model=not_required_nullable_model,
330+
nullable_one_of_models=nullable_one_of_models,
331+
not_required_one_of_models=not_required_one_of_models,
332+
not_required_nullable_one_of_models=not_required_nullable_one_of_models,
188333
)
189334

190335
return a_model

0 commit comments

Comments
 (0)