Permalink
Browse files

Save the args and kwargs the view receives to the view instance

  • Loading branch information...
1 parent 0d2e0c2 commit ab710a9796e55ae30aef6adb1a54aae6a45a6d84 @jpvanhal jpvanhal committed Mar 30, 2012
Showing with 15 additions and 0 deletions.
  1. +5 −0 flask_generic_views/core.py
  2. +10 −0 tests/unit/test_core.py
@@ -17,6 +17,11 @@ def __init__(self, **kwargs):
for key, value in kwargs.iteritems():
setattr(self, key, value)
+ def dispatch_request(self, *args, **kwargs):
+ self.args = args
+ self.kwargs = kwargs
+ return super(BaseView, self).dispatch_request(*args, **kwargs)
+
class TemplateView(BaseView):
"""Render a given template."""
@@ -19,6 +19,16 @@ def test_constructor_saves_kwargs_to_the_view(self):
view = BaseView(foo='bar')
assert view.foo == 'bar'
+ def test_saves_arguments_and_keywords_arguments_to_the_instance(self):
+ (flexmock(MethodView)
+ .should_receive('dispatch_request')
+ .with_args('foo', bar='xyzzy')
+ .and_return('dispatch_request'))
+ view = BaseView()
+ view.dispatch_request('foo', bar='xyzzy')
+ assert view.args == ('foo',)
+ assert view.kwargs == {'bar': 'xyzzy'}
+
class TestTemplateView(object):
def test_responds_to_get_requests(self):

0 comments on commit ab710a9

Please sign in to comment.