Skip to content

Commit 8b0aca1

Browse files
committed
test coverage
1 parent fe6b7dd commit 8b0aca1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_parser/test_responses.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from unittest.mock import MagicMock
22

3+
import pytest
4+
35
import openapi_python_client.schema as oai
46
from openapi_python_client.parser.errors import ParseError, PropertyError
57
from openapi_python_client.parser.properties import Schemas
@@ -181,6 +183,38 @@ def test_response_from_data_reference(mocker, any_property_factory):
181183
)
182184

183185

186+
@pytest.mark.parametrize(
187+
"ref_string",
188+
[
189+
"#/components/responses/Nonexistent",
190+
"malformed-references-string",
191+
"#/components/something-that-isnt-responses/ErrorResponse",
192+
],
193+
)
194+
def test_response_from_data_reference_errors(ref_string, mocker, any_property_factory):
195+
from openapi_python_client.parser import responses
196+
197+
prop = any_property_factory()
198+
mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas()))
199+
predefined_response_data = oai.Response.model_construct(
200+
description="",
201+
content={"application/json": oai.MediaType.model_construct(media_type_schema="something")},
202+
)
203+
config = MagicMock()
204+
config.content_type_overrides = {}
205+
206+
response, schemas = responses.response_from_data(
207+
status_code=400,
208+
data=oai.Reference.model_construct(ref=ref_string),
209+
schemas=Schemas(),
210+
responses={"ErrorResponse": predefined_response_data},
211+
parent_name="parent",
212+
config=config,
213+
)
214+
215+
assert isinstance(response, ParseError)
216+
217+
184218
def test_response_from_data_content_type_overrides(any_property_factory):
185219
from openapi_python_client.parser.responses import Response, response_from_data
186220

0 commit comments

Comments
 (0)