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

Raise TypeError when unknown kwargs are provided to route() #144

Merged
merged 1 commit into from
Oct 24, 2016
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
17 changes: 10 additions & 7 deletions chalice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,20 @@ def _register_view(view_func):
return _register_view

def _add_route(self, path, view_func, **kwargs):
name = kwargs.get('name', view_func.__name__)
methods = kwargs.get('methods', ['GET'])
authorization_type = kwargs.get('authorization_type', None)
authorizer_id = kwargs.get('authorizer_id', None)
api_key_required = kwargs.get('api_key_required', None)
content_types = kwargs.get('content_types', ['application/json'])
cors = kwargs.get('cors', False)
name = kwargs.pop('name', view_func.__name__)
methods = kwargs.pop('methods', ['GET'])
authorization_type = kwargs.pop('authorization_type', None)
authorizer_id = kwargs.pop('authorizer_id', None)
api_key_required = kwargs.pop('api_key_required', None)
content_types = kwargs.pop('content_types', ['application/json'])
cors = kwargs.pop('cors', False)
if not isinstance(content_types, list):
raise ValueError('In view function "%s", the content_types '
'value must be a list, not %s: %s'
% (name, type(content_types), content_types))
if kwargs:
raise TypeError('TypeError: route() got unexpected keyword '
'arguments: %s' % ', '.join(list(kwargs)))

if path in self.routes:
raise ValueError(
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,10 @@ def test_case_insensitive_mapping():
assert mapping.get('hEAdEr')
assert 'hEAdEr' in mapping
assert repr({'header': 'Value'}) in repr(mapping)


def test_unknown_kwargs_raise_error(sample_app):
with pytest.raises(TypeError):
@sample_app.route('/foo', unknown_kwargs='foo')
def badkwargs():
pass