Skip to content

Commit 2edc6fe

Browse files
committed
test coverage
1 parent 8b0aca1 commit 2edc6fe

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

tests/test_parser/test_responses.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ def test_response_from_data_reference(mocker, any_property_factory):
184184

185185

186186
@pytest.mark.parametrize(
187-
"ref_string",
187+
"ref_string,expected_error_string",
188188
[
189-
"#/components/responses/Nonexistent",
190-
"malformed-references-string",
191-
"#/components/something-that-isnt-responses/ErrorResponse",
189+
("#/components/responses/Nonexistent", "Could not find"),
190+
("https://remote-reference", "Remote references"),
191+
("#/components/something-that-isnt-responses/ErrorResponse", "not allowed in responses"),
192192
],
193193
)
194-
def test_response_from_data_reference_errors(ref_string, mocker, any_property_factory):
194+
def test_response_from_data_invalid_reference(ref_string, expected_error_string, mocker, any_property_factory):
195195
from openapi_python_client.parser import responses
196196

197197
prop = any_property_factory()
@@ -213,6 +213,38 @@ def test_response_from_data_reference_errors(ref_string, mocker, any_property_fa
213213
)
214214

215215
assert isinstance(response, ParseError)
216+
assert expected_error_string in response.detail
217+
218+
219+
def test_response_from_data_ref_to_response_that_is_a_ref(mocker, any_property_factory):
220+
from openapi_python_client.parser import responses
221+
222+
prop = any_property_factory()
223+
mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas()))
224+
predefined_response_base_data = oai.Response.model_construct(
225+
description="",
226+
content={"application/json": oai.MediaType.model_construct(media_type_schema="something")},
227+
)
228+
predefined_response_data = oai.Reference.model_construct(
229+
ref="#/components/references/BaseResponse",
230+
)
231+
config = MagicMock()
232+
config.content_type_overrides = {}
233+
234+
response, schemas = responses.response_from_data(
235+
status_code=400,
236+
data=oai.Reference.model_construct(ref="#/components/schemas/ErrorResponse"),
237+
schemas=Schemas(),
238+
responses={
239+
"BaseResponse": predefined_response_base_data,
240+
"ErrorResponse": predefined_response_data,
241+
},
242+
parent_name="parent",
243+
config=config,
244+
)
245+
246+
assert isinstance(response, ParseError)
247+
assert "not allowed in responses" in response.detail
216248

217249

218250
def test_response_from_data_content_type_overrides(any_property_factory):

0 commit comments

Comments
 (0)