summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_urldispatch.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-06-21 19:54:16 +0000
committerChris McDonough <chrism@agendaless.com>2009-06-21 19:54:16 +0000
commit5e939a9a86f42318f1e92419cec23f49ec5b76f6 (patch)
tree7054a9661dafc3090e713b2939a2b574cadb8b24 /repoze/bfg/tests/test_urldispatch.py
parent588c64277429e144a531704833c40ef8c6bd0007 (diff)
downloadpyramid-5e939a9a86f42318f1e92419cec23f49ec5b76f6.tar.gz
pyramid-5e939a9a86f42318f1e92419cec23f49ec5b76f6.tar.bz2
pyramid-5e939a9a86f42318f1e92419cec23f49ec5b76f6.zip
- Make Routes mapper responsible for doing magic to fix up PATH_INFO
and SCRIPT_NAME when a ``path_info`` key exists in the matchdict. This used to be done in the traverser, which made no sense.
Diffstat (limited to 'repoze/bfg/tests/test_urldispatch.py')
-rw-r--r--repoze/bfg/tests/test_urldispatch.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py
index 68fda032d..eb3be4323 100644
--- a/repoze/bfg/tests/test_urldispatch.py
+++ b/repoze/bfg/tests/test_urldispatch.py
@@ -70,6 +70,54 @@ class RoutesRootFactoryTests(unittest.TestCase):
self.assertEqual(environ['bfg.routes.matchdict'], {})
self.assertEqual(environ['wsgiorg.routing_args'], ((), {}))
+ def test_matches_with_path_info_no_scriptname(self):
+ root_factory = make_get_root(123)
+ mapper = self._makeOne(root_factory)
+ mapper.connect('root', '/a/b/*path_info')
+ environ = self._getEnviron(PATH_INFO='/a/b/c/d')
+ result = mapper(environ)
+ self.assertEqual(result, 123)
+ self.assertEqual(environ['bfg.routes.route'].name, 'root')
+ self.assertEqual(environ['bfg.routes.matchdict'], {'path_info':'c/d'})
+ self.assertEqual(environ['PATH_INFO'], '/c/d')
+ self.assertEqual(environ['SCRIPT_NAME'], '/a/b')
+
+ def test_matches_with_path_info_with_scriptname(self):
+ root_factory = make_get_root(123)
+ mapper = self._makeOne(root_factory)
+ mapper.connect('root', '/a/b/*path_info')
+ environ = self._getEnviron(PATH_INFO='/a/b/c/d', SCRIPT_NAME='z')
+ result = mapper(environ)
+ self.assertEqual(result, 123)
+ self.assertEqual(environ['bfg.routes.route'].name, 'root')
+ self.assertEqual(environ['bfg.routes.matchdict'], {'path_info':'c/d'})
+ self.assertEqual(environ['PATH_INFO'], '/c/d')
+ self.assertEqual(environ['SCRIPT_NAME'], 'z/a/b')
+
+ def test_matches_PATH_INFO_w_extra_slash(self):
+ root_factory = make_get_root(123)
+ mapper = self._makeOne(root_factory)
+ mapper.connect('root', '/a/b/*path_info')
+ environ = self._getEnviron(PATH_INFO='/a/b//c/d', SCRIPT_NAME='')
+ result = mapper(environ)
+ self.assertEqual(result, 123)
+ self.assertEqual(environ['bfg.routes.route'].name, 'root')
+ self.assertEqual(environ['bfg.routes.matchdict'], {'path_info':'/c/d'})
+ self.assertEqual(environ['PATH_INFO'], '/c/d')
+ self.assertEqual(environ['SCRIPT_NAME'], '/a/b')
+
+ def test_matches_SCRIPT_NAME_endswith_slash(self):
+ root_factory = make_get_root(123)
+ mapper = self._makeOne(root_factory)
+ mapper.connect('root', '/a/b//*path_info')
+ environ = self._getEnviron(PATH_INFO='/a/b//c/d', SCRIPT_NAME='')
+ result = mapper(environ)
+ self.assertEqual(result, 123)
+ self.assertEqual(environ['bfg.routes.route'].name, 'root')
+ self.assertEqual(environ['bfg.routes.matchdict'], {'path_info':'c/d'})
+ self.assertEqual(environ['PATH_INFO'], '/c/d')
+ self.assertEqual(environ['SCRIPT_NAME'], '/a/b')
+
def test_unicode_in_route_default(self):
root_factory = make_get_root(123)
mapper = self._makeOne(root_factory)