[Zope3-checkins]
SVN: Zope3/branches/srichter-blow-services/src/zope/app/component/
Started documentation/tests for sites and local site
managers. I think I
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Jan 5 17:49:38 EST 2005
Log message for revision 28738:
Started documentation/tests for sites and local site managers. I think I
made some good progress on it and I was able to port some of the simpler
helper component/function tests already.
Once this work is completed, I will attempt to make Zope run again,
though I think it will take a while before I will be able to do this,
since many views and directives will be broken.
Changed:
A Zope3/branches/srichter-blow-services/src/zope/app/component/README.txt
U Zope3/branches/srichter-blow-services/src/zope/app/component/fields.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/interfaces/__init__.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/site.py
A Zope3/branches/srichter-blow-services/src/zope/app/component/site.txt
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/adapter.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/exampleclass.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/factory.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/module.py
U Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_directives.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_factory.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_localservice.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_requirepermissions.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicedirective.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicemanagercontainer.py
A Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_site.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/tests/views.py
-=-
Added: Zope3/branches/srichter-blow-services/src/zope/app/component/README.txt
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/README.txt 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/README.txt 2005-01-05 22:49:38 UTC (rev 28738)
@@ -0,0 +1,32 @@
+=====================================
+Zope 3's Local Component Architecture
+=====================================
+
+
+Registration Framework
+----------------------
+
+
+Local Adapter Registry
+----------------------
+
+
+Local Site Manager
+------------------
+
+
+Persistent Module Registry
+--------------------------
+
+resolve
+findModule
+__import__
+
+
+Local API
+---------
+
+getNextSiteManager
+queryNextSiteManager
+getNextUtility
+queryNextUtility
\ No newline at end of file
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/fields.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/fields.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/fields.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -28,7 +28,7 @@
class LayerField(GlobalObject):
- r"""This fields represents a layer.
+ r"""This field represents a layer.
Besides being able to look up the layer by importing it, we also try
to look up the name in the utility service.
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/hooks.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -18,16 +18,8 @@
__docformat__ = 'restructuredtext'
import zope.component
-from zope.app.component.interfaces import ISite
-from zope.component.exceptions import ComponentLookupError
-from zope.security.proxy import removeSecurityProxy
-from zope.app.traversing.interfaces import IContainmentRoot
-from zope.app.location.interfaces import ILocation
-from zope.app.location import locate
-from zope.interface import Interface
-from zope.component.servicenames import Adapters
-import warnings
import zope.thread
+import zope.security
class read_property(object):
def __init__(self, func):
@@ -44,9 +36,7 @@
sm = zope.component.getGlobalSiteManager()
def adapter_hook(self):
- services = self.services
- adapters = services.getService(Adapters)
- adapter_hook = adapters.adapter_hook
+ adapter_hook = self.sm.adapters.adapter_hook
self.adapter_hook = adapter_hook
return adapter_hook
@@ -66,11 +56,11 @@
# once site managers do less. There's probably no good reason why
# they can't be proxied. Well, except maybe for performance.
- site = removeSecurityProxy(site)
+ site = zope.security.proxy.removeSecurityProxy(site)
sm = site.getSiteManager()
siteinfo.site = site
- siteinfo.services = sm
+ siteinfo.sm = sm
try:
del siteinfo.adapter_hook
except AttributeError:
@@ -82,7 +72,7 @@
def adapter_hook(interface, object, name='', default=None):
try:
return siteinfo.adapter_hook(interface, object, name, default)
- except ComponentLookupError:
+ except zope.component.exceptions.ComponentLookupError:
return default
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/interfaces/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/interfaces/__init__.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/interfaces/__init__.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -95,25 +95,16 @@
"""
class ILocalSiteManager(ISiteManager, IComponentManager,
+ registration.ILocatedRegistry,
registration.IRegistry):
- """Service Managers act as containers for Services.
+ """Site Managers act as containers for registerable components.
- If a Service Manager is asked for a service, it checks for those it
- contains before using a context-based lookup to find another service
+ If a Site Manager is asked for an adapter or utility, it checks for those it
+ contains before using a context-based lookup to find another site
manager to delegate to. If no other service manager is found they defer
to the ComponentArchitecture ServiceManager which contains file based
services.
"""
-
- def addSubsite(subsite):
- """Add a subsite of the site
-
- Local sites are connected in a tree. Each site knows about
- its containing sites and its subsites.
- """
-
- next = zope.interface.Attribute('The site that this site is a subsite of.')
-
def findModule(name):
"""Find the module of the given name.
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/site.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/site.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/site.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -25,12 +25,12 @@
$Id$
"""
import sys
-from zodbcode.module import PersistentModuleRegistry
+import zodbcode.module
import zope.event
import zope.interface
+import zope.component
from zope.component.exceptions import ComponentLookupError
-from zope.component.site import SiteManager
from zope.app import zapi
from zope.app.component import adapter
@@ -42,15 +42,17 @@
from zope.app.container.contained import Contained
from zope.app.container.interfaces import IContainer
from zope.app.event import objectevent
-from zope.app.location import inside
+from zope.app.filerepresentation.interfaces import IDirectoryFactory
from zope.app.traversing.interfaces import IContainmentRoot
-class SiteManagementFolder(RegisterableContainer, BTreeContainer):
- implements(interfaces.ISiteManagementFolder)
+class SiteManagementFolder(registration.RegisterableContainer,
+ BTreeContainer):
+ zope.interface.implements(interfaces.ISiteManagementFolder)
+
class SMFolderFactory(object):
- implements(IDirectoryFactory)
+ zope.interface.implements(IDirectoryFactory)
def __init__(self, context):
self.context = context
@@ -59,74 +61,119 @@
return SiteManagementFolder()
-class LocalSiteManager(BTreeContainer, PersistentModuleRegistry, SiteManager):
+class SiteManagerContainer(Contained):
+ """Implement access to the service manager (++etc++site).
+
+ This is a mix-in that implements the IPossibleSite
+ interface; for example, it is used by the Folder implementation.
+ """
+ zope.interface.implements(interfaces.IPossibleSite)
+
+ __sm = None
+
+ def getSiteManager(self):
+ if self.__sm is not None:
+ return self.__sm
+ else:
+ raise ComponentLookupError('no site manager defined')
+
+ def setSiteManager(self, sm):
+ if interfaces.ISite.providedBy(self):
+ raise TypeError("Already a site")
+
+ if zope.component.interfaces.ISiteManager.providedBy(sm):
+ self.__sm = sm
+ sm.__name__ = '++etc++site'
+ sm.__parent__ = self
+ else:
+ raise ValueError('setSiteManager requires an ISiteManager')
+
+ zope.interface.directlyProvides(
+ self, interfaces.ISite,
+ zope.interface.directlyProvidedBy(self))
+
+
+def findNextSiteManager(site):
+ next = None
+ while next is None:
+ if IContainmentRoot.providedBy(site):
+ # we're the root site, use the global sm
+ next = zapi.getGlobalSiteManager()
+
+ site = zapi.getParent(site)
+
+ if interfaces.ISite.providedBy(site):
+ next = site.getSiteManager()
+
+ return next
+
+
+class LocalSiteManager(BTreeContainer,
+ zodbcode.module.PersistentModuleRegistry,
+ zope.component.site.SiteManager):
"""Local Site Manager implementation"""
zope.interface.implements(
interfaces.ILocalSiteManager,
- interfaces.registrations.IRegisterableContainerContainer)
+ interfaces.registration.IRegisterableContainerContaining)
+ # See interfaces.registration.ILocatedRegistry
+ next = None
+ subs = ()
+ base = None
+
def __init__(self, site):
# Locate the site manager
self.__parent__ = site
self.__name__ = '++etc++site'
+
# Make sure everything is setup correctly
BTreeContainer.__init__(self)
- PersistentModuleRegistry.__init__(self)
+ zodbcode.module.PersistentModuleRegistry.__init__(self)
+
+ # Setup located registry attributes
+ self.base = zapi.getGlobalSiteManager()
+ next = findNextSiteManager(site)
+ if not zope.component.site.IGlobalSiteManager.providedBy(next):
+ self.setNext(next)
+
# Set up adapter registries
- self.adapters = adapter.LocalAdapterRegistry()
- self.utilities = adapter.LocalAdapterRegistry()
- # Initialize all links
- self.subSites = ()
- self._setNext(site)
+ gsm = zapi.getGlobalSiteManager()
+ self.adapters = adapter.LocalAdapterRegistry(gsm.adapters)
+ self.utilities = adapter.LocalAdapterRegistry(gsm.utilities)
+
# Setup default site management folder
folder = SiteManagementFolder()
zope.event.notify(objectevent.ObjectCreatedEvent(folder))
self['default'] = folder
- def _setNext(self, site):
- """Find and set the next site manager"""
- next = None
- while next is None:
- if IContainmentRoot.providedBy(site):
- # we're the root site, use the global sm
- next = zapi.getGlobalServices()
- site = zapi.getParent(site)
+ def addSub(self, sub):
+ """See interfaces.registration.ILocatedRegistry"""
+ self.subs += (sub, )
- if ISite.providedBy(site):
- next = site.getSiteManager()
- next.addSubsite(self)
- return
+ def removeSub(self, sub):
+ """See interfaces.registration.ILocatedRegistry"""
+ self.subs = tuple(
+ [s for s in self.subs if s is not sub] )
+ def setNext(self, next, base=None):
+ """See interfaces.registration.ILocatedRegistry"""
+ if base is not None:
+ self.base = base
+ if self.next is not None:
+ self.next.removeSub(self)
+ if next is not None:
+ next.addSub(self)
self.next = next
- self.adapters.setNextRegistry(next.adapters)
- self.utilities.setNextRegistry(next.utilities)
+ self.adapaters.setNext(next.adapters)
+ self.utilities.setNext(next.adapters)
-
- def addSubsite(self, sub):
- """See ILocalSiteManager interface"""
- subsite = sub.__parent__
-
- # Update any sites that are now in the subsite:
- subsites = []
- for s in self.subSites:
- if inside(s, subsite):
- s.next = sub
- sub.addSubsite(s)
- else:
- subsites.append(s)
-
- subsites.append(sub)
- self.subSites = tuple(subsites)
- self.adapters.addSubRegistry(sub.adapters)
- self.utilities.addSubRegistry(sub.utilities)
-
def __getRegistry(registration):
"""Determine the correct registry for the registration."""
- if IAdapterRegistration.providedBy(registration):
+ if interfaces.IUtilityRegistration.providedBy(registration):
+ return self.utilities
+ elif interfaces.IAdapterRegistration.providedBy(registration):
return self.adapters
- elif IUtilityRegistration.providedBy(registration):
- return self.utilities
raise ValueError, \
("Unable to detect registration type or registration "
"type is not supported. The registration object must provide "
@@ -261,7 +308,7 @@
zope.interface.implements(interfaces.IUtilityRegistration)
############################################################
- # To make adapter code happy. Are we going too far?
+ # Make the adapter code happy.
required = zope.interface.adapter.Null
with = ()
############################################################
@@ -293,3 +340,38 @@
# Clear the site thread global
clearSite = setSite
+from zope.testing.cleanup import addCleanUp
+addCleanUp(clearSite)
+
+
+def SiteManagerAdapter(ob):
+ """An adapter from ILocation to ISiteManager.
+
+ The ILocation is interpreted flexibly, we just check for
+ ``__parent__``.
+ """
+ current = ob
+ while True:
+ if interfaces.ISite.providedBy(current):
+ return current.getSiteManager()
+ current = getattr(current, '__parent__', None)
+ if current is None:
+ raise ComponentLookupError(
+ "Could not adapt %r to ISiteManager" %ob)
+
+
+def threadSiteSubscriber(event):
+ """A subscriber to BeforeTraverseEvent
+
+ Sets the 'site' thread global if the object traversed is a site.
+ """
+ if interfaces.ISite.providedBy(event.object):
+ setSite(event.object)
+
+
+def clearThreadSiteSubscriber(event):
+ """A subscriber to EndRequestEvent
+
+ Cleans up the site thread global after the request is processed.
+ """
+ clearSite()
Added: Zope3/branches/srichter-blow-services/src/zope/app/component/site.txt
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/site.txt 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/site.txt 2005-01-05 22:49:38 UTC (rev 28738)
@@ -0,0 +1,78 @@
+=============================
+Sites and Local Site Managers
+=============================
+
+
+
+Creating Sites
+--------------
+
+*Sites* are used to provide custom component setups for parts of your
+application or Web site. Every folder,
+
+ >>> from zope.app.folder import folder
+ >>> myfolder = folder.Folder()
+
+has the potential to become a site
+
+ >>> from zope.app.component import interfaces
+ >>> interfaces.IPossibleSite.providedBy(myfolder)
+ True
+
+but is not yet one:
+
+ >>> interfaces.ISite.providedBy(myfolder)
+ False
+
+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
+ >>> class MyContentComponent(site.SiteManagerContainer):
+ ... pass
+
+ >>> myContent = MyContentComponent()
+ >>> interfaces.IPossibleSite.providedBy(myContent)
+ True
+ >>> interfaces.ISite.providedBy(myContent)
+ False
+
+
+
+
+ def test_get_and_set(self):
+ smc = self.makeTestObject()
+ self.failIf(ISite.providedBy(smc))
+ sm = ServiceManager()
+ smc.setSiteManager(sm)
+ self.failUnless(ISite.providedBy(smc))
+ self.failUnless(smc.getSiteManager() is sm)
+ verifyObject(ISite, smc)
+
+ def test_set_w_bogus_value(self):
+ smc=self.makeTestObject()
+ self.assertRaises(Exception, smc.setSiteManager, self)
+
+
+
+class Test(BaseTestServiceManagerContainer, TestCase):
+ def makeTestObject(self):
+ from zope.app.site.servicecontainer import ServiceManagerContainer
+ return ServiceManagerContainer()
+
+
+SiteManagerAdapter
+
+
+
+The Registry
+++++++++++++
+
+register
+unregister
+registrations
+registered
+
+setNext
+next
+subs
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/adapter.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/adapter.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/adapter.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,50 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""Sample adapter class for testing
-
-$Id$
-"""
-
-import zope.interface
-
-class I1(zope.interface.Interface):
- pass
-
-class I2(zope.interface.Interface):
- pass
-
-class I3(zope.interface.Interface):
- pass
-
-class IS(zope.interface.Interface):
- pass
-
-
-class Adapter(object):
- def __init__(self, *args):
- self.context = args
-
-class A1(Adapter):
- zope.interface.implements(I1)
-
-class A2(Adapter):
- zope.interface.implements(I2)
-
-class A3(Adapter):
- zope.interface.implements(I3)
-
-
-def Handler(content, *args):
- # uninteresting handler
- content.args = getattr(content, 'args', ()) + (args, )
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/exampleclass.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/exampleclass.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/exampleclass.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,30 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 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.
-#
-##############################################################################
-"""Example test classes
-
-$Id$
-"""
-from zope.interface import Interface
-
-class ExampleClass(object):
- pass
-
-class IExample(Interface):
- pass
-
-class IExample2(Interface):
- pass
-
-class IExampleContainer(Interface):
- pass
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/factory.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/factory.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/factory.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,44 +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.
-#
-##############################################################################
-"""Factory tests.
-
-$Id$
-"""
-from zope.component.interfaces import IFactory
-from zope.interface import Interface, implements, implementedBy
-
-class IX(Interface):
- """the dummy interface which class X supposedly implements,
- according to the factory"""
-
-class IFoo(Interface):
- """an even more dummy interface just for testing """
-
-class X(object):
- implements(IX)
- def __init__(self, *args, **kwargs):
- self.args=args
- self.kwargs=kwargs
-
-
-class ClassFactoryWrapper(object):
- implements(IFactory)
- def __init__(self, klass):
- self.__klass=klass
- def __call__(self, *args, **kwargs):
- return self.__klass(*args, **kwargs)
- def getInterfaces(self):
- return implementedBy(self.__klass)
-
-f=ClassFactoryWrapper(X)
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/module.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/module.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/module.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,58 +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.
-#
-##############################################################################
-"""Preliminaries to hookup a test suite with the external TestModule.
-
-This is necessary because the test framework interferes with seeing changes in
-the running modules via the module namespace. This enables having some
-subject classes, instances, permissions, etc, that don't live in the test
-modules, themselves.
-
-$Id$
-"""
-from zope.interface import Interface
-from zope.schema import Text
-
-class I(Interface):
- def m1():
- pass
- def m2():
- pass
-
-class I2(I):
- def m4():
- pass
-
-class I3(Interface):
- def m3():
- pass
-
-class I4(Interface):
- def m2():
- pass
-
-
-class S(Interface):
- foo = Text()
- bar = Text()
- baro = Text(readonly=True)
-
-class S2(Interface):
- foo2 = Text()
- bar2 = Text()
-
-
-template_bracket = """<configure
- xmlns="http://namespaces.zope.org/zope">
- %s
-</configure>"""
Modified: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_directives.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_directives.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_directives.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -943,9 +943,319 @@
from factory import X
self.assertEqual(zapi.createObject(None, 'foo.bar').__class__, X)
+
+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(Test, 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" />
+<content class="zope.app.component.tests.exampleclass.ExampleClass">
+ <factory
+ id="test.Example"
+ title="Example content"
+ description="Example description"
+ />
+</content>''')
+ xmlconfig(f)
+ obj = createObject(None, 'test.Example')
+ self.failUnless(zapi.isinstance(obj, 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(Test, 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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ attributes="m1 m3"/>
+ </content>"""
+ % (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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ set_attributes="m1 m3"/>
+ </content>"""
+ % (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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ set_schema="%s"/>
+ </content>"""
+ % (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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ set_schema="%s %s"/>
+ </content>"""
+ % (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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ interface="%s"/>
+ </content>"""
+ % (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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ interface=" %s
+ %s "/>
+ </content>"""
+ % (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 = ("""<content class="%s">
+ <require
+ attributes="m1"/>
+ </content>"""
+ % (PREFIX+"test_class"))
+ self.assertRaises(ZopeXMLConfigurationError,
+ self.assertDeclaration,
+ declaration)
+
+
+
+ def testCompositeMethodsPluralElementPerm(self):
+ declaration = ("""<content class="%s">
+ <require
+ permission="%s"
+ attributes="m1 m3"/>
+ </content>"""
+ % (PREFIX+"test_class", P1))
+ self.assertDeclaration(declaration,
+ m1P=P1, m3P=P1)
+
+ def testCompositeInterfaceTopPerm(self):
+ declaration = ("""<content class="%s">
+ <require
+ permission="%s"
+ interface="%s"/>
+ </content>"""
+ % (PREFIX+"test_class", P1, PREFIX+"I"))
+ self.assertDeclaration(declaration,
+ m1P=P1, m2P=P1)
+
+
+ def testSubInterfaces(self):
+ declaration = ("""<content class="%s">
+ <require
+ permission="%s"
+ interface="%s"/>
+ </content>"""
+ % (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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ attributes="m1 m2"/>
+ </content>
+ <content class="%s">
+ <require like_class="%s" />
+ </content>
+ """ % (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 = ("""<content class="%s">
+ <require
+ permission="%s"
+ attributes="m1 m2"/>
+ </content>
+ <content class="%s">
+ <require like_class="%s" />
+ <require
+ permission="%s"
+ attributes="m2 m3"/>
+ </content>
+ """ % (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(),
))
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_factory.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_factory.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_factory.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,73 +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 handler for 'factory' subdirective of 'content' directive
-
-$Id$
-"""
-import unittest
-from cStringIO import StringIO
-
-from zope.configuration.xmlconfig import xmlconfig
-from zope.configuration.xmlconfig import XMLConfig
-from zope.component import createObject
-from zope.app.tests.placelesssetup import PlacelessSetup
-
-from zope.app import zapi
-import zope.app.security
-import zope.app.component
-
-from zope.app.component.tests.exampleclass import ExampleClass
-
-
-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 Test(PlacelessSetup, unittest.TestCase):
- def setUp(self):
- super(Test, 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" />
-<content class="zope.app.component.tests.exampleclass.ExampleClass">
- <factory
- id="test.Example"
- title="Example content"
- description="Example description"
- />
-</content>''')
- xmlconfig(f)
- obj = createObject(None, 'test.Example')
- self.failUnless(zapi.isinstance(obj, ExampleClass))
-
-def test_suite():
- loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run(test_suite())
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_localservice.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_localservice.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_localservice.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,274 +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 local service code
-
-$Id$
-"""
-import unittest
-from zope.component import getGlobalServices
-from zope.app.component.hooks import getServices_hook
-from zope.app.component.localservice import serviceServiceAdapter
-from zope.app.site.interfaces import IPossibleSite, ISite, ISiteManager
-from zope.app.traversing.interfaces import IContainmentRoot
-from zope.component.exceptions import ComponentLookupError
-from zope.component.interfaces import IServiceService
-from zope.component.service import serviceManager
-from zope.interface import implements, directlyProvides, directlyProvidedBy
-from zope.interface.verify import verifyObject
-from zope.testing import doctest
-
-from zope.app.tests.setup import placelessSetUp, placelessTearDown
-from zope.app.tests import ztapi
-from zope.app.component.hooks import setSite, getSite
-
-class ServiceManager(object):
- implements(ISiteManager)
-
- def __init__(self):
- self.dummy_service = object()
-
- def getService(self, name):
- if name == 'dummy':
- return self.dummy_service
- raise ComponentLookupError(name)
-
-class Folder(object):
- implements(IPossibleSite)
-
- sm = None
-
- def getSiteManager(self, default=None):
- return self.sm
-
- def setSiteManager(self, sm):
- self.sm = sm
- sm.__parent__ = self
- directlyProvides(self, ISite, directlyProvidedBy(self))
-
-class Package(object):
- pass
-
-class Root(Folder):
- implements(IContainmentRoot, ISite)
- def getSiteManager(self):
- return getGlobalServices()
-
-class ServiceServiceStub(object):
- implements(IServiceService)
-
-
-def Wrapper(ob, container):
- ob.__parent__ = container
- return ob
-
-class Test(unittest.TestCase):
-
- def setUp(self):
- unittest.TestCase.setUp(self)
- placelessSetUp()
- root = Root()
-
- f1 = Wrapper(Folder(), root)
- sm1 = ServiceManager()
- f1.setSiteManager(sm1)
- p1 = Wrapper(Package(), sm1)
-
- f2 = Wrapper(Folder(), f1)
- sm2 = ServiceManager()
- f2.setSiteManager(sm2)
- p2 = Wrapper(Package(), sm2)
-
- sm1.next = serviceManager
- sm2.next = sm1
-
- self.root = root
- self.f1 = f1
- self.f2 = f2
- self.sm1 = sm1
- self.sm2 = sm2
- self.p1 = p1
- self.p2 = p2
- self.unparented_folder = Folder()
- self.unrooted_subfolder = Wrapper(Folder(), self.unparented_folder)
-
- ztapi.provideAdapter(None, IServiceService, serviceServiceAdapter)
-
- def tearDown(self):
- setSite()
- placelessTearDown()
-
- def test_getServices(self):
- self.assertEqual(getServices_hook(None), serviceManager)
- self.assertEqual(getServices_hook(self.root), serviceManager)
- self.assertEqual(getServices_hook(self.f1), self.sm1)
- self.assertEqual(getServices_hook(self.f2), self.sm2)
- setSite(self.f2)
- self.assertEqual(getServices_hook(None), self.sm2)
-
- def test_queryNextService(self):
- from zope.app.component.localservice import queryNextService
- self.assert_(queryNextService(self.sm2, 'dummy') is
- self.sm1.dummy_service)
- self.assert_(queryNextService(self.p2, 'dummy') is
- self.sm1.dummy_service)
- marker = object()
- self.assert_(queryNextService(self.p1, 'dummy', marker) is marker)
-
- def test_getNextService(self):
- from zope.app.component.localservice import getNextService
- self.assert_(getNextService(self.sm2, 'dummy') is
- self.sm1.dummy_service)
- self.assert_(getNextService(self.p2, 'dummy') is
- self.sm1.dummy_service)
- self.assertRaises(ComponentLookupError,
- getNextService, self.p1, 'dummy')
-
-
- def test_queryNextServices(self):
- from zope.app.component.localservice import queryNextServices
- marker = object()
- self.assert_(queryNextServices(self.root, marker) is marker)
- self.assert_(queryNextServices(self.f1, marker) is marker)
- self.assert_(queryNextServices(self.f2, marker) is marker)
- self.assertEqual(queryNextServices(self.sm1), serviceManager)
- self.assertEqual(queryNextServices(self.sm2), self.sm1)
- self.assertEqual(queryNextServices(self.p1), serviceManager)
- self.assertEqual(queryNextServices(self.p2), self.sm1)
-
- self.assert_(queryNextServices(self.unparented_folder, marker)
- is marker)
- self.assert_(queryNextServices(self.unrooted_subfolder, marker)
- is marker)
-
- def test_getNextServices(self):
- from zope.app.component.localservice import getNextServices
- self.assertRaises(ComponentLookupError,
- getNextServices, self.root)
- self.assertRaises(ComponentLookupError,
- getNextServices, self.f1)
- self.assertRaises(ComponentLookupError,
- getNextServices, self.f2)
- self.assertEqual(getNextServices(self.sm1), serviceManager)
- self.assertEqual(getNextServices(self.sm2), self.sm1)
- self.assertEqual(getNextServices(self.p1), serviceManager)
- self.assertEqual(getNextServices(self.p2), self.sm1)
-
- self.assertRaises(ComponentLookupError,
- getNextServices, self.unparented_folder)
- self.assertRaises(ComponentLookupError,
- getNextServices, self.unrooted_subfolder)
-
- def test_getNextServices_security(self):
- from zope.app.component.localservice import getNextServices
- from zope.security.checker import ProxyFactory, NamesChecker
- sm = ProxyFactory(self.sm1, NamesChecker(('next',)))
- # Check that serviceManager is not proxied
- self.assert_(getNextServices(sm) is serviceManager)
-
- def test_queryLocalServices(self):
- from zope.app.component.localservice import queryLocalServices
- marker = object()
- self.assert_(queryLocalServices(self.root, marker) is marker)
- self.assert_(queryLocalServices(self.f1, marker) is marker)
- self.assert_(queryLocalServices(self.f2, marker) is marker)
- self.assertEqual(queryLocalServices(self.sm1), self.sm1)
- self.assertEqual(queryLocalServices(self.sm2), self.sm2)
- self.assertEqual(queryLocalServices(self.p1), self.sm1)
- self.assertEqual(queryLocalServices(self.p2), self.sm2)
-
- self.assert_(queryLocalServices(self.unparented_folder, marker)
- is marker)
- self.assert_(queryLocalServices(self.unrooted_subfolder, marker)
- is marker)
-
- def test_getLocalServices(self):
- from zope.app.component.localservice import getLocalServices
- self.assertRaises(ComponentLookupError,
- getLocalServices, self.root)
- self.assertRaises(ComponentLookupError,
- getLocalServices, self.f1)
- self.assertRaises(ComponentLookupError,
- getLocalServices, self.f2)
- self.assertEqual(getLocalServices(self.sm1), self.sm1)
- self.assertEqual(getLocalServices(self.sm2), self.sm2)
- self.assertEqual(getLocalServices(self.p1), self.sm1)
- self.assertEqual(getLocalServices(self.p2), self.sm2)
-
- unparented_folder = Folder()
- self.assertRaises(ComponentLookupError,
- getLocalServices, unparented_folder)
- unrooted_subfolder = Wrapper(Folder(), unparented_folder)
- self.assertRaises(ComponentLookupError,
- getLocalServices, unrooted_subfolder)
-
- def test_serviceServiceAdapter(self):
- from zope.app.component.localservice import serviceServiceAdapter
-
- # If it is a site, return the service service.
- ss = ServiceServiceStub()
- site = Folder()
- site.setSiteManager(ss)
- self.assertEqual(serviceServiceAdapter(site), ss)
-
- # If it is locatable (has __parent__), "acquire" the site
- # and return the service service
- ob = Folder()
- ob.__parent__ = site
- self.assertEqual(serviceServiceAdapter(ob), ss)
- ob2 = Folder()
- ob2.__parent__ = ob
- self.assertEqual(serviceServiceAdapter(ob2), ss)
-
- # If it does we are unable to find a service service, raise
- # ComponentLookupError
- orphan = Folder()
- self.assertRaises(ComponentLookupError, serviceServiceAdapter, orphan)
-
- def test_setThreadSite_clearThreadSite(self):
- from zope.app.component.localservice import threadSiteSubscriber
- from zope.app.component.localservice import clearSite
- from zope.app.publication.zopepublication import BeforeTraverseEvent
-
- self.assertEqual(getSite(), None)
-
- # A non-site is traversed
- ob = object()
- request = object()
- ev = BeforeTraverseEvent(ob, request)
- threadSiteSubscriber(ev)
-
- self.assertEqual(getSite(), None)
-
- # A site is traversed
- ss = ServiceServiceStub()
- site = Folder()
- site.setSiteManager(ss)
-
- ev = BeforeTraverseEvent(site, request)
- threadSiteSubscriber(ev)
-
- self.assertEqual(getSite(), site)
-
- clearSite()
-
- self.assertEqual(getSite(), None)
-
-
-def test_suite():
- suite = unittest.makeSuite(Test)
- suite.addTest(doctest.DocTestSuite('zope.app.component.localservice'))
- return suite
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_requirepermissions.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_requirepermissions.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_requirepermissions.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,308 +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 handler for 'require' subdirective of 'content' directive
-
-$Id$
-"""
-from cStringIO import StringIO
-import unittest
-
-import zope.app.component
-import zope.app.security
-
-from zope.app.component.interface import queryInterface
-from zope.app.component.tests import module
-from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.checker import selectChecker
-from zope.interface import implements
-
-# So we can use config parser to exercise protectClass stuff.
-from zope.configuration.xmlconfig import XMLConfig
-from zope.configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
-
-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 Test(PlacelessSetup, unittest.TestCase):
-
- def setUp(self):
- super(Test, 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 = ("""<content class="%s">
- <require
- permission="%s"
- attributes="m1 m3"/>
- </content>"""
- % (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 = ("""<content class="%s">
- <require
- permission="%s"
- set_attributes="m1 m3"/>
- </content>"""
- % (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 = ("""<content class="%s">
- <require
- permission="%s"
- set_schema="%s"/>
- </content>"""
- % (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 = ("""<content class="%s">
- <require
- permission="%s"
- set_schema="%s %s"/>
- </content>"""
- % (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 = ("""<content class="%s">
- <require
- permission="%s"
- interface="%s"/>
- </content>"""
- % (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 = ("""<content class="%s">
- <require
- permission="%s"
- interface=" %s
- %s "/>
- </content>"""
- % (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 = ("""<content class="%s">
- <require
- attributes="m1"/>
- </content>"""
- % (PREFIX+"test_class"))
- self.assertRaises(ZopeXMLConfigurationError,
- self.assertDeclaration,
- declaration)
-
-
-
- def testCompositeMethodsPluralElementPerm(self):
- declaration = ("""<content class="%s">
- <require
- permission="%s"
- attributes="m1 m3"/>
- </content>"""
- % (PREFIX+"test_class", P1))
- self.assertDeclaration(declaration,
- m1P=P1, m3P=P1)
-
- def testCompositeInterfaceTopPerm(self):
- declaration = ("""<content class="%s">
- <require
- permission="%s"
- interface="%s"/>
- </content>"""
- % (PREFIX+"test_class", P1, PREFIX+"I"))
- self.assertDeclaration(declaration,
- m1P=P1, m2P=P1)
-
-
- def testSubInterfaces(self):
- declaration = ("""<content class="%s">
- <require
- permission="%s"
- interface="%s"/>
- </content>"""
- % (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 = ("""<content class="%s">
- <require
- permission="%s"
- attributes="m1 m2"/>
- </content>
- <content class="%s">
- <require like_class="%s" />
- </content>
- """ % (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 = ("""<content class="%s">
- <require
- permission="%s"
- attributes="m1 m2"/>
- </content>
- <content class="%s">
- <require like_class="%s" />
- <require
- permission="%s"
- attributes="m2 m3"/>
- </content>
- """ % (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():
- loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run(test_suite())
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicedirective.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicedirective.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicedirective.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,196 +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.
-#
-##############################################################################
-"""Service Directive Tests
-
-$Id$
-"""
-import unittest
-from cStringIO import StringIO
-
-from zope.security.interfaces import Forbidden, Unauthorized
-
-from zope.configuration.xmlconfig import testxmlconfig as xmlconfig, XMLConfig
-from zope.configuration.config import ConfigurationConflictError
-from zope.security.proxy import ProxyFactory
-from zope.component.exceptions import ComponentLookupError
-
-import zope.app.component
-from zope.component import getService
-from zope.app.tests.placelesssetup import PlacelessSetup
-
-
-class ParticipationStub(object):
-
- def __init__(self, principal):
- self.principal = principal
- self.interaction = None
-
-
-# TODO: tests for other directives needed
-
-template = """<configure
- xmlns='http://namespaces.zope.org/zope'
- xmlns:test='http://www.zope.org/NS/Zope3/test'
- i18n_domain='zope'>
- %s
- </configure>"""
-
-class Test(PlacelessSetup, unittest.TestCase):
-
-
- def setUp(self):
- super(Test, self).setUp()
- XMLConfig('meta.zcml', zope.app.component)()
-
- def testServiceConfigNoType(self):
- from zope.component.service \
- import UndefinedService
- self.assertRaises(
- UndefinedService,
- xmlconfig,
- StringIO(template % (
- '''
- <service
- serviceType="Foo"
- component="zope.app.component.tests.service.fooService"
- />
- '''
- )))
-
- def testDuplicateServiceConfig(self):
- self.assertRaises(
- ConfigurationConflictError,
- xmlconfig,
- StringIO(template % (
- '''
- <serviceType
- id="Foo"
- interface="zope.app.component.tests.service.IFooService"
- />
- <service
- serviceType="Foo"
- component="zope.app.component.tests.service.fooService"
- />
- <service
- serviceType="Foo"
- component="zope.app.component.tests.service.foo2"
- />
- '''
- )))
-
- def testServiceConfig(self):
- self.assertRaises(ComponentLookupError, getService, "Foo")
-
- xmlconfig(StringIO(template % (
- '''
- <serviceType
- id="Foo"
- interface="zope.app.component.tests.service.IFooService"
- />
- <service
- serviceType="Foo"
- component="zope.app.component.tests.service.fooService"
- />
- '''
- )))
-
- service = getService("Foo")
- self.assertEqual(service.foo(), "foo here")
- self.assertEqual(service.foobar(), "foobarred")
- self.assertEqual(service.bar(), "you shouldn't get this")
-
- def testServiceFactoryConfig(self):
- self.assertRaises(ComponentLookupError, getService, "Foo")
-
- xmlconfig(StringIO(template % (
- '''
- <serviceType
- id="Foo"
- interface="zope.app.component.tests.service.IFooService"
- />
- <service
- serviceType="Foo"
- factory="zope.app.component.tests.service.FooService"
- />
- '''
- )))
-
- service = getService("Foo")
- self.assertEqual(service.foo(), "foo here")
- self.assertEqual(service.foobar(), "foobarred")
- self.assertEqual(service.bar(), "you shouldn't get this")
-
- def testPublicProtectedServiceConfig(self):
- self.assertRaises(ComponentLookupError, getService, "Foo")
-
- xmlconfig(StringIO(template % (
- '''
- <serviceType
- id="Foo"
- interface="zope.app.component.tests.service.IFooService"
- />
- <service
- serviceType="Foo"
- component="zope.app.component.tests.service.fooService"
- permission="zope.Public"
- />
- '''
- )))
-
- service = getService("Foo")
- service = ProxyFactory(service) # simulate untrusted code!
- self.assertEqual(service.foo(), "foo here")
- self.assertEqual(service.foobar(), "foobarred")
- self.assertRaises(Forbidden, getattr, service, 'bar')
-
- def testProtectedServiceConfig(self):
- self.assertRaises(ComponentLookupError, getService, "Foo")
-
- xmlconfig(StringIO(template % (
- '''
- <include package="zope.app.security" file="meta.zcml" />
-
- <permission id="zope.TestPermission" title="Test permission" />
-
- <serviceType
- id="Foo"
- interface="zope.app.component.tests.service.IFooService"
- />
- <service
- serviceType="Foo"
- component="zope.app.component.tests.service.fooService"
- permission="zope.TestPermission"
- />
- '''
- )))
-
- # Need to "log someone in" to turn on checks
- from zope.security.management import newInteraction, endInteraction
- endInteraction()
- newInteraction(ParticipationStub('someuser'))
-
- service = getService("Foo")
- service = ProxyFactory(service) # simulate untrusted code!
-
- self.assertRaises(Unauthorized, getattr, service, 'foo')
- self.assertRaises(Unauthorized, getattr, service, 'foobar')
- self.assertRaises(Forbidden, getattr, service, 'bar')
-
-
-def test_suite():
- loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run(test_suite())
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicemanagercontainer.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicemanagercontainer.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_servicemanagercontainer.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,83 +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.
-#
-##############################################################################
-"""Service Manager Container Tests
-
-$Id$
-"""
-from unittest import TestCase, main, makeSuite
-from zope.component.interfaces import IServiceService
-from zope.app.site.interfaces import IPossibleSite, ISite
-from zope.component.exceptions import ComponentLookupError
-from zope.interface.verify import verifyObject
-from zope.interface import implements
-
-class ServiceManager(object):
-
- implements(IServiceService)
-
- ############################################################
- # Implementation methods for interface
- # IServiceService.
-
- def getService(self, object, name):
- '''See interface IServiceService'''
- raise ComponentLookupError(name)
-
- def getServiceDefinitions(self):
- '''See interface IServiceService'''
- return ()
-
- #
- ############################################################
-
-class BaseTestServiceManagerContainer(object):
-
- """This test is for objects that don't have service managers by
- default and that always give back the service manager they were
- given.
-
-
- Subclasses need to define a method, 'makeTestObject', that takes no
- arguments and that returns a new service manager
- container that has no service manager."""
-
- def test_IPossibleSite_verify(self):
- verifyObject(IPossibleSite, self.makeTestObject())
-
- def test_get_and_set(self):
- smc = self.makeTestObject()
- self.failIf(ISite.providedBy(smc))
- sm = ServiceManager()
- smc.setSiteManager(sm)
- self.failUnless(ISite.providedBy(smc))
- self.failUnless(smc.getSiteManager() is sm)
- verifyObject(ISite, smc)
-
- def test_set_w_bogus_value(self):
- smc=self.makeTestObject()
- self.assertRaises(Exception, smc.setSiteManager, self)
-
-
-
-class Test(BaseTestServiceManagerContainer, TestCase):
- def makeTestObject(self):
- from zope.app.site.servicecontainer import ServiceManagerContainer
- return ServiceManagerContainer()
-
-
-def test_suite():
- return makeSuite(Test)
-
-if __name__=='__main__':
- main(defaultTest='test_suite')
Added: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_site.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_site.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/test_site.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -0,0 +1,144 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Registration Tests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import unittest
+
+import zope.interface
+from zope.testing import doctest
+
+from zope.app.testing import setup
+from zope.app.component import interfaces
+from zope.app.folder import folder
+
+class SiteManagerStub(object):
+ zope.interface.implements(interfaces.ILocalSiteManager)
+
+class CustomFolder(folder.Folder):
+
+ def __init__(self, name):
+ self.__name__ = name
+ super(CustomFolder, self).__init__()
+
+ def __repr__(self):
+ return '<%s %s>' %(self.__class__.__name__, self.__name__)
+
+
+def test_SiteManagerAdapter():
+ """
+ The site manager adapter is used to find the nearest site for any given
+ location. If the provided context is a site,
+
+ >>> site = folder.Folder()
+ >>> sm = SiteManagerStub()
+ >>> site.setSiteManager(sm)
+
+ then the adapter simply return's the site's site manager:
+
+ >>> from zope.app.component.site import SiteManagerAdapter
+ >>> SiteManagerAdapter(site) is sm
+ True
+
+ If the context is a location (i.e. has a `__parent__` attribute),
+
+ >>> ob = folder.Folder()
+ >>> ob.__parent__ = site
+ >>> ob2 = folder.Folder()
+ >>> ob2.__parent__ = ob
+
+ we 'acquire' the closest site and return its site manager:
+
+ >>> SiteManagerAdapter(ob) is sm
+ True
+ >>> SiteManagerAdapter(ob2) is sm
+ True
+
+ If we are unable to find a site manager, a `ComponentLookupError` is
+ raised:
+
+ >>> orphan = CustomFolder('orphan')
+ >>> SiteManagerAdapter(orphan) #doctest: +NORMALIZE_WHITESPACE
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError:
+ 'Could not adapt <CustomFolder orphan> to ISiteManager'
+ """
+
+
+def test_setThreadSite_clearThreadSite():
+ """
+ This test ensures that the site is corectly set and cleared in a thread
+ during traversal using event subscribers. Before we start, no site is set:
+
+ >>> from zope.app.component import hooks
+ >>> hooks.getSite() is None
+ True
+
+ If a non-site is traversed,
+
+ >>> ob = object()
+ >>> request = object()
+
+ >>> from zope.app import publication
+ >>> ev = publication.interfaces.BeforeTraverseEvent(ob, request)
+ >>> from zope.app.component import site
+ >>> site.threadSiteSubscriber(ev)
+
+ still no site is set:
+
+ >>> hooks.getSite() is None
+ True
+
+ On the other hand, if a site is traversed,
+
+ >>> sm = SiteManagerStub()
+ >>> mysite = CustomFolder('mysite')
+ >>> mysite.setSiteManager(sm)
+
+ >>> ev = publication.interfaces.BeforeTraverseEvent(mysite, request)
+ >>> site.threadSiteSubscriber(ev)
+
+ >>> hooks.getSite()
+ <CustomFolder mysite>
+
+ Once the request is completed,
+
+ >>> ev = publication.interfaces.EndRequestEvent(mysite, request)
+ >>> site.clearThreadSiteSubscriber(ev)
+
+ the site assignment is cleared again:
+
+ >>> hooks.getSite() is None
+ True
+ """
+
+def setUp(test):
+ setup.placefulSetUp()
+
+def tearDown(test):
+ setup.placefulTearDown()
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ doctest.DocFileSuite('../site.txt',
+ setUp=setUp, tearDown=tearDown),
+ ))
+
+if __name__ == "__main__":
+ unittest.main(defaultTest='test_suite')
+
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/tests/views.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/component/tests/views.py 2005-01-05 22:38:27 UTC (rev 28737)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/tests/views.py 2005-01-05 22:49:38 UTC (rev 28738)
@@ -1,60 +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.
-#
-##############################################################################
-"""Views test.
-
-$Id$
-"""
-from zope.interface import Interface, implements
-
-class IR(Interface):
- pass
-
-class IV(Interface):
- def index():
- pass
-
-class IC(Interface): pass
-
-class V1(object):
- implements(IV)
-
- def __init__(self, context, request):
- self.context = context
- self.request = request
-
- def index(self):
- return 'V1 here'
-
- def action(self):
- return 'done'
-
-class VZMI(V1):
- def index(self):
- return 'ZMI here'
-
-class R1(object):
-
- def index(self):
- return 'R1 here'
-
- def action(self):
- return 'R done'
-
- def __init__(self, request):
- pass
-
- implements(IV)
-
-class RZMI(R1):
- pass
More information about the Zope3-Checkins
mailing list