[Checkins] SVN: Sandbox/faassen/zope.site/trunk/src/zope/site/ More various cleanups.

Martijn Faassen faassen at infrae.com
Tue Jan 27 07:43:38 EST 2009


Log message for revision 95155:
  More various cleanups.
  

Changed:
  U   Sandbox/faassen/zope.site/trunk/src/zope/site/README.txt
  U   Sandbox/faassen/zope.site/trunk/src/zope/site/__init__.py
  A   Sandbox/faassen/zope.site/trunk/src/zope/site/next.py
  U   Sandbox/faassen/zope.site/trunk/src/zope/site/site.txt
  D   Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_contentdirective.py
  D   Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_directives.py
  D   Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_vocabulary.py

-=-
Modified: Sandbox/faassen/zope.site/trunk/src/zope/site/README.txt
===================================================================
--- Sandbox/faassen/zope.site/trunk/src/zope/site/README.txt	2009-01-27 12:39:29 UTC (rev 95154)
+++ Sandbox/faassen/zope.site/trunk/src/zope/site/README.txt	2009-01-27 12:43:38 UTC (rev 95155)
@@ -2,95 +2,24 @@
 Zope 3's Local Component Architecture
 =====================================
 
-The local component architecture provides several packages that can be used
-independent of the entire component architecture framework. Thus, I decided to
-document these frameworks in different files.
+This package provides a local and persistent site manager
+implementation, so that one can register local utilities and
+adapters. It uses local adapter registries for its adapter and utility
+registry. The module also provides some facilities to organize the
+local software and ensures the correct behavior inside the ZODB.
 
-  o Registration Framework (`registration.txt`)
-
-    Provides an API for creating custom registries. The entries of the
-    registries are managed via registration components. A specific
-    implementation for component-based registrations is also
-    provided. Finally, there are some generic container classes that allow the
-    developer to manage the components and their registrations.
-
-  o Local Adapter Registry (`adapterregistry.txt`)
-
-    Provides a persistent adapter registry that uses the registration
-    framework. Local registries can be assembled to a registry tree where
-    nodes further down in the tree overrride registrations of higher-up nodes.
-
-  o Sites and Local Site Managers (`site.txt`)
-
-    Provides a local and persistent site manager implementation, so that one
-    can register local utilities and adapters. It uses local adapter
-    registries for its adapter and utility registry. The module also provides
-    some facilities to organize the local software and ensures the correct
-    behavior inside the ZODB.
-
-
 Local Component Architecture API
 --------------------------------
 
 While the component architecture API provided by ``zope.component`` is
-sufficient most of the time, there are a couple of functions that are useful
-in the context of multiple sites and base component registries.
+sufficient most of the time, there are a couple of functions that are
+useful in the context of multiple sites and base component registries.
 
---- BBB: Deprecated on 9/26/2006 --
+It is common for a utility to delegate its answer to a utility
+providing the same interface in one of the component registry's
+bases. Let's start by creating a utility and inserting it in our
+folder hiearchy:
 
-  >>> import zope.deprecation
-  >>> zope.deprecation.__show__.off()
-
-A very common use case is to get the nearest site manager in a given
-context. Sometimes, however, one wants the next higher-up site manager. First,
-let's create a folder tree and create some sites from it:
-
-  >>> from zope.app.testing import setup
-  >>> root = setup.buildSampleFolderTree()
-  >>> root_sm = setup.createSiteManager(root)
-  >>> folder1_sm = setup.createSiteManager(root['folder1'])
-
-If we ask `folder1` for its nearest site manager, we get
-
-  >>> from zope.component import getSiteManager
-  >>> getSiteManager(root['folder1']) is folder1_sm
-  True
-
-but its next site manager is
-
-  >>> from zope.app import component
-  >>> component.getNextSiteManager(root['folder1']) is root_sm
-  True
-
-The next site manager of the local root is the global site manager:
-
-  >>> from zope.component import getGlobalSiteManager
-  >>> gsm = getGlobalSiteManager()
-  >>> component.getNextSiteManager(root) is gsm
-  True
-
-If a non-location is passed into the function, a component lookup error is
-raised, since there is no site manager beyond the global site manager:
-
-  >>> component.getNextSiteManager(object())
-  Traceback (most recent call last):
-  ...
-  ComponentLookupError: No more site managers have been found.
-
-If you use the `queryNextSiteManager()` function, you can specify a `default`
-return value:
-
-  >>> component.queryNextSiteManager(object(), 'default')
-  'default'
-
-  >>> zope.deprecation.__show__.on()
-
---- BBB: End of block --
-
-It is common for a utility to delegate its answer to a utility providing the
-same interface in one of the component registry's bases. Let's start by
-creating a utility and inserting it in our folder hiearchy:
-
   >>> import zope.interface
   >>> class IMyUtility(zope.interface.Interface):
   ...     pass
@@ -114,18 +43,19 @@
 
 Now, if we ask `util1_1` for its next available utility and we get
 
-  >>> component.getNextUtility(util1_1, IMyUtility, 'myutil')
+  >>> from zope import site
+  >>> site.getNextUtility(util1_1, IMyUtility, 'myutil')
   MyUtility('one')
 
 Next we ask `util1` for its next utility and we should get the global version:
 
-  >>> component.getNextUtility(util1, IMyUtility, 'myutil')
+  >>> site.getNextUtility(util1, IMyUtility, 'myutil')
   MyUtility('global')
 
 However, if we ask the global utility for the next one, an error is raised
 
-  >>> component.getNextUtility(gutil, IMyUtility,
-  ...                          'myutil') #doctest: +NORMALIZE_WHITESPACE
+  >>> site.getNextUtility(gutil, IMyUtility,
+  ...                     'myutil') #doctest: +NORMALIZE_WHITESPACE
   Traceback (most recent call last):
   ...
   ComponentLookupError:
@@ -134,7 +64,7 @@
 
 or you can simply use the `queryNextUtility` and specify a default:
 
-  >>> component.queryNextUtility(gutil, IMyUtility, 'myutil', 'default')
+  >>> site.queryNextUtility(gutil, IMyUtility, 'myutil', 'default')
   'default'
 
 Let's now ensure that the function also works with multiple registries. First
@@ -152,7 +82,7 @@
 
 Both, the ``myregistry`` and global utilities should be available:
 
-  >>> component.queryNextUtility(folder1_sm, IMyUtility, 'my_custom_util')
+  >>> site.queryNextUtility(folder1_sm, IMyUtility, 'my_custom_util')
   MyUtility('my_custom_util')
-  >>> component.queryNextUtility(folder1_sm, IMyUtility, 'myutil')
+  >>> site.queryNextUtility(folder1_sm, IMyUtility, 'myutil')
   MyUtility('global')

Modified: Sandbox/faassen/zope.site/trunk/src/zope/site/__init__.py
===================================================================
--- Sandbox/faassen/zope.site/trunk/src/zope/site/__init__.py	2009-01-27 12:39:29 UTC (rev 95154)
+++ Sandbox/faassen/zope.site/trunk/src/zope/site/__init__.py	2009-01-27 12:43:38 UTC (rev 95155)
@@ -15,36 +15,10 @@
 
 $Id$
 """
-__docformat__ = "reStructuredText"
 
-import zope.component
-import zope.deprecation
+from zope.site.site import SiteManagerContainer, SiteManagerFolder
+from zope.site.site import LocalSiteManager, changeSiteConfigurationAfterMove
+from zope.site.site import threadSiteSubscriber
+from zope.site.site import clearThreadSiteSubscriber
+from zope.site.next import getNextUtility, queryNextUtility
 
-_marker = object()
-
-def getNextUtility(context, interface, name=''):
-    """Get the next available utility.
-
-    If no utility was found, a `ComponentLookupError` is raised.
-    """
-    util = queryNextUtility(context, interface, name, _marker)
-    if util is _marker:
-        raise zope.component.interfaces.ComponentLookupError(
-              "No more utilities for %s, '%s' have been found." % (
-                  interface, name))
-    return util
-
-
-def queryNextUtility(context, interface, name='', default=None):
-    """Query for the next available utility.
-
-    Find the next available utility providing `interface` and having the
-    specified name. If no utility was found, return the specified `default`
-    value."""
-    sm = zope.component.getSiteManager(context)
-    bases = sm.__bases__
-    for base in bases:
-        util = base.queryUtility(interface, name, _marker)
-        if util is not _marker:
-            return util
-    return default

Added: Sandbox/faassen/zope.site/trunk/src/zope/site/next.py
===================================================================
--- Sandbox/faassen/zope.site/trunk/src/zope/site/next.py	                        (rev 0)
+++ Sandbox/faassen/zope.site/trunk/src/zope/site/next.py	2009-01-27 12:43:38 UTC (rev 95155)
@@ -0,0 +1,33 @@
+import zope.component
+
+__docformat__ = "reStructuredText"
+
+_marker = object()
+
+def getNextUtility(context, interface, name=''):
+    """Get the next available utility.
+
+    If no utility was found, a `ComponentLookupError` is raised.
+    """
+    util = queryNextUtility(context, interface, name, _marker)
+    if util is _marker:
+        raise zope.component.interfaces.ComponentLookupError(
+              "No more utilities for %s, '%s' have been found." % (
+                  interface, name))
+    return util
+
+
+def queryNextUtility(context, interface, name='', default=None):
+    """Query for the next available utility.
+
+    Find the next available utility providing `interface` and having the
+    specified name. If no utility was found, return the specified `default`
+    value."""
+    sm = zope.component.getSiteManager(context)
+    bases = sm.__bases__
+    for base in bases:
+        util = base.queryUtility(interface, name, _marker)
+        if util is not _marker:
+            return util
+    return default
+

Modified: Sandbox/faassen/zope.site/trunk/src/zope/site/site.txt
===================================================================
--- Sandbox/faassen/zope.site/trunk/src/zope/site/site.txt	2009-01-27 12:39:29 UTC (rev 95154)
+++ Sandbox/faassen/zope.site/trunk/src/zope/site/site.txt	2009-01-27 12:43:38 UTC (rev 95155)
@@ -3,21 +3,18 @@
 =============================
 
 This chapter is an introduction of the location-based component
-architecture. This code uses the registration framework introduced in
-`registration.txt` and local adapter registries described in
-`adapterregistry.txt`.
+architecture.
 
-
 Creating and Accessing Sites
 ----------------------------
 
 *Sites* are used to provide custom component setups for parts of your
-application or Web site. Every folder,
+application or Web site. Every folder:
 
   >>> from zope.app.folder import folder
   >>> myfolder = folder.rootFolder()
 
-has the potential to become a site
+has the potential to become a site:
 
   >>> from zope.location.interfaces import ISite, IPossibleSite
   >>> IPossibleSite.providedBy(myfolder)
@@ -31,7 +28,7 @@
 If you would like your custom content component to be able to become a site,
 you can use the `SiteManagerContainer` mix-in class:
 
-  >>> from zope.app.component import site
+  >>> from zope import site
   >>> class MyContentComponent(site.SiteManagerContainer):
   ...     pass
 
@@ -118,13 +115,13 @@
   >>> sm = myfolder.getSiteManager()
   >>> default = sm['default']
   >>> default.__class__
-  <class 'zope.app.component.site.SiteManagementFolder'>
+  <class 'zope.site.site.SiteManagementFolder'>
 
 You can easily create a new site management folder:
 
   >>> sm['mySMF'] = site.SiteManagementFolder()
   >>> sm['mySMF'].__class__
-  <class 'zope.app.component.site.SiteManagementFolder'>
+  <class 'zope.site.site.SiteManagementFolder'>
 
 Once you have your site management folder -- let's use the default one -- we
 can register some components. Let's start with a utility

Deleted: Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_contentdirective.py
===================================================================
--- Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_contentdirective.py	2009-01-27 12:39:29 UTC (rev 95154)
+++ Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_contentdirective.py	2009-01-27 12:43:38 UTC (rev 95155)
@@ -1,206 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 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.
-#
-##############################################################################
-"""Test 'zope:class' directive.
-
-$Id$
-"""
-import unittest
-from StringIO import StringIO
-
-from zope.component.interfaces import IFactory
-from zope.component.interfaces import ComponentLookupError
-from zope.component.interface import queryInterface
-from zope.configuration.xmlconfig import xmlconfig, XMLConfig
-
-import zope.component
-import zope.app.security
-import zope.app.component
-from zope.app.testing.placelesssetup import PlacelessSetup
-
-# explicitly import ExampleClass and IExample using full paths
-# so that they are the same objects as resolve will get.
-from zope.app.component.tests.exampleclass import ExampleClass
-from zope.app.component.tests.exampleclass import IExample, IExample2
-
-
-class ParticipationStub(object):
-
-    def __init__(self, principal):
-        self.principal = principal
-        self.interaction = None
-
-
-def configfile(s):
-    return StringIO("""<configure
-      xmlns='http://namespaces.zope.org/zope'
-      i18n_domain='zope'>
-      %s
-      </configure>
-      """ % s)
-
-class TestClassDirective(PlacelessSetup, unittest.TestCase):
-    def setUp(self):
-        super(TestClassDirective, self).setUp()
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
-
-        try:
-            del ExampleClass.__implements__
-        except AttributeError:
-            pass
-
-    def testEmptyDirective(self):
-        f = configfile("""
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-</class>
-                       """)
-        xmlconfig(f)
-
-
-    def testImplements(self):
-        self.assertEqual(queryInterface(
-            "zope.app.component.tests.exampleclass.IExample"), None)
-
-        f = configfile("""
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-  <implements interface="zope.app.component.tests.exampleclass.IExample" />
-</class>
-                       """)
-        xmlconfig(f)
-        self.failUnless(IExample.implementedBy(ExampleClass))
-
-        self.assertEqual(queryInterface(
-            "zope.app.component.tests.exampleclass.IExample"), IExample)
-
-
-    def testMulImplements(self):
-        self.assertEqual(queryInterface(
-            "zope.app.component.tests.exampleclass.IExample"), None)
-        self.assertEqual(queryInterface(
-            "zope.app.component.tests.exampleclass.IExample2"), None)
-
-        f = configfile("""
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-  <implements interface="
-           zope.app.component.tests.exampleclass.IExample
-           zope.app.component.tests.exampleclass.IExample2
-                       " />
-</class>
-                       """)
-        xmlconfig(f)
-        self.failUnless(IExample.implementedBy(ExampleClass))
-        self.failUnless(IExample2.implementedBy(ExampleClass))
-
-        self.assertEqual(queryInterface(
-            "zope.app.component.tests.exampleclass.IExample"), IExample)
-        self.assertEqual(queryInterface(
-            "zope.app.component.tests.exampleclass.IExample2"),
-                         IExample2)
-
-    def testRequire(self):
-        f = configfile("""
-<permission id="zope.View" title="Zope view permission" />
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-    <require permission="zope.View"
-                      attributes="anAttribute anotherAttribute" />
-</class>
-                       """)
-        xmlconfig(f)
-
-    def testAllow(self):
-        f = configfile("""
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-    <allow attributes="anAttribute anotherAttribute" />
-</class>
-                       """)
-        xmlconfig(f)
-
-    def testMimic(self):
-        f = configfile("""
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-    <require like_class="zope.app.component.tests.exampleclass.ExampleClass" />
-</class>
-                       """)
-        xmlconfig(f)
-
-
-class TestFactorySubdirective(PlacelessSetup, unittest.TestCase):
-    def setUp(self):
-        super(TestFactorySubdirective, self).setUp()
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
-
-    def testFactory(self):
-        f = configfile("""
-<permission id="zope.Foo" title="Zope Foo Permission" />
-
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-  <factory
-      id="test.Example"
-      title="Example content"
-      description="Example description"
-      />
-</class>
-                       """)
-        xmlconfig(f)
-        factory = zope.component.getUtility(IFactory, 'test.Example')
-        self.assertEquals(factory.title, "Example content")
-        self.assertEquals(factory.description, "Example description")
-
-    def testFactoryNoId(self):
-        f = configfile("""
-<permission id="zope.Foo" title="Zope Foo Permission" />
-
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-    <factory
-      title="Example content"
-      description="Example description"
-    />
-</class>
-                       """)
-        xmlconfig(f)
-        self.assertRaises(ComponentLookupError, zope.component.getUtility,
-                          IFactory, 'Example')
-        factory = zope.component.getUtility(
-            IFactory, 'zope.app.component.tests.exampleclass.ExampleClass')
-        self.assertEquals(factory.title, "Example content")
-        self.assertEquals(factory.description, "Example description")
-
-
-    def testFactoryPublicPermission(self):
-
-        f = configfile("""
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-    <factory
-      id="test.Example"
-      title="Example content"
-      description="Example description"
-    />
-</class>
-            """)
-        xmlconfig(f)
-        factory = zope.component.getUtility(IFactory, 'test.Example')
-        self.assert_(hasattr(factory, '__Security_checker__'))
-
-
-def test_suite():
-    suite = unittest.TestSuite()
-    loader = unittest.TestLoader()
-    suite.addTest(loader.loadTestsFromTestCase(TestClassDirective))
-    suite.addTest(loader.loadTestsFromTestCase(TestFactorySubdirective))
-    return suite
-
-
-if __name__=='__main__':
-    unittest.TextTestRunner().run(test_suite())

Deleted: Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_directives.py
===================================================================
--- Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_directives.py	2009-01-27 12:39:29 UTC (rev 95154)
+++ Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_directives.py	2009-01-27 12:43:38 UTC (rev 95155)
@@ -1,805 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 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.
-#
-##############################################################################
-"""Component Directives Tests
-
-$Id$
-"""
-import re
-import unittest
-import pprint
-import warnings
-from cStringIO import StringIO
-
-import zope.component
-from zope.interface import implements
-from zope.testing.doctestunit import DocTestSuite
-from zope.component.interfaces import IDefaultViewName
-from zope.component.interfaces import ComponentLookupError
-from zope.component.interface import queryInterface
-
-from zope.configuration.xmlconfig import xmlconfig, XMLConfig
-from zope.configuration.exceptions import ConfigurationError
-from zope.configuration.xmlconfig import ZopeXMLConfigurationError
-from zope.security.checker import ProxyFactory, selectChecker
-from zope.security import proxy
-
-import zope.app.component
-from zope.app.testing.placelesssetup import PlacelessSetup
-from zope.app.component.tests.adapter import A1, A2, A3
-from zope.app.component.tests.adapter import I1, I2, I3, IS
-from zope.app.component.tests.components import IContent, Content
-from zope.app.component.tests.components import IApp
-from zope.app.component.tests.views import Request, IV, IC, V1, R1, IR
-
-from zope.app.component.tests import module, exampleclass
-
-# TODO: tests for other directives needed
-
-atre = re.compile(' at [0-9a-fA-Fx]+')
-
-class Context(object):
-    actions = ()
-
-    def action(self, discriminator, callable, args):
-        self.actions += ((discriminator, callable, args), )
-
-    def __repr__(self):
-        stream = StringIO()
-        pprinter = pprint.PrettyPrinter(stream=stream, width=60)
-        pprinter.pprint(self.actions)
-        r = stream.getvalue()
-        return (''.join(atre.split(r))).strip()
-
-
-template = """<configure
-   xmlns='http://namespaces.zope.org/zope'
-   xmlns:test='http://www.zope.org/NS/Zope3/test'
-   i18n_domain='zope'>
-   %s
-   </configure>"""
-
-class Ob(object):
-    implements(IC)
-
-def definePermissions():
-    XMLConfig('meta.zcml', zope.app.component)()
-
-
-class Test(PlacelessSetup, unittest.TestCase):
-
-    def setUp(self):
-        super(Test, self).setUp()
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
-
-    def testView(self):
-        ob = Ob()
-        request = Request(IV)
-        self.assertEqual(
-            zope.component.queryMultiAdapter((ob, request), name=u'test'), None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"/>
-            '''
-            ))
-
-        self.assertEqual(
-            zope.component.queryMultiAdapter((ob, request),
-                                             name=u'test').__class__,
-            V1)
-
-
-    def testMultiView(self):
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.adapter.A3"
-                  for="zope.app.component.tests.views.IC
-                       zope.app.component.tests.adapter.I1
-                       zope.app.component.tests.adapter.I2"
-                  type="zope.app.component.tests.views.IV"/>
-            '''
-            ))
-
-
-        ob = Ob()
-        a1 = A1()
-        a2 = A2()
-        request = Request(IV)
-        view = zope.component.queryMultiAdapter((ob, a1, a2, request),
-                                                name=u'test')
-        self.assertEqual(view.__class__, A3)
-        self.assertEqual(view.context, (ob, a1, a2, request))
-
-
-    def testMultiView_fails_w_multiple_factories(self):
-        self.assertRaises(
-            ConfigurationError,
-            xmlconfig,
-            StringIO(template %
-              '''
-              <view name="test"
-                    factory="zope.app.component.tests.adapter.A3
-                             zope.app.component.tests.adapter.A2"
-                    for="zope.app.component.tests.views.IC
-                         zope.app.component.tests.adapter.I1
-                         zope.app.component.tests.adapter.I2"
-                    type="zope.app.component.tests.views.IV"/>
-              '''
-              )
-            )
-
-    def testView_w_multiple_factories(self):
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.adapter.A1
-                           zope.app.component.tests.adapter.A2
-                           zope.app.component.tests.adapter.A3
-                           zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"/>
-            '''
-            ))
-
-        ob = Ob()
-
-        # The view should be a V1 around an A3, around an A2, around
-        # an A1, anround ob:
-        view = zope.component.queryMultiAdapter((ob, Request(IV)), name=u'test')
-        self.assertEqual(view.__class__, V1)
-        a3 = view.context
-        self.assertEqual(a3.__class__, A3)
-        a2 = a3.context[0]
-        self.assertEqual(a2.__class__, A2)
-        a1 = a2.context[0]
-        self.assertEqual(a1.__class__, A1)
-        self.assertEqual(a1.context[0], ob)
-
-    def testView_fails_w_no_factories(self):
-        self.assertRaises(ConfigurationError,
-                          xmlconfig,
-                          StringIO(template %
-                                   '''
-                                   <view name="test"
-                                   factory=""
-                                   for="zope.app.component.tests.views.IC"
-                                   type="zope.app.component.tests.views.IV"/>
-                                   '''
-                                   ),
-                          )
-
-
-    def testViewThatProvidesAnInterface(self):
-        ob = Ob()
-        self.assertEqual(
-            zope.component.queryMultiAdapter((ob, Request(IR)), IV, u'test'),
-            None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IR"
-                  />
-            '''
-            ))
-
-        self.assertEqual(
-            zope.component.queryMultiAdapter((ob, Request(IR)), IV, u'test'),
-            None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IR"
-                  provides="zope.app.component.tests.views.IV"
-                  />
-            '''
-            ))
-
-        v = zope.component.queryMultiAdapter((ob, Request(IR)), IV, u'test')
-        self.assertEqual(v.__class__, V1)
-
-
-    def testUnnamedViewThatProvidesAnInterface(self):
-        ob = Ob()
-        self.assertEqual(
-            zope.component.queryMultiAdapter((ob, Request(IR)), IV), None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <view factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IR"
-                  />
-            '''
-            ))
-
-        v = zope.component.queryMultiAdapter((ob, Request(IR)), IV)
-        self.assertEqual(v, None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <view factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IR"
-                  provides="zope.app.component.tests.views.IV"
-                  />
-            '''
-            ))
-
-        v = zope.component.queryMultiAdapter((ob, Request(IR)), IV)
-        self.assertEqual(v.__class__, V1)
-
-    def testViewHavingARequiredClass(self):
-        xmlconfig(StringIO(template % (
-            '''
-            <view
-              for="zope.app.component.tests.components.Content"
-              type="zope.app.component.tests.views.IR"
-              factory="zope.app.component.tests.adapter.A1"
-              />
-            '''
-            )))
-
-        content = Content()
-        a1 = zope.component.getMultiAdapter((content, Request(IR)))
-        self.assert_(isinstance(a1, A1))
-
-        class MyContent:
-            implements(IContent)
-
-        self.assertRaises(ComponentLookupError, zope.component.getMultiAdapter,
-                          (MyContent(), Request(IR)))
-
-    def testInterfaceProtectedView(self):
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"
-                  permission="zope.Public"
-              allowed_interface="zope.app.component.tests.views.IV"
-                  />
-            '''
-            ))
-
-        v = ProxyFactory(zope.component.getMultiAdapter((Ob(), Request(IV)),
-                                                        name='test'))
-        self.assertEqual(v.index(), 'V1 here')
-        self.assertRaises(Exception, getattr, v, 'action')
-
-    def testAttributeProtectedView(self):
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"
-                  permission="zope.Public"
-                  allowed_attributes="action"
-                  />
-            '''
-            ))
-
-        v = ProxyFactory(zope.component.getMultiAdapter((Ob(), Request(IV)),
-                                                        name='test'))
-        self.assertEqual(v.action(), 'done')
-        self.assertRaises(Exception, getattr, v, 'index')
-
-    def testInterfaceAndAttributeProtectedView(self):
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"
-                  permission="zope.Public"
-                  allowed_attributes="action"
-              allowed_interface="zope.app.component.tests.views.IV"
-                  />
-            '''
-            ))
-
-        v = zope.component.getMultiAdapter((Ob(), Request(IV)), name='test')
-        self.assertEqual(v.index(), 'V1 here')
-        self.assertEqual(v.action(), 'done')
-
-    def testDuplicatedInterfaceAndAttributeProtectedView(self):
-        xmlconfig(StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"
-                  permission="zope.Public"
-                  allowed_attributes="action index"
-              allowed_interface="zope.app.component.tests.views.IV"
-                  />
-            '''
-            ))
-
-        v = zope.component.getMultiAdapter((Ob(), Request(IV)), name='test')
-        self.assertEqual(v.index(), 'V1 here')
-        self.assertEqual(v.action(), 'done')
-
-    def testIncompleteProtectedViewNoPermission(self):
-        self.assertRaises(
-            ConfigurationError,
-            xmlconfig,
-            StringIO(template %
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"
-                  allowed_attributes="action index"
-                  />
-            '''
-            ))
-
-    def testViewUndefinedPermission(self):
-        config = StringIO(template % (
-            '''
-            <view name="test"
-                  factory="zope.app.component.tests.views.V1"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"
-                  permission="zope.UndefinedPermission"
-                  allowed_attributes="action index"
-              allowed_interface="zope.app.component.tests.views.IV"
-                  />
-            '''
-            ))
-        self.assertRaises(ValueError, xmlconfig, config, testing=1)
-
-
-    def testDefaultView(self):
-        ob = Ob()
-        self.assertEqual(
-            zope.component.queryMultiAdapter((Ob(), Request(IV)), name='test'),
-            None)
-
-        xmlconfig(StringIO(template % (
-            '''
-            <defaultView name="test"
-                  for="zope.app.component.tests.views.IC"
-                  type="zope.app.component.tests.views.IV"/>
-            '''
-            )))
-
-        self.assertEqual(
-            zope.component.queryMultiAdapter((Ob(), Request(IV)), name='test'),
-            None)
-        self.assertEqual(
-            zope.component.getGlobalSiteManager().adapters.lookup(
-                (IC, IV), IDefaultViewName),
-            'test')
-
-    def testResource(self):
-        ob = Ob()
-        self.assertEqual(
-            zope.component.queryAdapter(Request(IV), name=u'test'), None)
-        xmlconfig(StringIO(template % (
-            '''
-            <resource name="test"
-                  factory="zope.app.component.tests.views.R1"
-                  type="zope.app.component.tests.views.IV"/>
-            '''
-            )))
-
-        self.assertEqual(
-            zope.component.queryAdapter(Request(IV), name=u'test').__class__,
-            R1)
-
-    def testResourceThatProvidesAnInterface(self):
-        ob = Ob()
-        self.assertEqual(zope.component.queryAdapter(Request(IR), IV, u'test'),
-                         None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <resource
-                name="test"
-                factory="zope.app.component.tests.views.R1"
-                type="zope.app.component.tests.views.IR"
-                />
-            '''
-            ))
-
-        v = zope.component.queryAdapter(Request(IR), IV, name=u'test')
-        self.assertEqual(v, None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <resource
-                name="test"
-                factory="zope.app.component.tests.views.R1"
-                type="zope.app.component.tests.views.IR"
-                provides="zope.app.component.tests.views.IV"
-                />
-            '''
-            ))
-
-        v = zope.component.queryAdapter(Request(IR), IV, name=u'test')
-        self.assertEqual(v.__class__, R1)
-
-    def testUnnamedResourceThatProvidesAnInterface(self):
-        ob = Ob()
-        self.assertEqual(zope.component.queryAdapter(Request(IR), IV), None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <resource
-                factory="zope.app.component.tests.views.R1"
-                type="zope.app.component.tests.views.IR"
-                />
-            '''
-            ))
-
-        v = zope.component.queryAdapter(Request(IR), IV)
-        self.assertEqual(v, None)
-
-        xmlconfig(StringIO(template %
-            '''
-            <resource
-                factory="zope.app.component.tests.views.R1"
-                type="zope.app.component.tests.views.IR"
-                provides="zope.app.component.tests.views.IV"
-                />
-            '''
-            ))
-
-        v = zope.component.queryAdapter(Request(IR), IV)
-        self.assertEqual(v.__class__, R1)
-
-    def testResourceUndefinedPermission(self):
-
-        config = StringIO(template % (
-            '''
-            <resource name="test"
-                  factory="zope.app.component.tests.views.R1"
-                  type="zope.app.component.tests.views.IV"
-                  permission="zope.UndefinedPermission"/>
-            '''
-            ))
-        self.assertRaises(ValueError, xmlconfig, config, testing=1)
-
-
-class ParticipationStub(object):
-
-    def __init__(self, principal):
-        self.principal = principal
-        self.interaction = None
-
-
-def configfile(s):
-    return StringIO("""<configure
-      xmlns='http://namespaces.zope.org/zope'
-      i18n_domain='zope'>
-      %s
-      </configure>
-      """ % s)
-
-class TestFactoryDirective(PlacelessSetup, unittest.TestCase):
-    def setUp(self):
-        super(TestFactoryDirective, self).setUp()
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
-
-    def testFactory(self):
-        f = configfile('''
-<permission id="zope.Foo" title="Zope Foo Permission" />
-<class class="zope.app.component.tests.exampleclass.ExampleClass">
-    <factory
-      id="test.Example"
-      title="Example content"
-      description="Example description"
-       />
-</class>''')
-        xmlconfig(f)
-        obj = zope.component.createObject('test.Example')
-        self.failUnless(proxy.isinstance(obj, exampleclass.ExampleClass))
-
-
-
-PREFIX = module.__name__ + '.'
-
-def defineDirectives():
-    XMLConfig('meta.zcml', zope.app.component)()
-    XMLConfig('meta.zcml', zope.app.security)()
-    xmlconfig(StringIO("""<configure
-        xmlns='http://namespaces.zope.org/zope'
-        i18n_domain='zope'>
-       <permission id="zope.Extravagant" title="extravagant" />
-       <permission id="zope.Paltry" title="paltry" />
-    </configure>"""))
-
-NOTSET = []
-
-P1 = "zope.Extravagant"
-P2 = "zope.Paltry"
-
-class TestRequireDirective(PlacelessSetup, unittest.TestCase):
-
-    def setUp(self):
-        super(TestRequireDirective, self).setUp()
-        defineDirectives()
-
-        class B(object):
-            def m1(self):
-                return "m1"
-            def m2(self):
-                return "m2"
-        class C(B):
-            implements(module.I)
-            def m3(self):
-                return "m3"
-            def m4(self):
-                return "m4"
-        module.test_base = B
-        module.test_class = C
-        module.test_instance = C()
-        self.assertState()
-
-    def tearDown(self):
-        PlacelessSetup.tearDown(self)
-        module.test_class = None
-
-    def assertState(self, m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
-        "Verify that class, instance, and methods have expected permissions."
-
-        from zope.security.checker import selectChecker
-
-        checker = selectChecker(module.test_instance)
-        self.assertEqual(checker.permission_id('m1'), (m1P or None))
-        self.assertEqual(checker.permission_id('m2'), (m2P or None))
-        self.assertEqual(checker.permission_id('m3'), (m3P or None))
-
-    def assertDeclaration(self, declaration, **state):
-        apply_declaration(module.template_bracket % declaration)
-        self.assertState(**state)
-
-    # "testSimple*" exercises tags that do NOT have children.  This mode
-    # inherently sets the instances as well as the class attributes.
-
-    def testSimpleMethodsPlural(self):
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                attributes="m1 m3"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1))
-        self.assertDeclaration(declaration, m1P=P1, m3P=P1)
-
-    def assertSetattrState(self, m1P=NOTSET, m2P=NOTSET, m3P=NOTSET):
-        "Verify that class, instance, and methods have expected permissions."
-
-        from zope.security.checker import selectChecker
-
-        checker = selectChecker(module.test_instance)
-        self.assertEqual(checker.setattr_permission_id('m1'), (m1P or None))
-        self.assertEqual(checker.setattr_permission_id('m2'), (m2P or None))
-        self.assertEqual(checker.setattr_permission_id('m3'), (m3P or None))
-
-    def assertSetattrDeclaration(self, declaration, **state):
-        self.assertSetattrState(**state)
-
-    def test_set_attributes(self):
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                set_attributes="m1 m3"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1))
-        apply_declaration(module.template_bracket % declaration)
-        checker = selectChecker(module.test_instance)
-        self.assertEqual(checker.setattr_permission_id('m1'), P1)
-        self.assertEqual(checker.setattr_permission_id('m2'), None)
-        self.assertEqual(checker.setattr_permission_id('m3'), P1)
-
-    def test_set_schema(self):
-
-        self.assertEqual(queryInterface(PREFIX+"S"), None)
-
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                set_schema="%s"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1, PREFIX+"S"))
-        apply_declaration(module.template_bracket % declaration)
-
-        self.assertEqual(queryInterface(PREFIX+"S"), module.S)
-
-
-        checker = selectChecker(module.test_instance)
-        self.assertEqual(checker.setattr_permission_id('m1'), None)
-        self.assertEqual(checker.setattr_permission_id('m2'), None)
-        self.assertEqual(checker.setattr_permission_id('m3'), None)
-        self.assertEqual(checker.setattr_permission_id('foo'), P1)
-        self.assertEqual(checker.setattr_permission_id('bar'), P1)
-        self.assertEqual(checker.setattr_permission_id('baro'), None)
-
-    def test_multiple_set_schema(self):
-
-        self.assertEqual(queryInterface(PREFIX+"S"), None)
-        self.assertEqual(queryInterface(PREFIX+"S2"), None)
-
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                set_schema="%s %s"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1, PREFIX+"S", PREFIX+"S2"))
-        apply_declaration(module.template_bracket % declaration)
-
-        self.assertEqual(queryInterface(PREFIX+"S"), module.S)
-        self.assertEqual(queryInterface(PREFIX+"S2"), module.S2)
-
-
-        checker = selectChecker(module.test_instance)
-        self.assertEqual(checker.setattr_permission_id('m1'), None)
-        self.assertEqual(checker.setattr_permission_id('m2'), None)
-        self.assertEqual(checker.setattr_permission_id('m3'), None)
-        self.assertEqual(checker.setattr_permission_id('foo'), P1)
-        self.assertEqual(checker.setattr_permission_id('bar'), P1)
-        self.assertEqual(checker.setattr_permission_id('foo2'), P1)
-        self.assertEqual(checker.setattr_permission_id('bar2'), P1)
-        self.assertEqual(checker.setattr_permission_id('baro'), None)
-
-    def testSimpleInterface(self):
-
-        self.assertEqual(queryInterface(PREFIX+"I"), None)
-
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                interface="%s"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1, PREFIX+"I"))
-        # m1 and m2 are in the interface, so should be set, and m3 should not:
-        self.assertDeclaration(declaration, m1P=P1, m2P=P1)
-
-        # Make sure we know about the interfaces
-        self.assertEqual(queryInterface(PREFIX+"I"), module.I)
-
-
-    def testMultipleInterface(self):
-
-        self.assertEqual(queryInterface(PREFIX+"I3"), None)
-        self.assertEqual(queryInterface(PREFIX+"I4"), None)
-
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                interface="  %s
-                                             %s  "/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1, PREFIX+"I3", PREFIX+"I4"))
-        self.assertDeclaration(declaration, m3P=P1, m2P=P1)
-
-        # Make sure we know about the interfaces
-        self.assertEqual(queryInterface(PREFIX+"I3"), module.I3)
-        self.assertEqual(queryInterface(PREFIX+"I4"), module.I4)
-
-    # "testComposite*" exercises tags that DO have children.
-    # "testComposite*TopPerm" exercises tags with permission in containing tag.
-    # "testComposite*ElementPerm" exercises tags w/permission in children.
-
-    def testCompositeNoPerm(self):
-        # Establish rejection of declarations lacking a permission spec.
-        declaration = ('''<class class="%s">
-                            <require
-                                attributes="m1"/>
-                          </class>'''
-                       % (PREFIX+"test_class"))
-        self.assertRaises(ZopeXMLConfigurationError,
-                          self.assertDeclaration,
-                          declaration)
-
-
-
-    def testCompositeMethodsPluralElementPerm(self):
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                attributes="m1 m3"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1))
-        self.assertDeclaration(declaration,
-                               m1P=P1, m3P=P1)
-
-    def testCompositeInterfaceTopPerm(self):
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                interface="%s"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1, PREFIX+"I"))
-        self.assertDeclaration(declaration,
-                               m1P=P1, m2P=P1)
-
-
-    def testSubInterfaces(self):
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                interface="%s"/>
-                          </class>'''
-                       % (PREFIX+"test_class", P1, PREFIX+"I2"))
-        # m1 and m2 are in the interface, so should be set, and m3 should not:
-        self.assertDeclaration(declaration, m1P=P1, m2P=P1)
-
-
-    def testMimicOnly(self):
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                attributes="m1 m2"/>
-                          </class>
-                          <class class="%s">
-                            <require like_class="%s" />
-                          </class>
-                          ''' % (PREFIX+"test_base", P1,
-                PREFIX+"test_class", PREFIX+"test_base"))
-        # m1 and m2 are in the interface, so should be set, and m3 should not:
-        self.assertDeclaration(declaration,
-                               m1P=P1, m2P=P1)
-
-
-    def testMimicAsDefault(self):
-        declaration = ('''<class class="%s">
-                            <require
-                                permission="%s"
-                                attributes="m1 m2"/>
-                          </class>
-                          <class class="%s">
-                            <require like_class="%s" />
-                            <require
-                                permission="%s"
-                                attributes="m2 m3"/>
-                          </class>
-                          ''' % (PREFIX+"test_base", P1,
-                PREFIX+"test_class", PREFIX+"test_base", P2))
-
-        # m1 and m2 are in the interface, so should be set, and m3 should not:
-        self.assertDeclaration(declaration,
-                               m1P=P1, m2P=P2, m3P=P2)
-
-
-def apply_declaration(declaration):
-    '''Apply the xmlconfig machinery.'''
-    return xmlconfig(StringIO(declaration))
-
-
-def test_suite():
-    return unittest.TestSuite((
-        unittest.makeSuite(Test),
-        unittest.makeSuite(TestFactoryDirective),
-        unittest.makeSuite(TestRequireDirective),
-        DocTestSuite(),
-        ))
-
-if __name__ == "__main__":
-    unittest.TextTestRunner().run(test_suite())

Deleted: Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_vocabulary.py
===================================================================
--- Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_vocabulary.py	2009-01-27 12:39:29 UTC (rev 95154)
+++ Sandbox/faassen/zope.site/trunk/src/zope/site/tests/test_vocabulary.py	2009-01-27 12:43:38 UTC (rev 95155)
@@ -1,23 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""Vocabulary tests
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-import doctest
-
-
-def test_suite():
-    return doctest.DocTestSuite('zope.app.component.vocabulary')



More information about the Checkins mailing list