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

Fix body validator different error codes for bad Content-Types. #629

Merged
merged 5 commits into from Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion connexion/decorators/validation.py
Expand Up @@ -101,7 +101,8 @@ def wrapper(request):
if all_json(self.consumes):
data = request.json

if data is None and len(request.body) > 0 and not self.is_null_value_valid:
empty_body = len(request.body) == 0 and len(request.form) == 0 and len(request.files) == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not(request.body or request.form or request.files) would be more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it definitely will

if data is None and not empty_body and not self.is_null_value_valid:
try:
ctype_is_json = is_json_mimetype(request.headers.get("Content-Type", ""))
except ValueError:
Expand Down
6 changes: 6 additions & 0 deletions tests/api/test_responses.py
Expand Up @@ -215,6 +215,12 @@ def test_post_wrong_content_type(simple_app):
)
assert resp.status_code == 415

resp = app_client.post('/v1.0/post_wrong_content_type',
content_type="application/x-www-form-urlencoded",
data="a=1&b=2"
)
assert resp.status_code == 415

# this test checks exactly what the test directly above is supposed to check,
# i.e. no content-type is provided in the header
# unfortunately there is an issue with the werkzeug test environment
Expand Down