-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Yelp/bravado
- Loading branch information
Showing
9 changed files
with
305 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
CONFIG_DEFAULTS = { | ||
# See the constructor of :class:`bravado.http_future.HttpFuture` for an | ||
# in depth explanation of what this means. | ||
'also_return_response': False, | ||
} | ||
|
||
REQUEST_OPTIONS_DEFAULTS = { | ||
# List of callbacks that are executed after the incoming response has been | ||
# validated and the swagger_result has been unmarshalled. | ||
# | ||
# The callback should expect two arguments: | ||
# param : incoming_response | ||
# type : subclass of class:`bravado_core.response.IncomingResponse` | ||
# param : operation | ||
# type : class:`bravado_core.operation.Operation` | ||
'response_callbacks': [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
Changelog | ||
========= | ||
|
||
0.9.1 (2018-XX-XX) | ||
------------------ | ||
- bravado version: 9.2.2 | ||
|
||
0.9.0 (2017-11-17) | ||
------------------ | ||
- Initial release, based on the source code of bravado 9.2.0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# -*- coding: utf-8 -*- | ||
from asyncio import coroutine | ||
|
||
import mock | ||
import msgpack | ||
import pytest | ||
from bravado_core.content_type import APP_JSON | ||
from bravado_core.content_type import APP_MSGPACK | ||
from bravado_core.response import IncomingResponse | ||
from bravado_core.spec import Spec | ||
|
||
from aiobravado.http_future import unmarshal_response_inner | ||
|
||
|
||
@pytest.fixture | ||
def empty_swagger_spec(): | ||
return Spec(spec_dict={}) | ||
|
||
|
||
@pytest.fixture | ||
def response_spec(): | ||
return { | ||
'description': "Day of the week", | ||
'schema': { | ||
'type': 'string', | ||
} | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def mock_get_response_spec(): | ||
with mock.patch('aiobravado.http_future.get_response_spec') as m: | ||
yield m | ||
|
||
|
||
@pytest.fixture | ||
def mock_validate_schema_object(): | ||
with mock.patch('aiobravado.http_future.validate_schema_object') as m: | ||
yield m | ||
|
||
|
||
def test_no_content(mock_get_response_spec, empty_swagger_spec, event_loop): | ||
response_spec = { | ||
'description': "I don't have a 'schema' key so I return nothing", | ||
} | ||
response = mock.Mock(spec=IncomingResponse, status_code=200) | ||
|
||
mock_get_response_spec.return_value = response_spec | ||
op = mock.Mock(swagger_spec=empty_swagger_spec) | ||
result = event_loop.run_until_complete(unmarshal_response_inner(response, op)) | ||
assert result is None | ||
|
||
|
||
def test_json_content(mock_get_response_spec, empty_swagger_spec, response_spec, event_loop): | ||
response = mock.Mock( | ||
spec=IncomingResponse, | ||
status_code=200, | ||
headers={'content-type': APP_JSON}, | ||
json=coroutine(mock.Mock(return_value='Monday')), | ||
) | ||
|
||
mock_get_response_spec.return_value = response_spec | ||
op = mock.Mock(swagger_spec=empty_swagger_spec) | ||
assert 'Monday' == event_loop.run_until_complete(unmarshal_response_inner(response, op)) | ||
|
||
|
||
def test_msgpack_content(mock_get_response_spec, empty_swagger_spec, response_spec, event_loop): | ||
message = 'Monday' | ||
response = mock.Mock( | ||
spec=IncomingResponse, | ||
status_code=200, | ||
headers={'content-type': APP_MSGPACK}, | ||
raw_bytes=coroutine(lambda: msgpack.dumps(message))(), | ||
) | ||
|
||
mock_get_response_spec.return_value = response_spec | ||
op = mock.Mock(swagger_spec=empty_swagger_spec) | ||
assert message == event_loop.run_until_complete(unmarshal_response_inner(response, op)) | ||
|
||
|
||
def test_text_content(mock_get_response_spec, empty_swagger_spec, response_spec, event_loop): | ||
response = mock.Mock( | ||
spec=IncomingResponse, | ||
status_code=200, | ||
headers={'content-type': 'text/plain'}, | ||
text='Monday', | ||
) | ||
|
||
mock_get_response_spec.return_value = response_spec | ||
op = mock.Mock(swagger_spec=empty_swagger_spec) | ||
assert 'Monday' == event_loop.run_until_complete(unmarshal_response_inner(response, op)) | ||
|
||
|
||
def test_skips_validation( | ||
mock_validate_schema_object, | ||
mock_get_response_spec, | ||
empty_swagger_spec, | ||
response_spec, | ||
event_loop, | ||
): | ||
empty_swagger_spec.config['validate_responses'] = False | ||
response = mock.Mock( | ||
spec=IncomingResponse, | ||
status_code=200, | ||
headers={'content-type': APP_JSON}, | ||
json=coroutine(mock.Mock(return_value='Monday')), | ||
) | ||
|
||
mock_get_response_spec.return_value = response_spec | ||
op = mock.Mock(swagger_spec=empty_swagger_spec) | ||
event_loop.run_until_complete(unmarshal_response_inner(response, op)) | ||
assert mock_validate_schema_object.call_count == 0 | ||
|
||
|
||
def test_performs_validation( | ||
mock_validate_schema_object, | ||
mock_get_response_spec, | ||
empty_swagger_spec, | ||
response_spec, | ||
event_loop, | ||
): | ||
empty_swagger_spec.config['validate_responses'] = True | ||
response = mock.Mock( | ||
spec=IncomingResponse, | ||
status_code=200, | ||
headers={'content-type': APP_JSON}, | ||
json=coroutine(mock.Mock(return_value='Monday')), | ||
) | ||
|
||
mock_get_response_spec.return_value = response_spec | ||
op = mock.Mock(swagger_spec=empty_swagger_spec) | ||
event_loop.run_until_complete(unmarshal_response_inner(response, op)) | ||
assert mock_validate_schema_object.call_count == 1 |
Oops, something went wrong.