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

Add guard against adding files to the parameters when no file given #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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_core/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ def add_file(param, value, request):
:param value: The raw content of the file to be uploaded
:type request: dict
"""
if not value:
return

if request.get('files') is None:
# support multiple files by default by setting to an empty array
request['files'] = []
Expand Down
14 changes: 14 additions & 0 deletions tests/param/add_file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
from bravado_core.param import add_file, Param


def test_no_file(empty_swagger_spec):
request = {}
op = Mock(spec=Operation, consumes=['multipart/form-data'])
param_spec = {
'type': 'file',
'in': 'formData',
'name': 'photo'
}
param = Param(empty_swagger_spec, op, param_spec)
add_file(param, None, request)
expected_request = {}
assert expected_request == request


def test_single_file(empty_swagger_spec):
request = {}
file_contents = "I am the contents of a file"
Expand Down