From eecdbc34962b00e35d41039af014462cf558acee Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 3 Jan 2010 03:39:30 +0000 Subject: Features -------- - The ``Configurator.add_view`` method now accepts an argument named ``context``. This is an alias for the older argument named ``for_``; it is preferred over ``for_``, but ``for_`` will continue to be supported "forever". - The ``view`` ZCML directive now accepts an attribute named ``context``. This is an alias for the older attribute named ``for``; it is preferred over ``for``, but ``for`` will continue to be supported "forever". - The ``Configurator.add_route`` method now accepts an argument named ``view_context``. This is an alias for the older argument named ``view_for``; it is preferred over ``view_for``, but ``view_for`` will continue to be supported "forever". - The ``route`` ZCML directive now accepts an attribute named ``view_context``. This is an alias for the older attribute named ``view_for``; it is preferred over ``view_for``, but ``view_for`` will continue to be supported "forever". Documentation and Paster Templates ---------------------------------- - All uses of the ``Configurator.add_view`` method that used its ``for_`` argument now use the ``context``argument instead. - All uses of the ``Configurator.add_route`` method that used its ``view_for`` argument now use the ``view_context``argument instead. - All uses of the ``view`` ZCML directive that used its ``for`` attribute now use the ``context`` attribute instead. - All uses of the ``route`` ZCML directive that used its ``view_for`` attribute now use the ``view_context`` attribute instead. --- repoze/bfg/tests/test_configuration.py | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/tests/test_configuration.py') diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index d8b6aca99..ba306f26b 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -492,7 +492,26 @@ class ConfiguratorTests(unittest.TestCase): result = wrapper(None, None) self.assertEqual(result, 'OK') + def test_add_view_context_as_class(self): + from zope.interface import implementedBy + view = lambda *arg: 'OK' + class Foo: + pass + config = self._makeOne() + config.add_view(context=Foo, view=view) + foo = implementedBy(Foo) + wrapper = self._getViewCallable(config, foo) + self.assertEqual(wrapper, view) + + def test_add_view_context_as_iface(self): + view = lambda *arg: 'OK' + config = self._makeOne() + config.add_view(context=IDummy, view=view) + wrapper = self._getViewCallable(config, IDummy) + self.assertEqual(wrapper, view) + def test_add_view_for_as_class(self): + # ``for_`` is older spelling for ``context`` from zope.interface import implementedBy view = lambda *arg: 'OK' class Foo: @@ -504,12 +523,23 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(wrapper, view) def test_add_view_for_as_iface(self): + # ``for_`` is older spelling for ``context`` view = lambda *arg: 'OK' config = self._makeOne() config.add_view(for_=IDummy, view=view) wrapper = self._getViewCallable(config, IDummy) self.assertEqual(wrapper, view) + def test_add_view_context_trumps_for(self): + # ``for_`` is older spelling for ``context`` + view = lambda *arg: 'OK' + config = self._makeOne() + class Foo: + pass + config.add_view(context=IDummy, for_=Foo, view=view) + wrapper = self._getViewCallable(config, IDummy) + self.assertEqual(wrapper, view) + def test_add_view_register_secured_view(self): from zope.interface import Interface from repoze.bfg.interfaces import IRequest @@ -1091,6 +1121,17 @@ class ConfiguratorTests(unittest.TestCase): self.assertEqual(wrapper(None, None), 'OK') self._assertRoute(config, 'name', 'path') + def test_add_route_with_view_context(self): + config = self._makeOne() + view = lambda *arg: 'OK' + config.add_route('name', 'path', view=view, view_context=IDummy) + request_type = self._getRouteRequestIface(config, 'name') + wrapper = self._getViewCallable(config, IDummy, request_type) + self.assertEqual(wrapper(None, None), 'OK') + self._assertRoute(config, 'name', 'path') + wrapper = self._getViewCallable(config, IOther, request_type) + self.assertEqual(wrapper, None) + def test_add_route_with_view_for(self): config = self._makeOne() view = lambda *arg: 'OK' @@ -1102,7 +1143,7 @@ class ConfiguratorTests(unittest.TestCase): wrapper = self._getViewCallable(config, IOther, request_type) self.assertEqual(wrapper, None) - def test_add_route_with_view_for_alias(self): + def test_add_route_with_for_(self): config = self._makeOne() view = lambda *arg: 'OK' config.add_route('name', 'path', view=view, for_=IDummy) -- cgit v1.2.3