From 65476e8d2cef6b3ce105c4786645a88151a09a6c Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 1 Nov 2009 00:48:04 +0000 Subject: - The ZCML ``route`` directive's attributes ``xhr``, ``request_method``, ``path_info``, ``request_param``, ``header`` and ``accept`` are now *route* predicates rather than *view* predicates. If one or more of these predicates is specified in the route configuration, all of the predicates must return true for the route to match a request. If one or more of the route predicates associated with a route returns ``False`` when checked during a request, the route match fails, and the next match in the routelist is tried. This differs from the previous behavior, where no route predicates existed and all predicates were considered view predicates, because in that scenario, the next route was not tried. --- repoze/bfg/tests/test_urldispatch.py | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'repoze/bfg/tests/test_urldispatch.py') 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') -- cgit v1.2.3