mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-28 03:00:11 +00:00
Falcon3 tests
This commit is contained in:
parent
8eff3dd736
commit
ffa54aae88
5 changed files with 19 additions and 8 deletions
|
@ -36,11 +36,16 @@ class FalconOpenAPIErrorsHandler(object):
|
|||
data = {
|
||||
'errors': data_errors,
|
||||
}
|
||||
data_str = dumps(data)
|
||||
data_error_max = max(data_errors, key=lambda x: x['status'])
|
||||
resp.content_type = MEDIA_JSON
|
||||
resp.status = cls.FALCON_STATUS_CODES.get(
|
||||
data_error_max['status'], HTTP_400)
|
||||
resp.body = dumps(data)
|
||||
# in falcon 3 body is deprecated
|
||||
if hasattr(resp, 'text'):
|
||||
resp.text = data_str
|
||||
else:
|
||||
resp.body = data_str
|
||||
resp.complete = True
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -13,8 +13,14 @@ class FalconOpenAPIResponseFactory(object):
|
|||
else:
|
||||
mimetype = response.options.default_media_type
|
||||
|
||||
# in falcon 3 body is deprecated
|
||||
if hasattr(response, "text"):
|
||||
data = response.text
|
||||
else:
|
||||
data = response.body
|
||||
|
||||
return OpenAPIResponse(
|
||||
data=response.body,
|
||||
data=data,
|
||||
status_code=status_code,
|
||||
mimetype=mimetype,
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ mock==2.0.0
|
|||
pytest==3.5.0
|
||||
pytest-flake8
|
||||
pytest-cov==2.5.1
|
||||
falcon==2.0.0
|
||||
falcon==3.0.0
|
||||
flask
|
||||
django==2.2.18; python_version>="3.0"
|
||||
requests==2.22.0
|
||||
|
|
|
@ -43,7 +43,7 @@ def response_factory(environ_factory):
|
|||
data, status_code=200, content_type='application/json'):
|
||||
options = ResponseOptions()
|
||||
resp = Response(options)
|
||||
resp.body = data
|
||||
resp.text = data
|
||||
resp.content_type = content_type
|
||||
resp.status = HTTP_200
|
||||
return resp
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from json import dumps
|
||||
|
||||
from falcon import API
|
||||
from falcon import App
|
||||
from falcon.testing import TestClient
|
||||
import pytest
|
||||
|
||||
|
@ -24,7 +24,7 @@ class TestFalconOpenAPIMiddleware(object):
|
|||
|
||||
@pytest.fixture
|
||||
def app(self, middleware):
|
||||
return API(middleware=[middleware])
|
||||
return App(middleware=[middleware])
|
||||
|
||||
@pytest.yield_fixture
|
||||
def client(self, app):
|
||||
|
@ -67,7 +67,7 @@ class TestFalconOpenAPIMiddleware(object):
|
|||
})
|
||||
response.content_type = MEDIA_HTML
|
||||
response.status = HTTP_200
|
||||
response.body = 'success'
|
||||
response.text = 'success'
|
||||
self.view_response_callable = view_response_callable
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
result = client.simulate_get(
|
||||
|
@ -190,7 +190,7 @@ class TestFalconOpenAPIMiddleware(object):
|
|||
})
|
||||
response.status = HTTP_200
|
||||
response.content_type = MEDIA_JSON
|
||||
response.body = dumps({
|
||||
response.text = dumps({
|
||||
'data': 'data',
|
||||
})
|
||||
self.view_response_callable = view_response_callable
|
||||
|
|
Loading…
Reference in a new issue