From 8098c05c2cb147683ab072af4459550eab9f1ee6 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 1 Nov 2009 13:50:35 +0000 Subject: - The routes root factory called route factories and the default route factory with an environ rather than a request. One of the symptoms of this bug: applications generated using the ``bfg_zodb`` paster template in 1.1a9 did not work properly. --- CHANGES.txt | 8 ++++++++ repoze/bfg/tests/test_urldispatch.py | 25 ++++++++++++++++++++++++- repoze/bfg/urldispatch.py | 4 ++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8e291b9f3..72f6c5d6b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,14 @@ Next release ============ +Bug Fixes +--------- + +- The routes root factory called route factories and the default route + factory with an environ rather than a request. One of the symptoms + of this bug: applications generated using the ``bfg_zodb`` paster + template in 1.1a9 did not work properly. + Internal -------- diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py index c7dfdf196..83e908994 100644 --- a/repoze/bfg/tests/test_urldispatch.py +++ b/repoze/bfg/tests/test_urldispatch.py @@ -87,6 +87,7 @@ class RoutesRootFactoryTests(unittest.TestCase): request = self._getRequest(PATH_INFO='/') result = mapper(request.environ) self.assertEqual(result, 123) + self.assertEqual(root_factory.request, request.environ) def test_route_matches(self): root_factory = DummyRootFactory(123) @@ -105,6 +106,25 @@ class RoutesRootFactoryTests(unittest.TestCase): self.assertEqual(request.matchdict, routing_args) self.failUnless(req_iface.providedBy(request)) + def test_route_matches_and_has_factory(self): + root_factory = DummyRootFactory(123) + req_iface = self._registerRouteRequest('foo') + mapper = self._makeOne(root_factory) + factory = DummyRootFactory(456) + mapper.connect('archives/:action/:article', 'foo', factory) + request = self._getRequest(PATH_INFO='/archives/action1/article1') + result = mapper(request) + self.assertEqual(result, 456) + self.assertEqual(factory.request, request) + 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_matches_with_predicates(self): root_factory = DummyRootFactory(123) req_iface = self._registerRouteRequest('foo') @@ -181,6 +201,7 @@ class RoutesRootFactoryTests(unittest.TestCase): request = self._getRequest(PATH_INFO='/archives/action1/article1') result = mapper(request) self.assertEqual(result, 123) + self.assertEqual(root_factory.request, request) def test_no_path_info(self): root_factory = DummyRootFactory(123) @@ -189,6 +210,7 @@ class RoutesRootFactoryTests(unittest.TestCase): request = self._getRequest() result = mapper(request) self.assertEqual(result, 123) + self.assertEqual(root_factory.request, request) def test_has_routes(self): mapper = self._makeOne(None) @@ -295,7 +317,8 @@ class TestCompileRouteMatchFunctional(unittest.TestCase): class DummyRootFactory(object): def __init__(self, result): self.result = result - def __call__(self, environ): + def __call__(self, request): + self.request = request return self.result class DummyContext(object): diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py index 185baa1a1..715fb07e4 100644 --- a/repoze/bfg/urldispatch.py +++ b/repoze/bfg/urldispatch.py @@ -82,9 +82,9 @@ class RoutesRootFactory(object): if iface is not None: directlyProvides(request, iface) factory = route.factory or self.default_root_factory - return factory(environ) + return factory(request) - return self.default_root_factory(environ) + return self.default_root_factory(request) # stolen from bobo and modified route_re = re.compile(r'(/:[a-zA-Z]\w*)') -- cgit v1.2.3