Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return binary data for application content types #414

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bravado/http_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ def unmarshal_response_inner(
value=content_value,
)

if content_type.startswith('application'):
return response.raw_bytes

# TODO: Non-json response contents
return response.text

Expand Down
14 changes: 14 additions & 0 deletions tests/http_future/unmarshall_response_inner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ def test_text_content(mock_get_response_spec, empty_swagger_spec, response_spec)
assert 'Monday' == unmarshal_response_inner(response, op)


def test_binary_content(mock_get_response_spec, empty_swagger_spec, response_spec):
response = mock.Mock(
spec=IncomingResponse,
status_code=200,
headers={'content-type': 'application/octet-stream'},
text='Monday',
raw_bytes='SomeBinaryData'
)

mock_get_response_spec.return_value = response_spec
op = mock.Mock(swagger_spec=empty_swagger_spec)
assert 'SomeBinaryData' == unmarshal_response_inner(response, op)


def test_skips_validation(mock_validate_schema_object, mock_get_response_spec, empty_swagger_spec, response_spec):
empty_swagger_spec.config['validate_responses'] = False
response = mock.Mock(
Expand Down