Added tests for Router's trailing slash handling options
parent
f14b744ef7
commit
f5f7e76dae
|
@ -24,8 +24,6 @@ import functools
|
|||
import milla
|
||||
import re
|
||||
import sys
|
||||
import urllib
|
||||
import urlparse
|
||||
import warnings
|
||||
|
||||
class Router(object):
|
||||
|
@ -99,7 +97,7 @@ class Router(object):
|
|||
for attr in functools.WRAPPER_ASSIGNMENTS:
|
||||
try:
|
||||
value = getattr(controller, attr)
|
||||
except AttributeError:
|
||||
except AttributeError: #pragma: no cover
|
||||
pass
|
||||
else:
|
||||
setattr(func, attr, value)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
:Updater: $Author$
|
||||
'''
|
||||
import milla.dispatch.routing
|
||||
import nose.tools
|
||||
|
||||
def fake_controller():
|
||||
pass
|
||||
|
@ -44,6 +45,7 @@ def test_urlvars():
|
|||
assert func.keywords['bar'] == 'abc'
|
||||
assert func.keywords['baz'] == 'def'
|
||||
|
||||
@nose.tools.raises(milla.dispatch.UnresolvedPath)
|
||||
def test_regexp_urlvar():
|
||||
'''Ensure the dispatcher can resolve alternate regexps in urlvars
|
||||
|
||||
|
@ -61,13 +63,9 @@ def test_regexp_urlvar():
|
|||
assert func.func == controller
|
||||
assert func.keywords['arg'] == 'abcde'
|
||||
|
||||
try:
|
||||
func = router.resolve('/test/1234')
|
||||
except milla.dispatch.UnresolvedPath:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError
|
||||
router.resolve('/test/1234')
|
||||
|
||||
@nose.tools.raises(milla.dispatch.UnresolvedPath)
|
||||
def test_unresolved():
|
||||
'''Ensure the resolver raises an exception for unresolved paths
|
||||
|
||||
|
@ -80,12 +78,7 @@ def test_unresolved():
|
|||
|
||||
router = milla.dispatch.routing.Router()
|
||||
router.add_route('/test', controller)
|
||||
try:
|
||||
router.resolve('/tset')
|
||||
except milla.dispatch.UnresolvedPath:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError
|
||||
router.resolve('/tset')
|
||||
|
||||
def test_unrelated():
|
||||
'''Ensure the dispatcher is not confused by unrelated paths
|
||||
|
@ -119,3 +112,41 @@ def test_string_controller():
|
|||
router.add_route('/test', 'milla.tests.test_routing:fake_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
|
||||
'''
|
||||
|
||||
def controller():
|
||||
pass
|
||||
|
||||
router = milla.dispatch.routing.Router()
|
||||
router.add_route('/test/', controller)
|
||||
func = router.resolve('/test')
|
||||
assert func is not controller
|
||||
func()
|
||||
|
||||
@nose.tools.raises(milla.dispatch.routing.UnresolvedPath)
|
||||
def test_trailing_slash_none():
|
||||
'''Paths that match except the trailing slash are ignored
|
||||
'''
|
||||
|
||||
def controller():
|
||||
pass
|
||||
|
||||
router = milla.dispatch.routing.Router(None)
|
||||
router.add_route('/test/', controller)
|
||||
router.resolve('/test')
|
||||
|
||||
def test_trailing_slash_silent():
|
||||
'''Paths that match except the trailing slash are treated the same
|
||||
'''
|
||||
|
||||
def controller():
|
||||
pass
|
||||
|
||||
router = milla.dispatch.routing.Router(milla.dispatch.routing.Router.SILENT)
|
||||
router.add_route('/test/', controller)
|
||||
func = router.resolve('/test')
|
||||
assert func.func is controller
|
Loading…
Reference in New Issue