summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_urldispatch.py
diff options
context:
space:
mode:
Diffstat (limited to 'repoze/bfg/tests/test_urldispatch.py')
-rw-r--r--repoze/bfg/tests/test_urldispatch.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py
index 99d5d1a98..c7dfdf196 100644
--- a/repoze/bfg/tests/test_urldispatch.py
+++ b/repoze/bfg/tests/test_urldispatch.py
@@ -105,6 +105,45 @@ class RoutesRootFactoryTests(unittest.TestCase):
self.assertEqual(request.matchdict, routing_args)
self.failUnless(req_iface.providedBy(request))
+ def test_route_matches_with_predicates(self):
+ root_factory = DummyRootFactory(123)
+ req_iface = self._registerRouteRequest('foo')
+ mapper = self._makeOne(root_factory)
+ mapper.connect('archives/:action/:article', 'foo',
+ predicates=[lambda *arg: True])
+ request = self._getRequest(PATH_INFO='/archives/action1/article1')
+ result = mapper(request)
+ self.assertEqual(result, 123)
+ environ = request.environ
+ routing_args = environ['wsgiorg.routing_args'][1]
+ self.assertEqual(routing_args['action'], 'action1')
+ self.assertEqual(routing_args['article'], 'article1')
+ self.assertEqual(environ['bfg.routes.matchdict'], routing_args)
+ self.assertEqual(environ['bfg.routes.route'].name, 'foo')
+ self.assertEqual(request.matchdict, routing_args)
+ self.failUnless(req_iface.providedBy(request))
+
+ def test_route_fails_to_match_with_predicates(self):
+ root_factory = DummyRootFactory(123)
+ foo_iface = self._registerRouteRequest('foo')
+ bar_iface = self._registerRouteRequest('bar')
+ mapper = self._makeOne(root_factory)
+ mapper.connect('archives/:action/article1', 'foo',
+ predicates=[lambda *arg: True, lambda *arg: False])
+ mapper.connect('archives/:action/:article', 'bar')
+ request = self._getRequest(PATH_INFO='/archives/action1/article1')
+ result = mapper(request)
+ self.assertEqual(result, 123)
+ environ = request.environ
+ routing_args = environ['wsgiorg.routing_args'][1]
+ self.assertEqual(routing_args['action'], 'action1')
+ self.assertEqual(routing_args['article'], 'article1')
+ self.assertEqual(environ['bfg.routes.matchdict'], routing_args)
+ self.assertEqual(environ['bfg.routes.route'].name, 'bar')
+ self.assertEqual(request.matchdict, routing_args)
+ self.failUnless(bar_iface.providedBy(request))
+ self.failIf(foo_iface.providedBy(request))
+
def test_root_route_matches(self):
root_factory = DummyRootFactory(123)
req_iface = self._registerRouteRequest('root')