Skip to content

Commit ffa54aa

Browse files
committed
Falcon3 tests
1 parent 8eff3dd commit ffa54aa

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

openapi_core/contrib/falcon/handlers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ def handle(cls, req, resp, errors):
3636
data = {
3737
'errors': data_errors,
3838
}
39+
data_str = dumps(data)
3940
data_error_max = max(data_errors, key=lambda x: x['status'])
4041
resp.content_type = MEDIA_JSON
4142
resp.status = cls.FALCON_STATUS_CODES.get(
4243
data_error_max['status'], HTTP_400)
43-
resp.body = dumps(data)
44+
# in falcon 3 body is deprecated
45+
if hasattr(resp, 'text'):
46+
resp.text = data_str
47+
else:
48+
resp.body = data_str
4449
resp.complete = True
4550

4651
@classmethod

openapi_core/contrib/falcon/responses.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ def create(cls, response):
1313
else:
1414
mimetype = response.options.default_media_type
1515

16+
# in falcon 3 body is deprecated
17+
if hasattr(response, "text"):
18+
data = response.text
19+
else:
20+
data = response.body
21+
1622
return OpenAPIResponse(
17-
data=response.body,
23+
data=data,
1824
status_code=status_code,
1925
mimetype=mimetype,
2026
)

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mock==2.0.0
22
pytest==3.5.0
33
pytest-flake8
44
pytest-cov==2.5.1
5-
falcon==2.0.0
5+
falcon==3.0.0
66
flask
77
django==2.2.18; python_version>="3.0"
88
requests==2.22.0

tests/integration/contrib/falcon/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def create_response(
4343
data, status_code=200, content_type='application/json'):
4444
options = ResponseOptions()
4545
resp = Response(options)
46-
resp.body = data
46+
resp.text = data
4747
resp.content_type = content_type
4848
resp.status = HTTP_200
4949
return resp

tests/integration/contrib/falcon/test_falcon_middlewares.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from json import dumps
22

3-
from falcon import API
3+
from falcon import App
44
from falcon.testing import TestClient
55
import pytest
66

@@ -24,7 +24,7 @@ def middleware(self, spec):
2424

2525
@pytest.fixture
2626
def app(self, middleware):
27-
return API(middleware=[middleware])
27+
return App(middleware=[middleware])
2828

2929
@pytest.yield_fixture
3030
def client(self, app):
@@ -67,7 +67,7 @@ def view_response_callable(request, response, id):
6767
})
6868
response.content_type = MEDIA_HTML
6969
response.status = HTTP_200
70-
response.body = 'success'
70+
response.text = 'success'
7171
self.view_response_callable = view_response_callable
7272
headers = {'Content-Type': 'application/json'}
7373
result = client.simulate_get(
@@ -190,7 +190,7 @@ def view_response_callable(request, response, id):
190190
})
191191
response.status = HTTP_200
192192
response.content_type = MEDIA_JSON
193-
response.body = dumps({
193+
response.text = dumps({
194194
'data': 'data',
195195
})
196196
self.view_response_callable = view_response_callable

0 commit comments

Comments
 (0)