[Zope-Checkins] SVN: Products.Five/branches/1.3/ Issue #2327: Don't
require wrapped context / view to render template.
Tres Seaver
tseaver at palladion.com
Tue May 22 10:40:05 EDT 2007
Log message for revision 75874:
Issue #2327: Don't require wrapped context / view to render template.
Changed:
U Products.Five/branches/1.3/CHANGES.txt
U Products.Five/branches/1.3/browser/pagetemplatefile.py
U Products.Five/branches/1.3/browser/tests/test_pages.py
-=-
Modified: Products.Five/branches/1.3/CHANGES.txt
===================================================================
--- Products.Five/branches/1.3/CHANGES.txt 2007-05-22 14:39:35 UTC (rev 75873)
+++ Products.Five/branches/1.3/CHANGES.txt 2007-05-22 14:40:05 UTC (rev 75874)
@@ -5,6 +5,10 @@
Five 1.3.9 (unreleased)
=======================
+* Relaxed requirements for context of browser.pagetemplatefile's
+ ZopeTwoPageTemplateFile, to reduce barriers for testing renderability
+ of views which use them. (http://www.zope.org/Collectors/Zope/2327)
+
* View methods which aren't explicitly declared as allowed must be marked
private explicitly to avoid being web publishable.
Modified: Products.Five/branches/1.3/browser/pagetemplatefile.py
===================================================================
--- Products.Five/branches/1.3/browser/pagetemplatefile.py 2007-05-22 14:39:35 UTC (rev 75873)
+++ Products.Five/branches/1.3/browser/pagetemplatefile.py 2007-05-22 14:40:05 UTC (rev 75874)
@@ -17,6 +17,7 @@
"""
import os, sys
+from Acquisition import aq_inner
from Globals import package_home
from AccessControl import getSecurityManager
from Shared.DC.Scripts.Bindings import Unauthorized, UnauthorizedBinding
@@ -67,14 +68,18 @@
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,
Modified: Products.Five/branches/1.3/browser/tests/test_pages.py
===================================================================
--- Products.Five/branches/1.3/browser/tests/test_pages.py 2007-05-22 14:39:35 UTC (rev 75873)
+++ Products.Five/branches/1.3/browser/tests/test_pages.py 2007-05-22 14:40:05 UTC (rev 75874)
@@ -26,8 +26,8 @@
>>> 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 @@
>>> 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()
+ '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
More information about the Zope-Checkins
mailing list