@@ -63,12 +63,14 @@ def test_response_from_data_unsupported_content_type():
63
63
from openapi_python_client .parser .responses import response_from_data
64
64
65
65
data = oai .Response .model_construct (description = "" , content = {"blah" : None })
66
+ config = MagicMock ()
67
+ config .content_type_overrides = {}
66
68
response , schemas = response_from_data (
67
69
status_code = 200 ,
68
70
data = data ,
69
71
schemas = Schemas (),
70
72
parent_name = "parent" ,
71
- config = MagicMock () ,
73
+ config = config ,
72
74
)
73
75
74
76
assert response == ParseError (data = data , detail = "Unsupported content_type {'blah': None}" )
@@ -81,12 +83,14 @@ def test_response_from_data_no_content_schema(any_property_factory):
81
83
description = "" ,
82
84
content = {"application/vnd.api+json; version=2.2" : oai .MediaType .model_construct ()},
83
85
)
86
+ config = MagicMock ()
87
+ config .content_type_overrides = {}
84
88
response , schemas = response_from_data (
85
89
status_code = 200 ,
86
90
data = data ,
87
91
schemas = Schemas (),
88
92
parent_name = "parent" ,
89
- config = MagicMock () ,
93
+ config = config ,
90
94
)
91
95
92
96
assert response == Response (
@@ -111,6 +115,7 @@ def test_response_from_data_property_error(mocker):
111
115
content = {"application/json" : oai .MediaType .model_construct (media_type_schema = "something" )},
112
116
)
113
117
config = MagicMock ()
118
+ config .content_type_overrides = {}
114
119
115
120
response , schemas = responses .response_from_data (
116
121
status_code = 400 ,
@@ -141,6 +146,7 @@ def test_response_from_data_property(mocker, any_property_factory):
141
146
content = {"application/json" : oai .MediaType .model_construct (media_type_schema = "something" )},
142
147
)
143
148
config = MagicMock ()
149
+ config .content_type_overrides = {}
144
150
145
151
response , schemas = responses .response_from_data (
146
152
status_code = 400 ,
@@ -164,3 +170,35 @@ def test_response_from_data_property(mocker, any_property_factory):
164
170
parent_name = "parent" ,
165
171
config = config ,
166
172
)
173
+
174
+
175
+ def test_response_from_data_content_type_overrides (any_property_factory ):
176
+ from openapi_python_client .parser .responses import Response , response_from_data
177
+
178
+ data = oai .Response .model_construct (
179
+ description = "" ,
180
+ content = {"application/zip" : oai .MediaType .model_construct ()},
181
+ )
182
+ config = MagicMock ()
183
+ config .content_type_overrides = {
184
+ "application/zip" : "application/octet-stream"
185
+ }
186
+ response , schemas = response_from_data (
187
+ status_code = 200 ,
188
+ data = data ,
189
+ schemas = Schemas (),
190
+ parent_name = "parent" ,
191
+ config = config ,
192
+ )
193
+
194
+ assert response == Response (
195
+ status_code = 200 ,
196
+ prop = any_property_factory (
197
+ name = "response_200" ,
198
+ default = None ,
199
+ required = True ,
200
+ description = data .description ,
201
+ ),
202
+ source = NONE_SOURCE ,
203
+ data = data ,
204
+ )
0 commit comments