diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-11-01 13:50:35 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-11-01 13:50:35 +0000 |
| commit | 8098c05c2cb147683ab072af4459550eab9f1ee6 (patch) | |
| tree | e76a2b43d976cf99f39c24dc33f83780e9d85b30 /repoze | |
| parent | c32af05d5914a85967e01127eb4b1765e43788e9 (diff) | |
| download | pyramid-8098c05c2cb147683ab072af4459550eab9f1ee6.tar.gz pyramid-8098c05c2cb147683ab072af4459550eab9f1ee6.tar.bz2 pyramid-8098c05c2cb147683ab072af4459550eab9f1ee6.zip | |
- 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.
Diffstat (limited to 'repoze')
| -rw-r--r-- | repoze/bfg/tests/test_urldispatch.py | 25 | ||||
| -rw-r--r-- | repoze/bfg/urldispatch.py | 4 |
2 files changed, 26 insertions, 3 deletions
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*)') |
