From 6a6f6cc370c51f28536cbc1751176a6480ed5f68 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 2 Dec 2009 21:10:57 +0000 Subject: - When two views were registered with differering ``for`` interfaces or classes, and the ``for`` of first view registered was a superclass of the second, the ``repoze.bfg` view machinery would incorrectly associate the two views with the same "multiview". Multiviews are meant to be collections of views that have *exactly* the same for/request/viewname values, without taking inheritance into account. Symptom: wrong view callable found even when you had correctly specified a ``for_`` interface/class during view configuration for one or both view configurations. --- repoze/bfg/tests/test_configuration.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'repoze/bfg/tests') diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index 43d2cb153..da2f1d2c4 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -547,6 +547,48 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(wrapper.views, [(view2, None)]) self.assertEqual(wrapper(None, None), 'OK1') + def test_add_view_multiview_context_superclass_then_subclass(self): + from zope.interface import Interface + from repoze.bfg.interfaces import IRequest + from repoze.bfg.interfaces import IView + from repoze.bfg.interfaces import IMultiView + class ISuper(Interface): + pass + class ISub(ISuper): + pass + view = lambda *arg: 'OK' + view2 = lambda *arg: 'OK2' + config = self._makeOne() + config.registry.registerAdapter( + view, (ISuper, IRequest), IView, name='') + config.add_view(view=view2, for_=ISub) + wrapper = self._getViewCallable(config, ISuper, IRequest) + self.failIf(IMultiView.providedBy(wrapper)) + self.assertEqual(wrapper(None, None), 'OK') + wrapper = self._getViewCallable(config, ISub, IRequest) + self.failIf(IMultiView.providedBy(wrapper)) + self.assertEqual(wrapper(None, None), 'OK2') + + def test_add_view_multiview_request_superclass_then_subclass(self): + from zope.interface import Interface + from repoze.bfg.interfaces import IRequest + from repoze.bfg.interfaces import IView + from repoze.bfg.interfaces import IMultiView + class ISubRequest(IRequest): + pass + view = lambda *arg: 'OK' + view2 = lambda *arg: 'OK2' + config = self._makeOne() + config.registry.registerAdapter( + view, (Interface, IRequest), IView, name='') + config.add_view(view=view2, request_type=ISubRequest) + wrapper = self._getViewCallable(config, Interface, IRequest) + self.failIf(IMultiView.providedBy(wrapper)) + self.assertEqual(wrapper(None, None), 'OK') + wrapper = self._getViewCallable(config, Interface, ISubRequest) + self.failIf(IMultiView.providedBy(wrapper)) + self.assertEqual(wrapper(None, None), 'OK2') + def test_add_view_multiview_call_ordering(self): from zope.interface import directlyProvides def view1(context, request): return 'view1' -- cgit v1.2.3