[Zope3-checkins] SVN: Zope3/branches/roger-contentprovider/src/zope/contentprovider/ first steps towards making the tests run again

Helmut Merz helmutm at cy55.de
Thu Oct 6 13:39:04 EDT 2005


Log message for revision 38814:
  first steps towards making the tests run again

Changed:
  U   Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt
  U   Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py
  U   Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py
  A   Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/
  A   Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/__init__.py
  A   Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py

-=-
Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt	2005-10-06 17:09:32 UTC (rev 38813)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/README.txt	2005-10-06 17:39:03 UTC (rev 38814)
@@ -1,11 +1,11 @@
-========
-Viewlets
-========
+=================
+Content Providers
+=================
 
 This package provides a framework to develop componentized Web GUI
 applications. Instead of describing the content of a page using a single
 template or static system of templates and METAL macros, page regions can be
-defined and are filled dynamically with content (viewlets) based on the setup
+defined and are filled dynamically with content based on the setup
 of the application.
 
 
@@ -29,14 +29,14 @@
   >>> class ILeftColumn(zope.interface.Interface):
   ...     '''The left column of a Web site.'''
 
-  >>> from zope.app.viewlet import interfaces
+  >>> from zope.contentprovider import interfaces
   >>> zope.interface.directlyProvides(ILeftColumn, interfaces.IRegion)
 
   >>> import zope.component
   >>> zope.component.provideUtility(ILeftColumn, interfaces.IRegion,
   ...                               'webpage.LeftColumn')
 
-It is important that the region interface provides the ``IRegion``
+It is important that the region provides the ``IRegion``
 interface and that it is registered as a utility providing
 ``IRegion``. If omitted, the framework will be unable to find the
 region later.
@@ -52,38 +52,15 @@
 filling; we will demonstrate a more advanced example later, where the purpose
 of this requirement becomes clear.
 
-Like regular views, viewlets can either use page templates to provide content
-or provide a simple ``__call__`` method. For our first viewlet, let's develop
-a more commonly used page-template-driven viewlet:
+  >>> class TestViewlet(object):
+  ...     title = 'Demo Viewlet'
+  ...     weight = 1
+  ...     def __call__(self, *args, **kw):
+  ...         return 'viewlet content'
 
-  >>> import os, tempfile
-  >>> temp_dir = tempfile.mkdtemp()
+  >>> Viewlet = TestViewlet()
 
-  >>> viewletFileName = os.path.join(temp_dir, 'viewlet.pt')
-  >>> open(viewletFileName, 'w').write('''
-  ...         <div class="box">
-  ...           <tal:block replace="viewlet/title" />
-  ...         </div>
-  ... ''')
-
-  >>> class ViewletBase(object):
-  ...     def title(self):
-  ...         return 'Viewlet Title'
-
-As you can see, the viewlet Python object is known as ``viewlet`` inside the
-template, while the view object is still available as ``view``. Next we build
-and register the viewlet using a special helper function:
-
-  # Create the viewlet class
-  >>> from zope.app.viewlet import viewlet
-  >>> Viewlet = viewlet.SimpleViewletClass(
-  ...     viewletFileName, bases=(ViewletBase,), name='viewlet')
-
-  # Generate a viewlet checker
-  >>> from zope.security.checker import NamesChecker, defineChecker
-  >>> viewletChecker = NamesChecker(('__call__', 'weight', 'title',))
-  >>> defineChecker(Viewlet, viewletChecker)
-
+  
   # Register the viewlet with component architecture
   >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
   >>> from zope.app.publisher.interfaces.browser import IBrowserView
@@ -93,10 +70,6 @@
   ...     ILeftColumn,
   ...     name='viewlet')
 
-As you can see from the security checker registration, a viewlet provides also
-a weight, which acts as a hint to determine the order in which the viewlets of
-a region should be displayed. The view the viewlet is used in can also be
-accessed via the ``view`` attribute of the viewlet class.
 
 
 Creating the View
@@ -105,6 +78,8 @@
 Now that we have a region with a viewlet registered for it, let's use it by
 creating the front page of our Web Site:
 
+  >>> import os, tempfile
+  >>> temp_dir = tempfile.mkdtemp()
   >>> templateFileName = os.path.join(temp_dir, 'template.pt')
   >>> open(templateFileName, 'w').write('''
   ... <html>
@@ -112,7 +87,7 @@
   ...     <h1>My Web Page</h1>
   ...     <div class="left-column">
   ...       <div class="column-item"
-  ...            tal:repeat="viewlet viewlets:webpage.LeftColumn">
+  ...            tal:repeat="viewlet providers:webpage.LeftColumn">
   ...         <tal:block replace="structure viewlet" />
   ...       </div>
   ...     </div>
@@ -202,6 +177,8 @@
   ...     name='infoViewlet')
 
 
+
+  
 Note that you would commonly not state in the class itself that it
 implements a particular region, since it is usually done by the ZCML
 directive, which is introduced in `directives.zcml`.

Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py	2005-10-06 17:09:32 UTC (rev 38813)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/manager.py	2005-10-06 17:39:03 UTC (rev 38814)
@@ -21,7 +21,7 @@
 import zope.interface
 import zope.security
 
-from zope.viewlet import interfaces
+from zope.contentprovider import interfaces
 
 
 class DefaultContentProviderManager(object):
@@ -31,7 +31,7 @@
     sorts the viewlet list by weight. Viewlets that are not accessible in the
     context of this request will also be filtered.
     """
-    zope.interface.implements(interfaces.IViewletManager)
+    zope.interface.implements(interfaces.IContentProviderManager)
 
     def __init__(self, context, request, view):
         self.context = context

Modified: Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py	2005-10-06 17:09:32 UTC (rev 38813)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/tales.py	2005-10-06 17:39:03 UTC (rev 38814)
@@ -20,7 +20,7 @@
 import zope.component
 from zope.tales import expressions
 
-from zope.app.viewlet import interfaces, manager
+from zope.contentprovider import interfaces, manager
 
 
 def getRegion(str):

Added: Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/__init__.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/__init__.py	2005-10-06 17:09:32 UTC (rev 38813)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/__init__.py	2005-10-06 17:39:03 UTC (rev 38814)
@@ -0,0 +1 @@
+# Make a package.


Property changes on: Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py	2005-10-06 17:09:32 UTC (rev 38813)
+++ Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py	2005-10-06 17:39:03 UTC (rev 38814)
@@ -0,0 +1,81 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Viewlet tests
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+import zope.interface
+import zope.security
+from zope.testing import doctest
+from zope.testing.doctestunit import DocTestSuite, DocFileSuite
+from zope.app.testing import setup
+
+from zope.app.viewlet import interfaces
+
+
+class TestViewlet(object):
+
+    def doSomething(self):
+        return u'something'
+
+
+class TestViewlet2(object):
+
+    def __call__(self):
+        return u'called'
+
+
+class ITestRegion(zope.interface.Interface):
+    '''A region for testing purposes.'''
+zope.interface.directlyProvides(ITestRegion, interfaces.IRegion)
+
+
+class TestParticipation(object):
+    principal = 'foobar'
+    interaction = None
+
+
+def setUp(test):
+    setup.placefulSetUp()
+
+    from zope.app.pagetemplate import metaconfigure
+    from zope.contentprovider import tales
+    metaconfigure.registerType('providers', tales.TALESProvidersExpression)
+    metaconfigure.registerType('provider', tales.TALESProviderExpression)
+
+    zope.security.management.getInteraction().add(TestParticipation())
+
+
+def tearDown(test):
+    setup.placefulTearDown()
+
+
+def test_suite():
+    return unittest.TestSuite((
+        DocTestSuite('zope.contentprovider.tales'),
+        DocFileSuite('../README.txt',
+                     setUp=setUp, tearDown=tearDown,
+                     optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+                     ),
+#         DocFileSuite('../directives.txt',
+#                      setUp=setUp, tearDown=tearDown,
+#                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+#                      ),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: Zope3/branches/roger-contentprovider/src/zope/contentprovider/tests/test_doc.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list