Skip to content

Commit 1289711

Browse files
committed
Response data renamed
1 parent 3541793 commit 1289711

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

openapi_core/validators.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def __init__(self, errors, body=None, parameters=None):
4545

4646
class ResponseValidationResult(BaseValidationResult):
4747

48-
def __init__(self, errors, body=None, headers=None):
48+
def __init__(self, errors, data=None, headers=None):
4949
super(ResponseValidationResult, self).__init__(errors)
50-
self.body = body
50+
self.data = data
5151
self.headers = headers
5252

5353

@@ -137,15 +137,15 @@ def __init__(self, spec):
137137

138138
def validate(self, request, response):
139139
errors = []
140-
body = None
140+
data = None
141141
headers = {}
142142

143143
try:
144144
server = self.spec.get_server(request.full_url_pattern)
145145
# don't process if server errors
146146
except OpenAPIMappingError as exc:
147147
errors.append(exc)
148-
return ResponseValidationResult(errors, body, headers)
148+
return ResponseValidationResult(errors, data, headers)
149149

150150
operation_pattern = request.full_url_pattern.replace(
151151
server.default_url, '')
@@ -156,14 +156,14 @@ def validate(self, request, response):
156156
# don't process if operation errors
157157
except OpenAPIMappingError as exc:
158158
errors.append(exc)
159-
return ResponseValidationResult(errors, body, headers)
159+
return ResponseValidationResult(errors, data, headers)
160160

161161
try:
162162
operation_response = operation.get_response(str(response.status))
163163
# don't process if invalid response status code
164164
except InvalidResponse as exc:
165165
errors.append(exc)
166-
return ResponseValidationResult(errors, body, headers)
166+
return ResponseValidationResult(errors, data, headers)
167167

168168
if operation_response.content:
169169
try:
@@ -172,19 +172,19 @@ def validate(self, request, response):
172172
errors.append(exc)
173173
else:
174174
try:
175-
raw_body = self._get_raw_body(response)
175+
raw_data = self._get_raw_data(response)
176176
except MissingBody as exc:
177177
errors.append(exc)
178178
else:
179179
try:
180-
body = media_type.unmarshal(raw_body)
180+
data = media_type.unmarshal(raw_data)
181181
except OpenAPIMappingError as exc:
182182
errors.append(exc)
183183

184-
return ResponseValidationResult(errors, body, headers)
184+
return ResponseValidationResult(errors, data, headers)
185185

186-
def _get_raw_body(self, response):
187-
if not response.body:
188-
raise MissingBody("Missing required response body")
186+
def _get_raw_data(self, response):
187+
if not response.data:
188+
raise MissingBody("Missing required response data")
189189

190-
return response.body
190+
return response.data

openapi_core/wrappers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ class BaseOpenAPIResponse(object):
116116

117117
class MockResponse(BaseOpenAPIRequest):
118118

119-
def __init__(self, body, status=200, mimetype='application/json'):
120-
self.body = body
119+
def __init__(self, data, status=200, mimetype='application/json'):
120+
self.data = data
121121

122122
self.status = status
123123
self.mimetype = mimetype
@@ -129,8 +129,8 @@ def __init__(self, response):
129129
self.response = response
130130

131131
@property
132-
def body(self):
133-
return self.response.text
132+
def data(self):
133+
return self.response.data
134134

135135
@property
136136
def status(self):

tests/integration/test_validators.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_invalid_server(self, validator):
181181

182182
assert len(result.errors) == 1
183183
assert type(result.errors[0]) == InvalidServer
184-
assert result.body is None
184+
assert result.data is None
185185
assert result.headers == {}
186186

187187
def test_invalid_operation(self, validator):
@@ -192,7 +192,7 @@ def test_invalid_operation(self, validator):
192192

193193
assert len(result.errors) == 1
194194
assert type(result.errors[0]) == InvalidOperation
195-
assert result.body is None
195+
assert result.data is None
196196
assert result.headers == {}
197197

198198
def test_invalid_response(self, validator):
@@ -203,7 +203,7 @@ def test_invalid_response(self, validator):
203203

204204
assert len(result.errors) == 1
205205
assert type(result.errors[0]) == InvalidResponse
206-
assert result.body is None
206+
assert result.data is None
207207
assert result.headers == {}
208208

209209
def test_invalid_content_type(self, validator):
@@ -214,7 +214,7 @@ def test_invalid_content_type(self, validator):
214214

215215
assert len(result.errors) == 1
216216
assert type(result.errors[0]) == InvalidContentType
217-
assert result.body is None
217+
assert result.data is None
218218
assert result.headers == {}
219219

220220
def test_missing_body(self, validator):
@@ -225,7 +225,7 @@ def test_missing_body(self, validator):
225225

226226
assert len(result.errors) == 1
227227
assert type(result.errors[0]) == MissingBody
228-
assert result.body is None
228+
assert result.data is None
229229
assert result.headers == {}
230230

231231
def test_invalid_media_type_value(self, validator):
@@ -236,7 +236,7 @@ def test_invalid_media_type_value(self, validator):
236236

237237
assert len(result.errors) == 1
238238
assert type(result.errors[0]) == InvalidMediaTypeValue
239-
assert result.body is None
239+
assert result.data is None
240240
assert result.headers == {}
241241

242242
def test_get_pets(self, validator):
@@ -254,5 +254,5 @@ def test_get_pets(self, validator):
254254
result = validator.validate(request, response)
255255

256256
assert result.errors == []
257-
assert result.body == response_json
257+
assert result.data == response_json
258258
assert result.headers == {}

tests/integration/test_wrappers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_url_rule(self, request_factory, environ, request):
9292
assert openapi_request.mimetype == request.mimetype
9393

9494

95-
class TetsFlaskOpenAPIResponse(object):
95+
class TestFlaskOpenAPIResponse(object):
9696

9797
@pytest.fixture
9898
def response_factory(self):
@@ -105,6 +105,7 @@ def test_invalid_server(self, response_factory):
105105

106106
openapi_response = FlaskOpenAPIResponse(response)
107107

108-
assert openapi_response.body == response.text
108+
assert openapi_response.response == response
109+
assert openapi_response.data == response.data
109110
assert openapi_response.status == response.status
110111
assert openapi_response.mimetype == response.mimetype

0 commit comments

Comments
 (0)