|
3 | 3 | import pytest
|
4 | 4 |
|
5 | 5 | import openapi_python_client.schema as oai
|
| 6 | +from openapi_python_client.config import JSONDecoder |
6 | 7 | from openapi_python_client.parser import responses
|
7 | 8 | from openapi_python_client.parser.errors import ParseError, PropertyError
|
8 | 9 | from openapi_python_client.parser.properties import Schemas
|
9 | 10 | from openapi_python_client.parser.responses import (
|
| 11 | + ALT_JSON_SOURCE, |
10 | 12 | JSON_SOURCE,
|
11 | 13 | NONE_SOURCE,
|
12 | 14 | HTTPStatusPattern,
|
@@ -184,6 +186,44 @@ def test_response_from_data_reference(mocker, any_property_factory):
|
184 | 186 | )
|
185 | 187 |
|
186 | 188 |
|
| 189 | +def test_response_with_alt_decoder(mocker, any_property_factory): |
| 190 | + prop = any_property_factory() |
| 191 | + property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas())) |
| 192 | + data = oai.Response.model_construct( |
| 193 | + description="", |
| 194 | + content={"application/json": oai.MediaType.model_construct(media_type_schema="something")}, |
| 195 | + ) |
| 196 | + config = MagicMock() |
| 197 | + config.content_type_overrides = {} |
| 198 | + config.alt_json_decoder = JSONDecoder.ORJSON |
| 199 | + status_code = HTTPStatusPattern(pattern="400", code_range=(400, 400)) |
| 200 | + |
| 201 | + response, schemas = responses.response_from_data( |
| 202 | + status_code=status_code, |
| 203 | + data=data, |
| 204 | + schemas=Schemas(), |
| 205 | + responses={}, |
| 206 | + parent_name="parent", |
| 207 | + config=config, |
| 208 | + ) |
| 209 | + |
| 210 | + assert response == responses.Response( |
| 211 | + status_code=status_code, |
| 212 | + prop=prop, |
| 213 | + source=ALT_JSON_SOURCE, |
| 214 | + data=data, |
| 215 | + |
| 216 | + ) |
| 217 | + property_from_data.assert_called_once_with( |
| 218 | + name="response_400", |
| 219 | + required=True, |
| 220 | + data="something", |
| 221 | + schemas=Schemas(), |
| 222 | + parent_name="parent", |
| 223 | + config=config, |
| 224 | + ) |
| 225 | + |
| 226 | + |
187 | 227 | @pytest.mark.parametrize(
|
188 | 228 | "ref_string,expected_error_string",
|
189 | 229 | [
|
|
0 commit comments