summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-09-14 07:55:36 +0000
committerChris McDonough <chrism@agendaless.com>2009-09-14 07:55:36 +0000
commit4eb45e9de657bedeb0b03469781c35758500dfa2 (patch)
tree0d4a7b93f08248425af04dcc38d447c1e25e66ad /repoze/bfg/tests
parent7dbf3ffc6e3d27dbebe3b32ff6d4c97f6a81de92 (diff)
downloadpyramid-4eb45e9de657bedeb0b03469781c35758500dfa2.tar.gz
pyramid-4eb45e9de657bedeb0b03469781c35758500dfa2.tar.bz2
pyramid-4eb45e9de657bedeb0b03469781c35758500dfa2.zip
- A ZCML ``view`` directive (and the associated ``bfg_view``
decorator) can now accept a "wrapper" value. If a "wrapper" value is supplied, it is the value of a separate view's *name* attribute. When a view with a ``wrapper`` attribute is rendered, the "inner" view is first rendered normally. Its body is then attached to the request as "wrapped_body", and then a wrapper view name is looked up and rendered (using ``repoze.bfg.render_view_to_response``), passed the request and the context. The wrapper view is assumed to do something sensible with ``request.wrapped_body``, usually inserting its structure into some other rendered template. This feature makes it possible to specify (potentially nested) "owrap" relationships between views using only ZCML or decorators (as opposed always using ZPT METAL and analogues to wrap view renderings in outer wrappers).
Diffstat (limited to 'repoze/bfg/tests')
-rw-r--r--repoze/bfg/tests/test_zcml.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index e54bd108f..398159801 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -1321,6 +1321,24 @@ class TestDeriveView(unittest.TestCase):
self.assertEqual(next, True)
self.assertEqual(predicates, [True, True])
+ def test_view_with_wrapper_viewname(self):
+ from webob import Response
+ from zope.component import getSiteManager
+ from repoze.bfg.interfaces import IView
+ def inner_view(context, request):
+ return Response('OK')
+ def outer_view(context, request):
+ return Response('outer ' + request.wrapped_body)
+ sm = getSiteManager()
+ sm.registerAdapter(outer_view, (None, None), IView, 'owrap')
+ result = self._callFUT(inner_view, wrapper_viewname='owrap')
+ self.failIf(result is inner_view)
+ self.assertEqual(inner_view.__module__, result.__module__)
+ self.assertEqual(inner_view.__doc__, result.__doc__)
+ request = DummyRequest()
+ response = result(None, request)
+ self.assertEqual(response.body, 'outer OK')
+
class TestConnectRouteFunction(unittest.TestCase):
def setUp(self):
cleanUp()