summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_zcml.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-01-03 03:39:30 +0000
committerChris McDonough <chrism@agendaless.com>2010-01-03 03:39:30 +0000
commiteecdbc34962b00e35d41039af014462cf558acee (patch)
tree784bfdf054d6f4846fb1817d1ba7b01792792dcc /repoze/bfg/tests/test_zcml.py
parent1dff935445ff293a7434f074c1f6bb7304174ec2 (diff)
downloadpyramid-eecdbc34962b00e35d41039af014462cf558acee.tar.gz
pyramid-eecdbc34962b00e35d41039af014462cf558acee.tar.bz2
pyramid-eecdbc34962b00e35d41039af014462cf558acee.zip
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.
Diffstat (limited to 'repoze/bfg/tests/test_zcml.py')
-rw-r--r--repoze/bfg/tests/test_zcml.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index b50f841c2..3cbeb05c8 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -117,6 +117,27 @@ class TestViewDirective(unittest.TestCase):
regview = reg.adapters.lookup((IDummy, IRequest), IView, name='')
self.assertEqual(regview(None, None), 'OK')
+ def test_context_trumps_for(self):
+ from repoze.bfg.threadlocal import get_current_registry
+ from repoze.bfg.interfaces import IView
+ from repoze.bfg.interfaces import IRequest
+ context = DummyContext()
+ reg = get_current_registry()
+ view = lambda *arg: 'OK'
+ class Foo:
+ pass
+ self._callFUT(context, 'repoze.view', for_=Foo, view=view,
+ context=IDummy)
+ actions = context.actions
+ self.assertEqual(len(actions), 1)
+ discrim = ('view', IDummy, '', None, IView, None, None, None, None,
+ None, False, None, None, None)
+ self.assertEqual(actions[0]['discriminator'], discrim)
+ register = actions[0]['callable']
+ register()
+ regview = reg.adapters.lookup((IDummy, IRequest), IView, name='')
+ self.assertEqual(regview(None, None), 'OK')
+
class TestNotFoundDirective(unittest.TestCase):
def setUp(self):
testing.setUp()
@@ -475,6 +496,63 @@ class TestRouteDirective(unittest.TestCase):
wrapped = reg.adapters.lookup((Interface, request_type), IView, name='')
self.failUnless(wrapped)
+ def test_with_view_and_view_context(self):
+ from repoze.bfg.threadlocal import get_current_registry
+ from repoze.bfg.interfaces import IView
+ from repoze.bfg.interfaces import IRouteRequest
+ context = DummyContext()
+ view = lambda *arg: 'OK'
+ self._callFUT(context, 'name', 'path', view=view, view_context=IDummy)
+ actions = context.actions
+ self.assertEqual(len(actions), 2)
+
+ route_action = actions[0]
+ route_action['callable']()
+ route_discriminator = route_action['discriminator']
+ self.assertEqual(route_discriminator,
+ ('route', 'name', False, None, None, None, None,None))
+ self._assertRoute('name', 'path')
+
+ view_action = actions[1]
+ reg = get_current_registry()
+ request_type = reg.getUtility(IRouteRequest, 'name')
+ view_discriminator = view_action['discriminator']
+ discrim = ('view', IDummy, '', request_type, IView, None, None, None,
+ 'name', None, False, None, None, None)
+ self.assertEqual(view_discriminator, discrim)
+ wrapped = reg.adapters.lookup((IDummy, request_type), IView, name='')
+ self.failUnless(wrapped)
+
+ def test_with_view_context_trumps_view_for(self):
+ from repoze.bfg.threadlocal import get_current_registry
+ from repoze.bfg.interfaces import IView
+ from repoze.bfg.interfaces import IRouteRequest
+ context = DummyContext()
+ view = lambda *arg: 'OK'
+ class Foo:
+ pass
+ self._callFUT(context, 'name', 'path', view=view, view_context=IDummy,
+ view_for=Foo)
+ actions = context.actions
+ self.assertEqual(len(actions), 2)
+
+ route_action = actions[0]
+ route_action['callable']()
+ route_discriminator = route_action['discriminator']
+ self.assertEqual(route_discriminator,
+ ('route', 'name', False, None, None, None, None,None))
+ self._assertRoute('name', 'path')
+
+ view_action = actions[1]
+ reg = get_current_registry()
+ request_type = reg.getUtility(IRouteRequest, 'name')
+ view_discriminator = view_action['discriminator']
+ discrim = ('view', IDummy, '', request_type, IView, None, None, None,
+ 'name', None, False, None, None, None)
+ self.assertEqual(view_discriminator, discrim)
+ wrapped = reg.adapters.lookup((IDummy, request_type), IView, name='')
+ self.failUnless(wrapped)
+
def test_with_dotted_renderer(self):
from repoze.bfg.threadlocal import get_current_registry