Skip to content

Commit bdace8d

Browse files
committed
test: test alt json decoder
1 parent 5e275f9 commit bdace8d

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

tests/test_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
from ruamel.yaml import YAML as _YAML
99

10-
from openapi_python_client.config import ConfigFile
10+
from openapi_python_client.config import ConfigFile, JSONDecoder
1111

1212

1313
class YAML(_YAML):
@@ -49,6 +49,7 @@ def test_load_from_path(tmp_path: Path, filename, dump, relative) -> None:
4949
"project_name_override": "project-name",
5050
"package_name_override": "package_name",
5151
"package_version_override": "package_version",
52+
"alt_json_decoder": "orjson",
5253
}
5354
yml_file.write_text(dump(data))
5455

@@ -59,3 +60,4 @@ def test_load_from_path(tmp_path: Path, filename, dump, relative) -> None:
5960
assert config.project_name_override == "project-name"
6061
assert config.package_name_override == "package_name"
6162
assert config.package_version_override == "package_version"
63+
assert config.alt_json_decoder == JSONDecoder.ORJSON

tests/test_parser/test_responses.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import pytest
44

55
import openapi_python_client.schema as oai
6+
from openapi_python_client.config import JSONDecoder
67
from openapi_python_client.parser import responses
78
from openapi_python_client.parser.errors import ParseError, PropertyError
89
from openapi_python_client.parser.properties import Schemas
910
from openapi_python_client.parser.responses import (
11+
ALT_JSON_SOURCE,
1012
JSON_SOURCE,
1113
NONE_SOURCE,
1214
HTTPStatusPattern,
@@ -184,6 +186,44 @@ def test_response_from_data_reference(mocker, any_property_factory):
184186
)
185187

186188

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+
187227
@pytest.mark.parametrize(
188228
"ref_string,expected_error_string",
189229
[

0 commit comments

Comments
 (0)