[Checkins] SVN: Zope/branches/philikon-aq/lib/python/Products/Five/browser/ Some legacy tests. And a (disabled) failing one that tests the __of__

Philipp von Weitershausen philikon at philikon.de
Mon Jul 30 18:02:15 EDT 2007


Log message for revision 78489:
  Some legacy tests.  And a (disabled) failing one that tests the __of__
  behaviour of BrowserView.  Well, when I say failing I should really say
  segfaulting :/
  

Changed:
  U   Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py
  A   Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
  A   Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml
  A   Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
  U   Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/test_pages.py

-=-
Modified: Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py	2007-07-30 21:58:11 UTC (rev 78488)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py	2007-07-30 22:02:14 UTC (rev 78489)
@@ -15,18 +15,21 @@
 
 $Id$
 """
-
+import Acquisition
 import zope.publisher.browser
 
-from Acquisition import aq_chain
-from Acquisition import aq_inner
-
 class BrowserView(zope.publisher.browser.BrowserView):
 
     # BBB for code that expects BrowserView to still inherit from
     # Acquisition.Explicit.
 
     def __of__(self, context):
+        # Technically this isn't in line with the way Acquisition's
+        # __of__ works.  With Acquisition, you get a wrapper around
+        # the original object and only that wrapper's parent is the
+        # new context.  Here we change the original object.
+        #self.__parent__ = context  # ugh. segfault!
+
         return self
 
     # XXX Classes which are still based on Acquisition and access
@@ -34,7 +37,7 @@
     # aq_chain. We do this here for BBB friendly purposes.
 
     def __getParent(self):
-        return getattr(self, '_parent', aq_inner(self.context))
+        return getattr(self, '_parent', Acquisition.aq_inner(self.context))
 
     def __setParent(self, parent):
         self._parent = parent
@@ -43,12 +46,8 @@
 
     # We provide the aq_* properties here for BBB
 
-    @property
-    def aq_base(self):
-        return self
+    aq_self = aq_inner = aq_base = property(lambda self: self)
 
-    aq_self = aq_inner = aq_base
-
     @property
     def aq_chain(self):
-        return aq_chain(self)
+        return Acquisition.aq_chain(self)

Added: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py	                        (rev 0)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py	2007-07-30 22:02:14 UTC (rev 78489)
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Legacy browser view tests.
+
+Here we nake sure that legacy implementations of views (e.g. those
+which mix-in one of the Acquisition base classes without knowing
+better) still work.
+"""
+import Acquisition
+from Products.Five import BrowserView
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+
+class LegacyAttributes(BrowserView):
+    """Make sure that accessing those old aq_* attributes on Five
+    BrowserViews still works, even though BrowserView may not be an
+    Acquisition-decendant class anymore...
+    """
+
+    def __call__(self):
+        assert self.aq_parent == self.context
+        assert self.aq_inner == self
+        assert self.aq_base == self
+        assert self.aq_self == self
+        return repr([obj for obj in self.aq_chain])
+
+class Explicit(Acquisition.Explicit):
+
+    def render(self):
+        return 'Explicit'
+
+class ExplicitWithTemplate(Acquisition.Explicit):
+
+    template = ViewPageTemplateFile('falcon.pt')
+
+class Implicit(Acquisition.Implicit):
+
+    def render(self):
+        return 'Implicit'
+
+class ImplicitWithTemplate(Acquisition.Implicit):
+
+    template = ViewPageTemplateFile('falcon.pt')


Property changes on: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml
===================================================================
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml	                        (rev 0)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml	2007-07-30 22:02:14 UTC (rev 78489)
@@ -0,0 +1,60 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:browser="http://namespaces.zope.org/browser">
+
+  <browser:page
+      for="*"
+      name="attributes"
+      class=".aqlegacy.LegacyAttributes"
+      permission="zope.Public"
+      />
+
+  <browser:page
+      for="*"
+      name="explicit"
+      class=".aqlegacy.Explicit"
+      attribute="render"
+      permission="zope.Public"
+      />
+
+  <browser:page
+      for="*"
+      name="explicit_zcmltemplate"
+      class=".aqlegacy.Explicit"
+      template="falcon.pt"
+      permission="zope.Public"
+      />
+
+  <browser:page
+      for="*"
+      name="explicit_template"
+      class=".aqlegacy.ExplicitWithTemplate"
+      attribute="template"
+      permission="zope.Public"
+      />
+
+  <browser:page
+      for="*"
+      name="implicit"
+      class=".aqlegacy.Implicit"
+      attribute="render"
+      permission="zope.Public"
+      />
+
+  <browser:page
+      for="*"
+      name="implicit_template"
+      class=".aqlegacy.ImplicitWithTemplate"
+      attribute="template"
+      permission="zope.Public"
+      />
+
+  <browser:page
+      for="*"
+      name="implicit_zcmltemplate"
+      class=".aqlegacy.Implicit"
+      template="falcon.pt"
+      permission="zope.Public"
+      />
+
+
+</configure>
\ No newline at end of file


Property changes on: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
===================================================================
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt	                        (rev 0)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt	2007-07-30 22:02:14 UTC (rev 78489)
@@ -0,0 +1,78 @@
+Testing legacy browser views
+============================
+
+This test tests publishing aspects of browser pages.  Let's register
+some:
+
+  >>> import Products.Five.browser.tests
+  >>> from Products.Five import zcml
+  >>> zcml.load_config("configure.zcml", Products.Five)
+  >>> zcml.load_config('aqlegacy.zcml', package=Products.Five.browser.tests)
+
+  >>> from Products.Five.testbrowser import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+
+Acquisition API legacy on BrowserView
+-------------------------------------
+
+Let's make sure that accessing those old aq_* properties on browser
+views still works (the printed output is the aq_chain of the view):
+
+  >>> browser.open('http://localhost/test_folder_1_/attributes')
+  >>> print browser.contents
+  [<Products.Five.metaclass.LegacyAttributes object at ...>, <Folder at /test_folder_1_>, <Application at >, <ZPublisher.BaseRequest.RequestContainer object at ...>]
+
+Let's also make sure that calling __of__ on a view has the desired
+effect.  First let's get a view:
+
+  >>> from zope.component import getMultiAdapter
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+  >>> view = getMultiAdapter((self.folder, request), name='attributes')
+
+Let's try the __of__ protocol:
+
+  #>>> view = view.__of__(self.app)
+  #>>> view.aq_parent == self.folder
+  #False
+  #>>> view.aq_parent == self.app
+  #True
+
+Mixing in Acquisition.{Ex|Im}plicit
+-----------------------------------
+
+Let's make sure that mixing in Acquisition.Explicit or Implicit won't
+mess up your views (even though you should never have done it in the
+first place...):
+
+  >>> browser.open('http://localhost/test_folder_1_/explicit')
+  >>> print browser.contents
+  Explicit
+
+  >>> browser.open('http://localhost/test_folder_1_/explicit_zcmltemplate')
+  >>> print browser.contents
+  <p>The falcon has taken flight</p>
+
+  >>> browser.open('http://localhost/test_folder_1_/explicit_template')
+  >>> print browser.contents
+  <p>The falcon has taken flight</p>
+
+  >>> browser.open('http://localhost/test_folder_1_/implicit')
+  >>> print browser.contents
+  Implicit
+
+  >>> browser.open('http://localhost/test_folder_1_/implicit_template')
+  >>> print browser.contents
+  <p>The falcon has taken flight</p>
+
+  >>> browser.open('http://localhost/test_folder_1_/implicit_zcmltemplate')
+  >>> print browser.contents
+  <p>The falcon has taken flight</p>
+
+
+Clean up
+--------
+
+  >>> from zope.app.testing.placelesssetup import tearDown
+  >>> tearDown()


Property changes on: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/test_pages.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/test_pages.py	2007-07-30 21:58:11 UTC (rev 78488)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/test_pages.py	2007-07-30 22:02:14 UTC (rev 78489)
@@ -77,7 +77,9 @@
         ZopeDocTestSuite(),
         ZopeDocFileSuite('pages.txt', package='Products.Five.browser.tests'),
         FunctionalDocFileSuite('pages_ftest.txt',
-                               package='Products.Five.browser.tests')
+                               package='Products.Five.browser.tests'),
+        FunctionalDocFileSuite('aqlegacy_ftest.txt',
+                               package='Products.Five.browser.tests'),
         ))
     return suite
 



More information about the Checkins mailing list