diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-12-02 21:10:57 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-12-02 21:10:57 +0000 |
| commit | 6a6f6cc370c51f28536cbc1751176a6480ed5f68 (patch) | |
| tree | b8ff09ae7a9119e2f1198245877545186135ed9b /repoze/bfg/tests | |
| parent | 16db57af0922f93026a5b046897acdaa8dd1e602 (diff) | |
| download | pyramid-6a6f6cc370c51f28536cbc1751176a6480ed5f68.tar.gz pyramid-6a6f6cc370c51f28536cbc1751176a6480ed5f68.tar.bz2 pyramid-6a6f6cc370c51f28536cbc1751176a6480ed5f68.zip | |
- 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.
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_configuration.py | 42 |
1 files changed, 42 insertions, 0 deletions
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' |
