diff --git a/src/milla/dispatch/routing.py b/src/milla/dispatch/routing.py index 239ead7..433e798 100644 --- a/src/milla/dispatch/routing.py +++ b/src/milla/dispatch/routing.py @@ -1,4 +1,4 @@ -# Copyright 2011 Dustin C. Hatch +# Copyright 2011, 2012, 2015 Dustin C. Hatch # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -121,8 +121,9 @@ class Router(object): # Return a dummy function that just raises # HTTPMovedPermanently to redirect the client to # the canonical URL - def redir(*args, **kwargs): - raise milla.HTTPMovedPermanently(location=new_path_info) + def redir(request, *args, **kwargs): + raise milla.HTTPMovedPermanently( + location=request.create_href(new_path_info)) return redir elif func and self.trailing_slash is Router.SILENT: # Return the function found at the alternate path diff --git a/src/milla/tests/test_routing.py b/src/milla/tests/test_routing.py index 0f46590..01a6ba4 100644 --- a/src/milla/tests/test_routing.py +++ b/src/milla/tests/test_routing.py @@ -113,7 +113,6 @@ def test_string_controller(): func = router.resolve('/test') assert func.func == fake_controller -@nose.tools.raises(milla.HTTPMovedPermanently) def test_trailing_slash_redir(): '''Paths that match except the trailing slash return a HTTP redirect ''' @@ -125,7 +124,12 @@ def test_trailing_slash_redir(): router.add_route('/test/', controller) func = router.resolve('/test') assert func is not controller - func() + try: + func(milla.Request.blank('/test')) + except milla.HTTPMovedPermanently as e: + assert e.location == '/test/' + else: + raise AssertionError('Redirect not raised') @nose.tools.raises(milla.dispatch.routing.UnresolvedPath) def test_trailing_slash_none():