Skip to content

Commit 5005d82

Browse files
committed
test: Add more unit test coverage
1 parent 0648aa0 commit 5005d82

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/test_parser/test_properties/test_init.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,25 @@ def test_property_from_data_ref_not_found(self, mocker):
611611
assert prop == PropertyError(data=data, detail="Could not find reference in parsed models or enums")
612612
assert schemas == new_schemas
613613

614+
def test_property_from_data_invalid_ref(self, mocker):
615+
from openapi_python_client.parser.properties import PropertyError, Schemas, property_from_data
616+
617+
name = mocker.MagicMock()
618+
required = mocker.MagicMock()
619+
data = oai.Reference.construct(ref=mocker.MagicMock())
620+
parse_reference_path = mocker.patch(
621+
f"{MODULE_NAME}.parse_reference_path", return_value=PropertyError(detail="bad stuff")
622+
)
623+
schemas = Schemas()
624+
625+
prop, new_schemas = property_from_data(
626+
name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=mocker.MagicMock()
627+
)
628+
629+
parse_reference_path.assert_called_once_with(data.ref)
630+
assert prop == PropertyError(data=data, detail="bad stuff")
631+
assert schemas == new_schemas
632+
614633
def test_property_from_data_string(self, mocker):
615634
from openapi_python_client.parser.properties import Schemas, property_from_data
616635

tests/test_parser/test_properties/test_model_property.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,32 @@ def test_conflicting_properties_different_types(self, model_property_factory):
231231

232232
assert isinstance(result, PropertyError)
233233

234+
def test_invalid_reference(self, model_property_factory):
235+
from openapi_python_client.parser.properties import Schemas
236+
from openapi_python_client.parser.properties.model_property import _process_properties
237+
238+
data = oai.Schema.construct(allOf=[oai.Reference.construct(ref="ThisIsNotGood")])
239+
schemas = Schemas()
240+
241+
result = _process_properties(data=data, schemas=schemas, class_name="", config=Config())
242+
243+
assert isinstance(result, PropertyError)
244+
245+
def test_non_model_reference(self, enum_property_factory):
246+
from openapi_python_client.parser.properties import Schemas
247+
from openapi_python_client.parser.properties.model_property import _process_properties
248+
249+
data = oai.Schema.construct(allOf=[oai.Reference.construct(ref="#/First")])
250+
schemas = Schemas(
251+
classes_by_reference={
252+
"/First": enum_property_factory(),
253+
}
254+
)
255+
256+
result = _process_properties(data=data, schemas=schemas, class_name="", config=Config())
257+
258+
assert isinstance(result, PropertyError)
259+
234260
def test_conflicting_properties_same_types(self, model_property_factory):
235261
from openapi_python_client.parser.properties import Schemas
236262
from openapi_python_client.parser.properties.model_property import _process_properties

0 commit comments

Comments
 (0)