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

Only accept known locations in request.errors.add() (fixes #99) #374

Merged
merged 2 commits into from
Oct 19, 2016

Conversation

leplatrem
Copy link
Contributor

If this conflicts with your PR @tarekziade, do not take it into account, I'll rebase it later.
r?

@leplatrem
Copy link
Contributor Author

From what I see in #376, it should probably also support cookie, path, method

@leplatrem
Copy link
Contributor Author

@Natim r?

Copy link
Contributor

@Natim Natim left a comment

Choose a reason for hiding this comment

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

Apparently this tests need to be fixed: test_validated_querystring_and_schema_from_same_schema (cornice.tests.test_validation.TestServiceDefinition)


def test_raises_an_exception_when_location_is_unsupported(self):
with self.assertRaises(ValueError):
self.errors.add('something')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add tests for each accepted parameters?

@@ -18,7 +18,7 @@ def add(self, location, name=None, description=None, **kw):
"""Registers a new error."""
allowed = ('body', 'querystring', 'url', 'header', 'path',
'cookies', 'method')
if location not in allowed:
if location != '' and location not in allowed:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really want to accept empty location?

@@ -16,6 +16,11 @@ def __init__(self, status=400):

def add(self, location, name=None, description=None, **kw):
"""Registers a new error."""
allowed = ('body', 'querystring', 'url', 'header', 'path',
'cookies', 'method')
if location != '' and location not in allowed:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really want to accept empty location?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what colander gives when you raise a validation error that is not related to a specific node (eg. provide param either via header or querystring)

@leplatrem leplatrem merged commit b99e186 into master Oct 19, 2016
@leplatrem leplatrem deleted the 99-check-errors-location branch October 19, 2016 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants