Log message for revision 75879:
  Issue #2327:  Don't require wrapped context / view to render template.

Changed:
  U   Products.Five/tags/1.5.2-plus-registerPackage-fix/CHANGES.txt
  U   
Products.Five/tags/1.5.2-plus-registerPackage-fix/browser/pagetemplatefile.py
  U   
Products.Five/tags/1.5.2-plus-registerPackage-fix/browser/tests/test_pages.py

-=-
Modified: Products.Five/tags/1.5.2-plus-registerPackage-fix/CHANGES.txt
===================================================================
--- Products.Five/tags/1.5.2-plus-registerPackage-fix/CHANGES.txt       
2007-05-22 14:46:50 UTC (rev 75878)
+++ Products.Five/tags/1.5.2-plus-registerPackage-fix/CHANGES.txt       
2007-05-22 14:52:00 UTC (rev 75879)
@@ -5,6 +5,10 @@
 Five 1.5.x (svn/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)
+
 * Added change to registerPackage directive so that it stores the newly
   registered packages on the Products package object for faster reference.
   This means code that looks this up (ie Zope2's FactoryDispatcher) no longer

Modified: 
Products.Five/tags/1.5.2-plus-registerPackage-fix/browser/pagetemplatefile.py
===================================================================
--- 
Products.Five/tags/1.5.2-plus-registerPackage-fix/browser/pagetemplatefile.py   
    2007-05-22 14:46:50 UTC (rev 75878)
+++ 
Products.Five/tags/1.5.2-plus-registerPackage-fix/browser/pagetemplatefile.py   
    2007-05-22 14:52:00 UTC (rev 75879)
@@ -17,6 +17,7 @@
 """
 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 @@
         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/tags/1.5.2-plus-registerPackage-fix/browser/tests/test_pages.py
===================================================================
--- 
Products.Five/tags/1.5.2-plus-registerPackage-fix/browser/tests/test_pages.py   
    2007-05-22 14:46:50 UTC (rev 75878)
+++ 
Products.Five/tags/1.5.2-plus-registerPackage-fix/browser/tests/test_pages.py   
    2007-05-22 14:52:00 UTC (rev 75879)
@@ -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()
+    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

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to