[Zope3-checkins] SVN: Zope3/branches/roger-contentprovider/src/zope/viewlet/ Fix viewlet tests

Roger Ineichen roger at projekt01.ch
Thu Oct 6 14:29:17 EDT 2005


Log message for revision 38818:
  Fix viewlet tests

Changed:
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/README.txt
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/SETUP.cfg
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py
  U   Zope3/branches/roger-contentprovider/src/zope/viewlet/tests/test_doc.py

-=-
Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/README.txt
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/README.txt	2005-10-06 18:20:53 UTC (rev 38817)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/README.txt	2005-10-06 18:29:17 UTC (rev 38818)
@@ -29,11 +29,11 @@
   >>> class ILeftColumn(zope.interface.Interface):
   ...     '''The left column of a Web site.'''
 
-  >>> from zope.app.viewlet import interfaces
-  >>> zope.interface.directlyProvides(ILeftColumn, interfaces.IRegion)
+  >>> from zope.contentprovider.interfaces import IRegion
+  >>> zope.interface.directlyProvides(ILeftColumn, IRegion)
 
   >>> import zope.component
-  >>> zope.component.provideUtility(ILeftColumn, interfaces.IRegion,
+  >>> zope.component.provideUtility(ILeftColumn, IRegion,
   ...                               'webpage.LeftColumn')
 
 It is important that the region interface provides the ``IRegion``
@@ -75,7 +75,7 @@
 and register the viewlet using a special helper function:
 
   # Create the viewlet class
-  >>> from zope.app.viewlet import viewlet
+  >>> from zope.viewlet import viewlet
   >>> Viewlet = viewlet.SimpleViewletClass(
   ...     viewletFileName, bases=(ViewletBase,), name='viewlet')
 
@@ -112,7 +112,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>
@@ -182,8 +182,9 @@
 not before the first one. Here is a most simple implementation:
 
   >>> from zope.app.publisher.browser import BrowserView
+  >>> from zope.viewlet.interfaces import IViewlet
   >>> class InfoViewlet(BrowserView):
-  ...     zope.interface.implements(interfaces.IViewlet, ILeftColumn)
+  ...     zope.interface.implements(IViewlet, ILeftColumn)
   ...     weight = 1
   ...
   ...     def __init__(self, context, request, view):
@@ -283,7 +284,7 @@
   ...     <div class="left-column">
   ...       <div class="column-item">
   ...         <tal:block
-  ...           replace="structure viewlet:webpage.LeftColumn/viewlet" />
+  ...           replace="structure provider:webpage.LeftColumn/viewlet" />
   ...       </div>
   ...     </div>
   ...   </body>
@@ -346,7 +347,7 @@
   ...     <h1>Contents</h1>
   ...     <table>
   ...       <tr tal:repeat="item view/objectInfo">
-  ...         <td tal:repeat="column viewlets:webpage.ObjectInfoColumn"
+  ...         <td tal:repeat="column providers:webpage.ObjectInfoColumn"
   ...             tal:content="structure column" />
   ...       </tr>
   ...     </table>
@@ -378,17 +379,16 @@
   ...         required=True)
 
   >>> zope.interface.directlyProvides(
-  ...     IObjectInfoColumn, interfaces.IRegion)
+  ...     IObjectInfoColumn, IRegion)
 
   >>> zope.component.provideUtility(
-  ...     IObjectInfoColumn, interfaces.IRegion,
-  ...     'webpage.ObjectInfoColumn')
+  ...     IObjectInfoColumn, IRegion, 'webpage.ObjectInfoColumn')
 
 
 Next we implement two very simple viewlets, one displaying the name
 
   >>> class NameColumnViewlet(BrowserView):
-  ...     zope.interface.implements(interfaces.IViewlet, IObjectInfoColumn)
+  ...     zope.interface.implements(IViewlet, IObjectInfoColumn)
   ...     weight = 0
   ...
   ...     def __init__(self, context, request, view):
@@ -409,7 +409,7 @@
 ... and the other displaying the size of the of objects in the list:
 
   >>> class SizeColumnViewlet(BrowserView):
-  ...     zope.interface.implements(interfaces.IViewlet, IObjectInfoColumn)
+  ...     zope.interface.implements(IViewlet, IObjectInfoColumn)
   ...     weight = 1
   ...
   ...     def __init__(self, context, request, view):
@@ -474,15 +474,15 @@
 Let's first have a close look at the default view manager, whose functionality
 we took for granted until now. Initializing the manager
 
-  >>> from zope.app.viewlet import manager
-  >>> defaultManager = manager.DefaultViewletManager(
+  >>> from zope.contentprovider import manager
+  >>> defaultManager = manager.DefaultContentProviderManager(
   ...     content, request, FrontPage(content, request))
 
 we can now get a list of viewlets:
 
-  >>> defaultManager.getViewlets(ILeftColumn)
+  >>> defaultManager.values(ILeftColumn)
   [<InfoViewlet object at ...>,
-   <zope.app.viewlet.viewlet.SimpleViewletClass from ...viewlet.pt object ...>]
+   <zope.viewlet.viewlet.SimpleViewletClass from ...viewlet.pt object ...>]
 
 The default manager also filters out all viewlets for which the current user
 is not authorized. So, if I create a viewlet that has no security
@@ -502,26 +502,26 @@
   ...     ILeftColumn,
   ...     name='unauthorized')
 
-  >>> len(defaultManager.getViewlets(ILeftColumn))
+  >>> len(defaultManager.values(ILeftColumn))
   2
 
 Also, when you try to look up the unauthorized viewlet by name you will get an
 exception telling you that you have insufficient priviledges to access the
 viewlet:
 
-  >>> defaultManager.getViewlet('unauthorized', ILeftColumn)
+  >>> defaultManager.__getitem__('unauthorized', ILeftColumn)
   Traceback (most recent call last):
   ...
-  Unauthorized: You are not authorized to access the viewlet
+  Unauthorized: You are not authorized to access the provider
                 called `unauthorized`.
 
 When looking for a particular viewlet, you also get an exception, if none is
 found:
 
-  >>> defaultManager.getViewlet('unknown', ILeftColumn)
+  >>> defaultManager.__getitem__('unknown', ILeftColumn)
   Traceback (most recent call last):
   ...
-  ComponentLookupError: 'No viewlet with name `unknown` found.'
+  ComponentLookupError: 'No provider with name `unknown` found.'
 
 
 An Alternative Viewlet Manager
@@ -537,9 +537,9 @@
 
 So our custom viewlet manager could look something like this:
 
-  >>> class ContentsViewletManager(manager.DefaultViewletManager):
+  >>> class ContentProviderManager(manager.DefaultContentProviderManager):
   ...
-  ...     def getViewlets(self, region):
+  ...     def values(self, region):
   ...         viewlets = zope.component.getAdapters(
   ...             (self.context, self.request, self.view), region)
   ...         viewlets = [(name, viewlet) for name, viewlet in viewlets
@@ -550,10 +550,11 @@
 
 We just have to register it as an adapter:
 
+  >>> from zope.contentprovider.interfaces import IContentProviderManager
   >>> zope.component.provideAdapter(
-  ...     ContentsViewletManager,
+  ...     ContentProviderManager,
   ...     (zope.interface.Interface, IDefaultBrowserLayer, IBrowserView),
-  ...     interfaces.IViewletManager)
+  ...     IContentProviderManager)
 
   >>> view = zope.component.getMultiAdapter(
   ...     (content, request), name='contents.html')

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/SETUP.cfg
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/SETUP.cfg	2005-10-06 18:20:53 UTC (rev 38817)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/SETUP.cfg	2005-10-06 18:29:17 UTC (rev 38818)
@@ -1,5 +1,5 @@
 # Tell zpkg how to install the ZCML slugs.
 
 <data-files zopeskel/etc/package-includes>
-  zope.app.viewlet-*.zcml
+  zope.viewlet-*.zcml
 </data-files>

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt	2005-10-06 18:20:53 UTC (rev 38817)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/directives.txt	2005-10-06 18:29:17 UTC (rev 38818)
@@ -9,13 +9,13 @@
   >>> from zope.configuration import xmlconfig
   >>> context = xmlconfig.string('''
   ... <configure i18n_domain="zope">
-  ...   <include package="zope.app.viewlet" file="meta.zcml" />
+  ...   <include package="zope.viewlet" file="meta.zcml" />
   ... </configure>
   ... ''')
 
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
-  ...            package="zope.app.viewlet.tests">
+  ...            package="zope.viewlet.tests">
   ...   <viewlet
   ...       name="testviewlet"
   ...       for="*"
@@ -48,10 +48,10 @@
   >>> view = BrowserView(content, request)
 
   >>> import zope.interface
-  >>> from zope.app.viewlet.tests.test_doc import ITestRegion
+  >>> from zope.viewlet.tests.test_doc import ITestRegion
 
   >>> import zope.component
-  >>> from zope.app.viewlet.interfaces import IViewlet
+  >>> from zope.viewlet.interfaces import IViewlet
   >>> viewlet = zope.component.getMultiAdapter(
   ...     (content, request, view), ITestRegion, name='testviewlet')
   >>> viewlet()
@@ -61,7 +61,7 @@
 
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
-  ...            package="zope.app.viewlet.tests">
+  ...            package="zope.viewlet.tests">
   ...   <viewlet
   ...       name="testviewlet2"
   ...       for="*"
@@ -83,7 +83,7 @@
 
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
-  ...            package="zope.app.viewlet.tests">
+  ...            package="zope.viewlet.tests">
   ...   <viewlet
   ...       name="testviewlet3"
   ...       for="*"
@@ -104,7 +104,7 @@
 
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
-  ...            package="zope.app.viewlet.tests">
+  ...            package="zope.viewlet.tests">
   ...   <viewlet
   ...       name="testviewlet4"
   ...       for="*"
@@ -129,7 +129,7 @@
 
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
-  ...            package="zope.app.viewlet.tests">
+  ...            package="zope.viewlet.tests">
   ...   <viewlet
   ...       name="testviewlet"
   ...       region=".test_doc.ITestRegion"
@@ -147,7 +147,7 @@
 
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
-  ...            package="zope.app.viewlet.tests">
+  ...            package="zope.viewlet.tests">
   ...   <viewlet
   ...       name="testviewlet"
   ...       region=".test_doc.ITestRegion"
@@ -167,7 +167,7 @@
 
   >>> context = xmlconfig.string('''
   ... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
-  ...            package="zope.app.viewlet.tests">
+  ...            package="zope.viewlet.tests">
   ...   <viewlet
   ...       name="testviewlet"
   ...       region=".test_doc.ITestRegion"

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py	2005-10-06 18:20:53 UTC (rev 38817)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/metaconfigure.py	2005-10-06 18:29:17 UTC (rev 38818)
@@ -30,7 +30,7 @@
 from zope.app.publisher.browser import viewmeta
 from zope.app.publisher.interfaces.browser import IBrowserView
 
-from zope.contentprovider import interfaces
+from zope.contentprovider.interfaces import IRegion
 from zope.viewlet import viewlet
 from zope.viewlet import interfaces
 
@@ -117,7 +117,7 @@
 
     viewmeta._handle_for(_context, for_)
     metaconfigure.interface(_context, view)
-    metaconfigure.interface(_context, region, interfaces.IRegion)
+    metaconfigure.interface(_context, region, IRegion)
 
     checker.defineChecker(new_class, checker.Checker(required))
 

Modified: Zope3/branches/roger-contentprovider/src/zope/viewlet/tests/test_doc.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/viewlet/tests/test_doc.py	2005-10-06 18:20:53 UTC (rev 38817)
+++ Zope3/branches/roger-contentprovider/src/zope/viewlet/tests/test_doc.py	2005-10-06 18:29:17 UTC (rev 38818)
@@ -24,7 +24,8 @@
 from zope.testing.doctestunit import DocTestSuite, DocFileSuite
 from zope.app.testing import setup
 
-from zope.app.viewlet import interfaces
+from zope.contentprovider.interfaces import IRegion
+from zope.viewlet import interfaces
 
 
 class TestViewlet(object):
@@ -40,8 +41,8 @@
 
 
 class ITestRegion(zope.interface.Interface):
-    '''A region for testing purposes.'''
-zope.interface.directlyProvides(ITestRegion, interfaces.IRegion)
+    """A region for testing purposes."""
+zope.interface.directlyProvides(ITestRegion, IRegion)
 
 
 class TestParticipation(object):
@@ -53,9 +54,9 @@
     setup.placefulSetUp()
 
     from zope.app.pagetemplate import metaconfigure
-    from zope.app.viewlet import tales
-    metaconfigure.registerType('viewlets', tales.TALESViewletsExpression)
-    metaconfigure.registerType('viewlet', tales.TALESViewletExpression)
+    from zope.contentprovider import tales
+    metaconfigure.registerType('providers', tales.TALESProvidersExpression)
+    metaconfigure.registerType('provider', tales.TALESProviderExpression)
 
     zope.security.management.getInteraction().add(TestParticipation())
 
@@ -66,7 +67,6 @@
 
 def test_suite():
     return unittest.TestSuite((
-        DocTestSuite('zope.app.viewlet.tales'),
         DocFileSuite('../README.txt',
                      setUp=setUp, tearDown=tearDown,
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,



More information about the Zope3-Checkins mailing list