summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_urldispatch.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-04-16 20:31:40 +0000
committerChris McDonough <chrism@agendaless.com>2009-04-16 20:31:40 +0000
commitd1209e077a1607440677a363651bda4393d72d82 (patch)
tree90a202a00438645d1624445cf7c34f8a73a4a46a /repoze/bfg/tests/test_urldispatch.py
parent168c10641aecba898616c01a25091b745362e366 (diff)
downloadpyramid-d1209e077a1607440677a363651bda4393d72d82.tar.gz
pyramid-d1209e077a1607440677a363651bda4393d72d82.tar.bz2
pyramid-d1209e077a1607440677a363651bda4393d72d82.zip
- The interface for ``repoze.bfg.interfaces.ITraverser`` and the
built-in implementations that implement the interface (``repoze.bfg.traversal.ModelGraphTraverser``, and ``repoze.bfg.urldispatch.RoutesModelTraverser``) now expect the ``__call__`` method of an ITraverser to return 3 additional arguments: ``traversed``, ``virtual_root``, and ``virtual_root_path`` (the old contract was that the ``__call__`` method of an ITraverser returned; three arguments, the contract new is that it returns six). ``traversed`` will be a sequence of Unicode names that were traversed (including the virtual root path, if any) or ``None`` if no traversal was performed, ``virtual_root`` will be a model object representing the virtual root (or the physical root if traversal was not performed), and ``virtual_root_path`` will be a sequence representing the virtual root path (a sequence of Unicode names) or ``None`` if traversal was not performed. Six arguments are now returned from BFG ITraversers. They are returned in this order: ``context``, ``view_name``, ``subpath``, ``traversed``, ``virtual_root``, and ``virtual_root_path``. Places in the BFG code which called an ITraverser continue to accept a 3-argument return value, although BFG will generate and log a warning when one is encountered. - The request object now has the following attributes: ``traversed`` (the sequence of names traversed or ``None`` if traversal was not performed), ``virtual_root`` (the model object representing the virtual root, including the virtual root path if any), and ``virtual_root_path`` (the seuquence of names representing the virtual root path or ``None`` if traversal was not performed). - A new decorator named ``wsgiapp2`` was added to the ``repoze.bfg.wsgi`` module. This decorator performs the same function as ``repoze.bfg.wsgi.wsgiapp`` except it fixes up the ``SCRIPT_NAME``, and ``PATH_INFO`` environment values before invoking the WSGI subapplication. - The ``repoze.bfg.testing.DummyRequest`` object now has default attributes for ``traversed``, ``virtual_root``, and ``virtual_root_path``. - The RoutesModelTraverser now behaves more like the Routes "RoutesMiddleware" object when an element in the match dict is named ``path_info`` (usually when there's a pattern like ``http://foo/*path_info``). When this is the case, the ``PATH_INFO`` environment variable is set to the value in the match dict, and the ``SCRIPT_NAME`` is appended to with the prefix of the original ``PATH_INFO`` not including the value of the new variable. - The notfound debug now shows the traversed path, the virtual root, and the virtual root path too.
Diffstat (limited to 'repoze/bfg/tests/test_urldispatch.py')
-rw-r--r--repoze/bfg/tests/test_urldispatch.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py
index 0fc828161..fec394d56 100644
--- a/repoze/bfg/tests/test_urldispatch.py
+++ b/repoze/bfg/tests/test_urldispatch.py
@@ -248,6 +248,9 @@ class RoutesModelTraverserTests(unittest.TestCase):
self.assertEqual(result[0], model)
self.assertEqual(result[1], 'controller')
self.assertEqual(result[2], [])
+ self.assertEqual(result[3], None)
+ self.assertEqual(result[4], model)
+ self.assertEqual(result[5], None)
def test_call_with_only_view_name_bwcompat(self):
model = DummyContext()
@@ -257,6 +260,9 @@ class RoutesModelTraverserTests(unittest.TestCase):
self.assertEqual(result[0], model)
self.assertEqual(result[1], 'view_name')
self.assertEqual(result[2], [])
+ self.assertEqual(result[3], None)
+ self.assertEqual(result[4], model)
+ self.assertEqual(result[5], None)
def test_call_with_subpath_bwcompat(self):
model = DummyContext()
@@ -267,6 +273,9 @@ class RoutesModelTraverserTests(unittest.TestCase):
self.assertEqual(result[0], model)
self.assertEqual(result[1], 'view_name')
self.assertEqual(result[2], ['a', 'b', 'c'])
+ self.assertEqual(result[3], None)
+ self.assertEqual(result[4], model)
+ self.assertEqual(result[5], None)
def test_call_with_no_view_name_or_controller_bwcompat(self):
model = DummyContext()
@@ -275,6 +284,9 @@ class RoutesModelTraverserTests(unittest.TestCase):
self.assertEqual(result[0], model)
self.assertEqual(result[1], '')
self.assertEqual(result[2], [])
+ self.assertEqual(result[3], None)
+ self.assertEqual(result[4], model)
+ self.assertEqual(result[5], None)
def test_call_with_only_view_name(self):
model = DummyContext()
@@ -285,6 +297,9 @@ class RoutesModelTraverserTests(unittest.TestCase):
self.assertEqual(result[0], model)
self.assertEqual(result[1], 'view_name')
self.assertEqual(result[2], [])
+ self.assertEqual(result[3], None)
+ self.assertEqual(result[4], model)
+ self.assertEqual(result[5], None)
def test_call_with_view_name_and_subpath(self):
model = DummyContext()
@@ -295,6 +310,25 @@ class RoutesModelTraverserTests(unittest.TestCase):
self.assertEqual(result[0], model)
self.assertEqual(result[1], 'view_name')
self.assertEqual(result[2], ['a', 'b','c'])
+ self.assertEqual(result[3], None)
+ self.assertEqual(result[4], model)
+ self.assertEqual(result[5], None)
+
+ def test_with_path_info(self):
+ model = DummyContext()
+ traverser = self._makeOne(model)
+ routing_args = ((), {'view_name':'view_name', 'path_info':'foo/bar'})
+ environ = {'wsgiorg.routing_args': routing_args,
+ 'PATH_INFO':'/a/b/foo/bar', 'SCRIPT_NAME':''}
+ result = traverser(environ)
+ self.assertEqual(result[0], model)
+ self.assertEqual(result[1], 'view_name')
+ self.assertEqual(result[2], [])
+ self.assertEqual(result[3], None)
+ self.assertEqual(result[4], model)
+ self.assertEqual(result[5], None)
+ self.assertEqual(environ['PATH_INFO'], '/foo/bar')
+ self.assertEqual(environ['SCRIPT_NAME'], '/a/b')
class RoutesContextURLTests(unittest.TestCase):
def _getTargetClass(self):