From be6f3b9ae06b31920d90744b20ccb7a8b4d9a278 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 28 Jul 2010 01:26:09 +0000 Subject: - When adding a view for a route which did not yet exist ("did not yet exist" meaning, temporally, a view was added with a route name for a route which had not yet been added via add_route), the value of the ``custom_predicate`` argument to ``add_view`` was lost. Symptom: wrong view matches when using URL dispatch and custom view predicates together. --- CHANGES.txt | 8 ++++++++ repoze/bfg/configuration.py | 3 ++- repoze/bfg/tests/test_configuration.py | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4185d9a65..6cb89f378 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,7 +7,15 @@ Features - The ``repoze.bfg.configuration.Configurator.add_route`` API now returns the route object that was added. +Bug Fixes +--------- +- When adding a view for a route which did not yet exist ("did not yet + exist" meaning, temporally, a view was added with a route name for a + route which had not yet been added via add_route), the value of the + ``custom_predicate`` argument to ``add_view`` was lost. Symptom: + wrong view matches when using URL dispatch and custom view + predicates together. 1.3a6 (2010-07-25) ================== diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index 08f6a6a5c..d11839613 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -839,7 +839,8 @@ class Configurator(object): containment=containment, attr=attr, renderer=renderer, wrapper=wrapper, xhr=xhr, accept=accept, header=header, path_info=path_info, - custom_predicates=(), context=context, _info=u'' + custom_predicates=custom_predicates, context=context, + _info=u'' ) view_info = deferred_views.setdefault(route_name, []) view_info.append(info) diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index a4a30c7e7..b34f6c270 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -1219,6 +1219,17 @@ class ConfiguratorTests(unittest.TestCase): self.failIfEqual(wrapper, None) self.assertEqual(wrapper(None, None), 'OK') + def test_deferred_route_views_retains_custom_predicates(self): + view = lambda *arg: 'OK' + config = self._makeOne() + config.add_view(view=view, route_name='foo', custom_predicates=('123',)) + self.assertEqual(len(config.registry.deferred_route_views), 1) + infos = config.registry.deferred_route_views['foo'] + self.assertEqual(len(infos), 1) + info = infos[0] + self.assertEqual(info['route_name'], 'foo') + self.assertEqual(info['custom_predicates'], ('123',)) + def test_add_view_with_route_name_exception(self): from zope.interface import implementedBy from zope.component import ComponentLookupError -- cgit v1.2.3