|
| 1 | +from typing import Optional |
1 | 2 | from unittest.mock import MagicMock
|
2 | 3 |
|
3 | 4 | import pytest
|
@@ -201,6 +202,46 @@ def test_model_name_conflict(self):
|
201 | 202 | assert new_schemas == schemas
|
202 | 203 | assert err == PropertyError(detail='Attempted to generate duplicate models with name "OtherModel"', data=data)
|
203 | 204 |
|
| 205 | + @pytest.mark.parametrize( |
| 206 | + "name, title, parent_name, use_title_prefixing, expected", |
| 207 | + ids=( |
| 208 | + "basic name only", |
| 209 | + "title override", |
| 210 | + "name with parent", |
| 211 | + "name with parent and title prefixing disabled", |
| 212 | + "title with parent", |
| 213 | + "title with parent and title prefixing disabled", |
| 214 | + ), |
| 215 | + argvalues=( |
| 216 | + ("prop", None, None, True, "Prop"), |
| 217 | + ("prop", "MyModel", None, True, "MyModel"), |
| 218 | + ("prop", None, "parent", True, "ParentProp"), |
| 219 | + ("prop", None, "parent", False, "ParentProp"), |
| 220 | + ("prop", "MyModel", "parent", True, "ParentMyModel"), |
| 221 | + ("prop", "MyModel", "parent", False, "MyModel"), |
| 222 | + ), |
| 223 | + ) |
| 224 | + def test_model_naming( |
| 225 | + self, name: str, title: Optional[str], parent_name: Optional[str], use_title_prefixing: bool, expected: str |
| 226 | + ): |
| 227 | + from openapi_python_client.parser.properties import Schemas, build_model_property |
| 228 | + |
| 229 | + data = oai.Schema( |
| 230 | + title=title, |
| 231 | + properties={}, |
| 232 | + ) |
| 233 | + result = build_model_property( |
| 234 | + data=data, |
| 235 | + name=name, |
| 236 | + schemas=Schemas(), |
| 237 | + required=True, |
| 238 | + parent_name=parent_name, |
| 239 | + config=Config(use_path_prefixes_for_title_model_names=use_title_prefixing), |
| 240 | + roots={"root"}, |
| 241 | + process_properties=True, |
| 242 | + )[0] |
| 243 | + assert result.class_info.name == expected |
| 244 | + |
204 | 245 | def test_model_bad_properties(self):
|
205 | 246 | from openapi_python_client.parser.properties import Schemas, build_model_property
|
206 | 247 |
|
|
0 commit comments