Exemplo n.º 1
0
class TestRoutingArgs(object):
    """Tests for the wsgiorg.routing_args middleware."""
    def setup(self):
        self.mw = RoutingArgsMiddleware()
        self.request = MockRequest({})

    def test_arguments_are_stored(self):
        """The positional and named arguments should be stored in the environ"""
        args = ("foo", "bar")
        kwargs = {'arg': "value"}
        self.mw.process_view(self.request, MOCK_VIEW, args, kwargs)
        ok_("wsgiorg.routing_args" in self.request.environ)
        eq_(len(self.request.environ['wsgiorg.routing_args']), 2)
        eq_(self.request.environ['wsgiorg.routing_args'][0], args)
        eq_(self.request.environ['wsgiorg.routing_args'][1], kwargs)

    def test_named_arguments_are_copied(self):
        """
        The named arguments must be copied, not passed by reference.
        
        Because Django will pass them on without inspecting the arguments for
        the view, unlike other frameworks like Pylons.
        
        """
        kwargs = {'arg': "value"}
        self.mw.process_view(self.request, MOCK_VIEW, ("foo", "bar"), kwargs)
        self.request.environ['wsgiorg.routing_args'][1][
            'new_arg'] = "new_value"
        # The original dictionary must have not been modified:
        eq_(len(kwargs), 1)
        ok_("arg" in kwargs)

    def test_no_response(self):
        """A response should never be returned."""
        args = ("foo", "bar")
        kwargs = {'arg': "value"}
        result = self.mw.process_view(self.request, MOCK_VIEW, args, kwargs)
        ok_(result is None)
Exemplo n.º 2
0
class TestRoutingArgs(object):
    """Tests for the wsgiorg.routing_args middleware."""
    
    def setup(self):
        self.mw = RoutingArgsMiddleware()
        self.request = MockRequest({})
    
    def test_arguments_are_stored(self):
        """The positional and named arguments should be stored in the environ"""
        args = ("foo", "bar")
        kwargs = {'arg': "value"}
        self.mw.process_view(self.request, MOCK_VIEW, args, kwargs)
        ok_("wsgiorg.routing_args" in self.request.environ)
        eq_(len(self.request.environ['wsgiorg.routing_args']), 2)
        eq_(self.request.environ['wsgiorg.routing_args'][0], args)
        eq_(self.request.environ['wsgiorg.routing_args'][1], kwargs)
    
    def test_named_arguments_are_copied(self):
        """
        The named arguments must be copied, not passed by reference.
        
        Because Django will pass them on without inspecting the arguments for
        the view, unlike other frameworks like Pylons.
        
        """
        kwargs = {'arg': "value"}
        self.mw.process_view(self.request, MOCK_VIEW, ("foo", "bar"), kwargs)
        self.request.environ['wsgiorg.routing_args'][1]['new_arg'] = "new_value"
        # The original dictionary must have not been modified:
        eq_(len(kwargs), 1)
        ok_("arg" in kwargs)
    
    def test_no_response(self):
        """A response should never be returned."""
        args = ("foo", "bar")
        kwargs = {'arg': "value"}
        result = self.mw.process_view(self.request, MOCK_VIEW, args, kwargs)
        ok_(result is None)
Exemplo n.º 3
0
 def setup(self):
     self.mw = RoutingArgsMiddleware()
     self.request = MockRequest({})
Exemplo n.º 4
0
 def setup(self):
     self.mw = RoutingArgsMiddleware()
     self.request = MockRequest({})