Commit f4783984 authored by Tres Seaver's avatar Tres Seaver

Issue #2327: Don't require wrapped context / view to render template.

parent 34404140
......@@ -97,6 +97,11 @@ Zope Changes
Bugs Fixed
- Relaxed requirements for context of
Products.Five.browser.pagetemplatefile.ZopeTwoPageTemplateFile,
to reduce barriers for testing renderability of views which use them.
(http://www.zope.org/Collectors/Zope/2327)
- Collector #2304: fixed markup issue in ptEdit.zpt
- Collector #2260: fixed bug in Examples package
......
......@@ -17,6 +17,7 @@ $Id$
"""
import os, sys
from Acquisition import aq_inner
from Globals import package_home
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PageTemplates.Expressions import SecureModuleImporter
......@@ -65,14 +66,18 @@ class ZopeTwoPageTemplateFile(PageTemplateFile):
try:
root = self.getPhysicalRoot()
except AttributeError:
root = self.context.getPhysicalRoot()
try:
root = self.context.getPhysicalRoot()
except AttributeError:
root = None
# Even if the context isn't a view (when would that be exaclty?),
# there shouldn't be any dange in applying a view, because it
# won't be used. However assuming that a lack of getPhysicalRoot
# implies a missing view causes problems.
view = self._getContext()
here = self.context.aq_inner
here = aq_inner(self.context)
request = getattr(root, 'REQUEST', None)
c = {'template': self,
......
......@@ -26,8 +26,8 @@ def test_ViewAcquisitionWrapping():
>>> zcml.load_config("configure.zcml", Products.Five)
>>> zcml.load_config('pages.zcml', package=Products.Five.browser.tests)
>>> from Products.Five.tests.testing.simplecontent import manage_addSimpleContent
>>> manage_addSimpleContent(self.folder, 'testoid', 'Testoid')
>>> from Products.Five.tests.testing import simplecontent as sc
>>> sc.manage_addSimpleContent(self.folder, 'testoid', 'Testoid')
>>> uf = self.folder.acl_users
>>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
>>> self.login('manager')
......@@ -60,6 +60,54 @@ def test_ViewAcquisitionWrapping():
>>> tearDown()
"""
def test_view_with_unwrapped_context():
"""
It may be desirable when writing tests for views themselves to
provide dummy contexts which are not wrapped.
>>> import Products.Five.browser.tests
>>> from Products.Five import zcml
>>> zcml.load_config("configure.zcml", Products.Five)
>>> zcml.load_config('pages.zcml', package=Products.Five.browser.tests)
>>> from Products.Five.tests.testing import simplecontent as sc
>>> from zope.interface import Interface
>>> from zope.interface import implements
>>> from zope.component import queryMultiAdapter
>>> class Unwrapped:
... implements(sc.ISimpleContent)
>>> unwrapped = Unwrapped()
Simple views should work fine without having their contexts wrapped:
>>> eagle = queryMultiAdapter((unwrapped, self.app.REQUEST),
... Interface, 'eagle.txt')
>>> eagle is not None
True
>>> from Products.Five.browser.tests.pages import SimpleView
>>> isinstance(eagle, SimpleView)
True
>>> eagle()
u'The eagle has landed'
We also want to be able to render the file-based ZPT without requiring
that the context be wrapped:
>>> falcon = queryMultiAdapter((unwrapped, self.app.REQUEST),
... Interface, 'falcon.html')
>>> falcon is not None
True
>>> from Products.Five.browser.tests.pages import SimpleView
>>> isinstance(falcon, SimpleView)
True
>>> print falcon()
<p>The falcon has taken flight</p>
Clean up:
>>> from zope.app.testing.placelesssetup import tearDown
>>> tearDown()
"""
def test_suite():
import unittest
from Testing.ZopeTestCase import installProduct, ZopeDocTestSuite
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment