-
Notifications
You must be signed in to change notification settings - Fork 149
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you really want to accept empty location? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
raise ValueError('%r not in %s' % (location, allowed)) | ||
|
||
self.append(dict( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,17 @@ class TestErrorsHelper(TestCase): | |
def setUp(self): | ||
self.errors = Errors() | ||
|
||
def test_add_to_supported_location(self): | ||
self.errors.add('') | ||
self.errors.add('body', description='!') | ||
self.errors.add('querystring', name='field') | ||
self.errors.add('url') | ||
self.errors.add('header') | ||
self.errors.add('path') | ||
self.errors.add('cookies') | ||
self.errors.add('method') | ||
self.assertEqual(len(self.errors), 8) | ||
|
||
def test_raises_an_exception_when_location_is_unsupported(self): | ||
with self.assertRaises(ValueError): | ||
self.errors.add('something') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add tests for each accepted parameters? |
There was a problem hiding this comment.
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?