Skip to content

Commit 2c4e4e1

Browse files
committed
Update test
1 parent e37715e commit 2c4e4e1

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

tests/test_parser/test_properties/test_model_property.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,28 @@ def test_happy_path(self, model_property_factory, string_property_factory, date_
165165
additional_properties=ANY_ADDITIONAL_PROPERTY,
166166
)
167167

168-
def test_model_name_conflict(self, config):
168+
@pytest.mark.parametrize(
169+
"existing_names, new_name, enumerate_duplicate_model_names, expected",
170+
ids=(
171+
"name without duplicate suffix",
172+
"name with duplicate suffix",
173+
"name with duplicate suffix and matching existing name",
174+
),
175+
argvalues=(
176+
(["OtherModel"], "OtherModel", None, 'Attempted to generate duplicate models with name "OtherModel"'),
177+
(["OtherModel"], "OtherModel", True, "OtherModel2"),
178+
(["OtherModel", "OtherModel2"], "OtherModel", True, "OtherModel3"),
179+
),
180+
)
181+
def test_model_name_conflict(self, existing_names: str, new_name: str, enumerate_duplicate_model_names: Optional[str], expected: str, config):
169182
from openapi_python_client.parser.properties import ModelProperty
170183

171184
data = oai.Schema.model_construct()
172-
schemas = Schemas(classes_by_name={"OtherModel": None})
173-
174-
err, new_schemas = ModelProperty.build(
185+
schemas = Schemas(classes_by_name={name: None for name in existing_names})
186+
config = evolve(config, enumerate_duplicate_model_names=enumerate_duplicate_model_names)
187+
result, new_schemas = ModelProperty.build(
175188
data=data,
176-
name="OtherModel",
189+
name=new_name,
177190
schemas=schemas,
178191
required=True,
179192
parent_name=None,
@@ -182,8 +195,13 @@ def test_model_name_conflict(self, config):
182195
process_properties=True,
183196
)
184197

185-
assert new_schemas == schemas
186-
assert err == PropertyError(detail='Attempted to generate duplicate models with name "OtherModel"', data=data)
198+
assert isinstance(result, (PropertyError, ModelProperty))
199+
if isinstance(result, PropertyError):
200+
assert new_schemas == schemas
201+
assert result == PropertyError(detail=expected, data=data)
202+
else: # ModelProperty
203+
assert result.class_info.name in new_schemas.classes_by_name
204+
assert result.class_info.name == expected
187205

188206
@pytest.mark.parametrize(
189207
"name, title, parent_name, use_title_prefixing, expected",

0 commit comments

Comments
 (0)