|
1 | 1 | from unittest.mock import MagicMock
|
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | import openapi_python_client.schema as oai
|
4 | 6 | from openapi_python_client.parser.errors import ParseError, PropertyError
|
5 | 7 | from openapi_python_client.parser.properties import Schemas
|
@@ -181,6 +183,38 @@ def test_response_from_data_reference(mocker, any_property_factory):
|
181 | 183 | )
|
182 | 184 |
|
183 | 185 |
|
| 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 | + |
184 | 218 | def test_response_from_data_content_type_overrides(any_property_factory):
|
185 | 219 | from openapi_python_client.parser.responses import Response, response_from_data
|
186 | 220 |
|
|
0 commit comments