forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_responses.py
More file actions
94 lines (70 loc) · 3.47 KB
/
test_responses.py
File metadata and controls
94 lines (70 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from unittest.mock import MagicMock
import openapi_python_client.schema as oai
from openapi_python_client.parser.errors import ParseError, PropertyError
from openapi_python_client.parser.properties import AnyProperty, Schemas, StringProperty
MODULE_NAME = "openapi_python_client.parser.responses"
def test_response_from_data_no_content():
from openapi_python_client.parser.responses import Response, response_from_data
response, schemas = response_from_data(
status_code=200,
data=oai.Response.construct(description=""),
schemas=Schemas(),
parent_name="parent",
config=MagicMock(),
)
assert response == Response(
status_code=200,
prop=AnyProperty(name="response_200", default=None, nullable=False, required=True, python_name="response_200"),
source="None",
)
def test_response_from_data_unsupported_content_type():
from openapi_python_client.parser.responses import response_from_data
data = oai.Response.construct(description="", content={"blah": None})
response, schemas = response_from_data(
status_code=200, data=data, schemas=Schemas(), parent_name="parent", config=MagicMock()
)
assert response == ParseError(data=data, detail="Unsupported content_type {'blah': None}")
def test_response_from_data_no_content_schema():
from openapi_python_client.parser.responses import Response, response_from_data
data = oai.Response.construct(description="", content={"application/json": oai.MediaType.construct()})
response, schemas = response_from_data(
status_code=200, data=data, schemas=Schemas(), parent_name="parent", config=MagicMock()
)
assert response == Response(
status_code=200,
prop=AnyProperty(name="response_200", default=None, nullable=False, required=True, python_name="response_200"),
source="None",
)
def test_response_from_data_property_error(mocker):
from openapi_python_client.parser import responses
property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(PropertyError(), Schemas()))
data = oai.Response.construct(
description="", content={"application/json": oai.MediaType.construct(media_type_schema="something")}
)
config = MagicMock()
response, schemas = responses.response_from_data(
status_code=400, data=data, schemas=Schemas(), parent_name="parent", config=config
)
assert response == PropertyError()
property_from_data.assert_called_once_with(
name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent", config=config
)
def test_response_from_data_property(mocker, property_factory):
from openapi_python_client.parser import responses
prop = property_factory()
property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas()))
data = oai.Response.construct(
description="", content={"application/json": oai.MediaType.construct(media_type_schema="something")}
)
config = MagicMock()
response, schemas = responses.response_from_data(
status_code=400, data=data, schemas=Schemas(), parent_name="parent", config=config
)
assert response == responses.Response(
status_code=400,
prop=prop,
source="response.json()",
)
property_from_data.assert_called_once_with(
name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent", config=config
)