-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathtest_model_property.py
752 lines (653 loc) · 29.1 KB
/
test_model_property.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
from typing import Optional
import pytest
from attr import evolve
import openapi_python_client.schema as oai
from openapi_python_client.parser.errors import PropertyError
from openapi_python_client.parser.properties import Schemas, StringProperty
from openapi_python_client.parser.properties.model_property import ANY_ADDITIONAL_PROPERTY, _process_properties
MODULE_NAME = "openapi_python_client.parser.properties.model_property"
class TestModelProperty:
@pytest.mark.parametrize(
"no_optional,required,json,quoted,expected",
[
(False, False, False, False, "Union[Unset, MyClass]"),
(False, True, False, False, "MyClass"),
(True, False, False, False, "MyClass"),
(True, True, False, False, "MyClass"),
(False, True, True, False, "dict[str, Any]"),
(False, False, False, True, "Union[Unset, 'MyClass']"),
(False, True, False, True, "'MyClass'"),
(True, False, False, True, "'MyClass'"),
(True, True, False, True, "'MyClass'"),
(False, True, True, True, "dict[str, Any]"),
],
)
def test_get_type_string(self, no_optional, required, json, expected, model_property_factory, quoted):
prop = model_property_factory(
required=required,
)
assert prop.get_type_string(no_optional=no_optional, json=json, quoted=quoted) == expected
def test_get_imports(self, model_property_factory):
prop = model_property_factory(required=False)
assert prop.get_imports(prefix="..") == {
"from typing import Union",
"from ..types import UNSET, Unset",
"from typing import cast",
}
def test_get_lazy_imports(self, model_property_factory):
prop = model_property_factory(required=False)
assert prop.get_lazy_imports(prefix="..") == {
"from ..models.my_module import MyClass",
}
def test_is_base_type(self, model_property_factory):
assert model_property_factory().is_base_type is False
@pytest.mark.parametrize(
"quoted,expected",
[
(False, "MyClass"),
(True, '"MyClass"'),
],
)
def test_get_base_type_string(self, quoted, expected, model_property_factory):
m = model_property_factory()
assert m.get_base_type_string(quoted=quoted) == expected
class TestBuild:
@pytest.mark.parametrize(
"additional_properties_schema, expected_additional_properties",
[
(True, ANY_ADDITIONAL_PROPERTY),
(oai.Schema.model_construct(), ANY_ADDITIONAL_PROPERTY),
(None, ANY_ADDITIONAL_PROPERTY),
(False, None),
(
oai.Schema.model_construct(type="string"),
StringProperty(
name="AdditionalProperty",
required=True,
default=None,
python_name="additional_property",
description=None,
example=None,
),
),
],
)
def test_additional_schemas(self, additional_properties_schema, expected_additional_properties, config):
from openapi_python_client.parser.properties import ModelProperty, Schemas
data = oai.Schema.model_construct(
additionalProperties=additional_properties_schema,
)
model, _ = ModelProperty.build(
data=data,
name="prop",
schemas=Schemas(),
required=True,
parent_name="parent",
config=config,
roots={"root"},
process_properties=True,
)
assert model.additional_properties == expected_additional_properties
def test_happy_path(self, model_property_factory, string_property_factory, date_time_property_factory, config):
from openapi_python_client.parser.properties import Class, ModelProperty, Schemas
name = "prop"
required = True
data = oai.Schema.model_construct(
required=["req"],
title="MyModel",
properties={
"req": oai.Schema.model_construct(type="string"),
"opt": oai.Schema(type="string", format="date-time"),
},
description="A class called MyModel",
)
schemas = Schemas(classes_by_reference={"OtherModel": None}, classes_by_name={"OtherModel": None})
class_info = Class(name="ParentMyModel", module_name="parent_my_model")
roots = {"root"}
model, new_schemas = ModelProperty.build(
data=data,
name=name,
schemas=schemas,
required=required,
parent_name="parent",
config=config,
roots=roots,
process_properties=True,
)
assert new_schemas != schemas
assert new_schemas.classes_by_name == {
"OtherModel": None,
"ParentMyModel": model,
}
assert new_schemas.classes_by_reference == {
"OtherModel": None,
}
assert new_schemas.dependencies == {"root": {class_info.name}}
assert model == model_property_factory(
name=name,
required=required,
roots={*roots, class_info.name},
data=data,
class_info=class_info,
required_properties=[string_property_factory(name="req", required=True)],
optional_properties=[date_time_property_factory(name="opt", required=False)],
description=data.description,
relative_imports={
"from dateutil.parser import isoparse",
"from typing import cast",
"import datetime",
"from ..types import UNSET, Unset",
"from typing import Union",
},
lazy_imports=set(),
additional_properties=ANY_ADDITIONAL_PROPERTY,
)
@pytest.mark.parametrize(
"existing_names, new_name, enumerate_duplicate_model_names, should_raise, expected",
ids=(
"name without duplicate suffix",
"name with duplicate suffix",
"name with duplicate suffix and matching existing name",
),
argvalues=(
(["OtherModel"], "OtherModel", None, True, 'Attempted to generate duplicate models with name "OtherModel"'),
(["OtherModel"], "OtherModel", True, False, "OtherModel1"),
(["OtherModel", "OtherModel1"], "OtherModel", True, False, "OtherModel2"),
),
)
def test_model_name_conflict(
self,
existing_names: str,
new_name: str,
enumerate_duplicate_model_names: Optional[str],
should_raise: bool,
expected: str,
config,
):
from openapi_python_client.parser.properties import ModelProperty
data = oai.Schema.model_construct()
schemas = Schemas(classes_by_name={name: None for name in existing_names})
config = evolve(config, enumerate_duplicate_model_names=enumerate_duplicate_model_names)
result, new_schemas = ModelProperty.build(
data=data,
name=new_name,
schemas=schemas,
required=True,
parent_name=None,
config=config,
roots={"root"},
process_properties=True,
)
if should_raise:
assert isinstance(result, PropertyError)
assert new_schemas == schemas
assert result.detail == expected
else:
assert isinstance(result, ModelProperty)
assert result.class_info.name in new_schemas.classes_by_name
assert result.class_info.name == expected
@pytest.mark.parametrize(
"name, title, parent_name, use_title_prefixing, expected",
ids=(
"basic name only",
"title override",
"name with parent",
"name with parent and title prefixing disabled",
"title with parent",
"title with parent and title prefixing disabled",
),
argvalues=(
("prop", None, None, True, "Prop"),
("prop", "MyModel", None, True, "MyModel"),
("prop", None, "parent", True, "ParentProp"),
("prop", None, "parent", False, "ParentProp"),
("prop", "MyModel", "parent", True, "ParentMyModel"),
("prop", "MyModel", "parent", False, "MyModel"),
),
)
def test_model_naming(
self,
name: str,
title: Optional[str],
parent_name: Optional[str],
use_title_prefixing: bool,
expected: str,
config,
):
from openapi_python_client.parser.properties import ModelProperty
data = oai.Schema(
title=title,
properties={},
)
config = evolve(config, use_path_prefixes_for_title_model_names=use_title_prefixing)
result = ModelProperty.build(
data=data,
name=name,
schemas=Schemas(),
required=True,
parent_name=parent_name,
config=config,
roots={"root"},
process_properties=True,
)[0]
assert result.class_info.name == expected
def test_model_bad_properties(self, config):
from openapi_python_client.parser.properties import ModelProperty
data = oai.Schema(
properties={
"bad": oai.Reference.model_construct(ref="#/components/schema/NotExist"),
},
)
result = ModelProperty.build(
data=data,
name="prop",
schemas=Schemas(),
required=True,
parent_name="parent",
config=config,
roots={"root"},
process_properties=True,
)[0]
assert isinstance(result, PropertyError)
def test_model_bad_additional_properties(self, config):
from openapi_python_client.parser.properties import ModelProperty
additional_properties = oai.Schema(
type="object",
properties={
"bad": oai.Reference(ref="#/components/schemas/not_exist"),
},
)
data = oai.Schema(additionalProperties=additional_properties)
result = ModelProperty.build(
data=data,
name="prop",
schemas=Schemas(),
required=True,
parent_name="parent",
config=config,
roots={"root"},
process_properties=True,
)[0]
assert isinstance(result, PropertyError)
def test_process_properties_false(self, model_property_factory, config):
from openapi_python_client.parser.properties import Class, ModelProperty
name = "prop"
required = True
data = oai.Schema.model_construct(
required=["req"],
title="MyModel",
properties={
"req": oai.Schema.model_construct(type="string"),
"opt": oai.Schema(type="string", format="date-time"),
},
description="A class called MyModel",
)
schemas = Schemas(classes_by_reference={"OtherModel": None}, classes_by_name={"OtherModel": None})
roots = {"root"}
class_info = Class(name="ParentMyModel", module_name="parent_my_model")
model, new_schemas = ModelProperty.build(
data=data,
name=name,
schemas=schemas,
required=required,
parent_name="parent",
config=config,
roots=roots,
process_properties=False,
)
assert new_schemas != schemas
assert new_schemas.classes_by_name == {
"OtherModel": None,
"ParentMyModel": model,
}
assert new_schemas.classes_by_reference == {
"OtherModel": None,
}
assert model == model_property_factory(
name=name,
required=required,
class_info=class_info,
data=data,
description=data.description,
roots={*roots, class_info.name},
)
class TestProcessProperties:
def test_conflicting_properties_different_types(
self, model_property_factory, string_property_factory, int_property_factory, config
):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(
required_properties=[], optional_properties=[string_property_factory()]
),
"/Second": model_property_factory(required_properties=[], optional_properties=[int_property_factory()]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_process_properties_reference_not_exist(self, config):
data = oai.Schema(
properties={
"bad": oai.Reference.model_construct(ref="#/components/schema/NotExist"),
},
)
result = _process_properties(data=data, class_name="", schemas=Schemas(), config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_process_properties_all_of_reference_not_exist(self, config):
data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="#/components/schema/NotExist")])
result = _process_properties(data=data, class_name="", schemas=Schemas(), config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_process_properties_model_property_roots(self, model_property_factory, config):
roots = {"root"}
data = oai.Schema(properties={"test_model_property": oai.Schema.model_construct(type="object")})
result = _process_properties(data=data, class_name="", schemas=Schemas(), config=config, roots=roots)
assert all(root in result.optional_props[0].roots for root in roots)
def test_invalid_reference(self, config):
data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="ThisIsNotGood")])
schemas = Schemas()
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_non_model_reference(self, enum_property_factory, config):
data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="#/First")])
schemas = Schemas(
classes_by_reference={
"/First": enum_property_factory(),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_reference_not_processed(self, model_property_factory, config):
data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="#/Unprocessed")])
schemas = Schemas(
classes_by_reference={
"/Unprocessed": model_property_factory(),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_allof_string_and_string_enum(
self, model_property_factory, enum_property_factory, string_property_factory, config
):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
enum_property = enum_property_factory(
values={"foo": "foo"},
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(
required_properties=[],
optional_properties=[string_property_factory(required=False)],
),
"/Second": model_property_factory(required_properties=[], optional_properties=[enum_property]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert result.required_props[0] == enum_property
def test_allof_string_enum_and_string(
self, model_property_factory, enum_property_factory, string_property_factory, config
):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
enum_property = enum_property_factory(
required=False,
values={"foo": "foo"},
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(required_properties=[], optional_properties=[enum_property]),
"/Second": model_property_factory(
required_properties=[],
optional_properties=[string_property_factory(required=False)],
),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert result.optional_props[0] == enum_property
def test_allof_int_and_int_enum(self, model_property_factory, enum_property_factory, int_property_factory, config):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
enum_property = enum_property_factory(
values={"foo": 1},
value_type=int,
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(required_properties=[], optional_properties=[int_property_factory()]),
"/Second": model_property_factory(required_properties=[], optional_properties=[enum_property]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert result.required_props[0] == enum_property
def test_allof_enum_incompatible_type(
self, model_property_factory, enum_property_factory, int_property_factory, config
):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
enum_property = enum_property_factory(
values={"foo": 1},
value_type=str,
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(required_properties=[], optional_properties=[int_property_factory()]),
"/Second": model_property_factory(required_properties=[], optional_properties=[enum_property]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_allof_string_enums(self, model_property_factory, enum_property_factory, config):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
enum_property1 = enum_property_factory(
name="an_enum",
value_type=str,
values={"foo": "foo"},
)
enum_property2 = enum_property_factory(
name="an_enum",
values={"foo": "foo", "bar": "bar"},
value_type=str,
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(required_properties=[], optional_properties=[enum_property1]),
"/Second": model_property_factory(required_properties=[], optional_properties=[enum_property2]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert result.required_props[0] == enum_property1
def test_allof_int_enums(self, model_property_factory, enum_property_factory, config):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
enum_property1 = enum_property_factory(
name="an_enum",
values={"foo": 1, "bar": 2},
value_type=int,
)
enum_property2 = enum_property_factory(
name="an_enum",
values={"foo": 1},
value_type=int,
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(required_properties=[], optional_properties=[enum_property1]),
"/Second": model_property_factory(required_properties=[], optional_properties=[enum_property2]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert result.required_props[0] == enum_property2
def test_allof_enums_are_not_subsets(self, model_property_factory, enum_property_factory, config):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
enum_property1 = enum_property_factory(
name="an_enum",
values={"foo": 1, "bar": 2},
value_type=int,
)
enum_property2 = enum_property_factory(
name="an_enum",
values={"foo": 1, "baz": 3},
value_type=int,
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(required_properties=[], optional_properties=[enum_property1]),
"/Second": model_property_factory(required_properties=[], optional_properties=[enum_property2]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_duplicate_properties(self, model_property_factory, string_property_factory, config):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
prop = string_property_factory(required=False)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(required_properties=[], optional_properties=[prop]),
"/Second": model_property_factory(required_properties=[], optional_properties=[prop]),
}
)
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert result.optional_props == [prop], "There should only be one copy of duplicate properties"
@pytest.mark.parametrize("first_required", [True, False])
@pytest.mark.parametrize("second_required", [True, False])
def test_mixed_requirements(
self,
model_property_factory,
first_required,
second_required,
string_property_factory,
config,
):
data = oai.Schema.model_construct(
allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")]
)
schemas = Schemas(
classes_by_reference={
"/First": model_property_factory(
required_properties=[],
optional_properties=[string_property_factory(required=first_required)],
),
"/Second": model_property_factory(
required_properties=[],
optional_properties=[string_property_factory(required=second_required)],
),
}
)
roots = {"root"}
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots=roots)
required = first_required or second_required
expected_prop = string_property_factory(
required=required,
)
assert result.schemas.dependencies == {"/First": roots, "/Second": roots}
if not required:
assert result.optional_props == [expected_prop]
else:
assert result.required_props == [expected_prop]
def test_direct_properties_non_ref(self, string_property_factory, config):
data = oai.Schema.model_construct(
allOf=[
oai.Schema.model_construct(
required=["first"],
properties={
"first": oai.Schema.model_construct(type="string"),
"second": oai.Schema.model_construct(type="string"),
},
)
]
)
schemas = Schemas()
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert result.optional_props == [string_property_factory(name="second", required=False)]
assert result.required_props == [string_property_factory(name="first", required=True)]
def test_conflicting_property_names(self, config):
data = oai.Schema.model_construct(
properties={
"int": oai.Schema.model_construct(type="integer"),
"int_": oai.Schema.model_construct(type="string"),
}
)
schemas = Schemas()
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert isinstance(result, PropertyError)
def test_merge_inline_objects(self, model_property_factory, enum_property_factory, config):
data = oai.Schema.model_construct(
allOf=[
oai.Schema.model_construct(
type="object",
properties={
"prop1": oai.Schema.model_construct(type="string", default="a"),
},
),
oai.Schema.model_construct(
type="object",
properties={
"prop1": oai.Schema.model_construct(type="string", description="desc"),
},
),
]
)
schemas = Schemas()
result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"})
assert not isinstance(result, PropertyError)
assert len(result.optional_props) == 1
prop1 = result.optional_props[0]
assert isinstance(prop1, StringProperty)
assert prop1.description == "desc"
assert prop1.default == StringProperty.convert_value("a")
class TestProcessModel:
def test_process_model_error(self, mocker, model_property_factory, config):
from openapi_python_client.parser.properties import Schemas
from openapi_python_client.parser.properties.model_property import process_model
model_prop = model_property_factory()
schemas = Schemas()
process_property_data = mocker.patch(f"{MODULE_NAME}._process_property_data")
process_property_data.return_value = (PropertyError(), schemas)
result = process_model(model_prop=model_prop, schemas=schemas, config=config)
assert result == PropertyError()
assert model_prop.required_properties is None
assert model_prop.optional_properties is None
assert model_prop.relative_imports is None
assert model_prop.additional_properties is None
def test_process_model(self, mocker, model_property_factory, config):
from openapi_python_client.parser.properties import Schemas
from openapi_python_client.parser.properties.model_property import _PropertyData, process_model
model_prop = model_property_factory()
schemas = Schemas()
property_data = _PropertyData(
required_props=["required"],
optional_props=["optional"],
relative_imports={"relative"},
lazy_imports={"lazy"},
schemas=schemas,
)
additional_properties = True
process_property_data = mocker.patch(f"{MODULE_NAME}._process_property_data")
process_property_data.return_value = ((property_data, additional_properties), schemas)
result = process_model(model_prop=model_prop, schemas=schemas, config=config)
assert result == schemas
assert model_prop.required_properties == property_data.required_props
assert model_prop.optional_properties == property_data.optional_props
assert model_prop.relative_imports == property_data.relative_imports
assert model_prop.lazy_imports == property_data.lazy_imports
assert model_prop.additional_properties == additional_properties
def test_set_relative_imports(model_property_factory):
from openapi_python_client.parser.properties import Class
class_info = Class("ClassName", module_name="module_name")
relative_imports = {f"from ..models.{class_info.module_name} import {class_info.name}"}
model_property = model_property_factory(class_info=class_info, relative_imports=relative_imports)
assert model_property.relative_imports == set()