[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - iregistry.py:1.1.2.1 registrationstack.py:1.1.2.1 test_cacheregistration.py:1.1.2.1 test_connectionregistration.py:1.1.2.1 test_nameregistry.py:1.1.2.1 test_registered.py:1.1.2.1 test_registrationmanager.py:1.1.2.1 test_registrations.py:1.1.2.1 test_registrationstack.py:1.1.2.1 test_registrationstatusproperty.py:1.1.2.1 test_serviceregistration.py:1.1.2.1 eventsetup.py:1.7.10.1 objecthubsetup.py:1.10.10.1 placefulsetup.py:1.20.2.1 test_adapter.py:1.12.2.1 test_auth.py:1.13.10.1 test_cachingservice.py:1.8.16.1 test_connectionservice.py:1.8.10.1 test_cookiesessionservice.py:1.3.18.1 test_eventservice.py:1.20.10.1 test_field.py:1.6.18.1 test_folder.py:1.3.16.1 test_interface.py:1.6.4.1 test_module.py:1.6.10.1 test_objecthub.py:1.9.10.1 test_pagefolder.py:1.3.16.1 test_principalannotation.py:1.3.10.1 test_roleservice.py:1.2.26.1 test_servicemanager.py:1.8.10.1 test_utility.py:1.5.10.1 test_view.py:1.11.10.1 configurationregistry.! py:NONE iconfigurable.py:NONE servicemanager.py:NONE test_cacheconfiguration.py:NONE test_configurationmanager.py:NONE test_configurationregistry.py:NONE test_configurations.py:NONE test_configurationstatusproperty.py:NONE test_connectionconfiguration.py:NONE test_nameconfigurable.py:NONE test_serviceconfiguration.py:NONE test_useconfiguration.py:NONE

Grégoire Weber zope@i-con.ch
Sun, 22 Jun 2003 10:24:03 -0400


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv24874/src/zope/app/services/tests

Modified Files:
      Tag: cw-mail-branch
	eventsetup.py objecthubsetup.py placefulsetup.py 
	test_adapter.py test_auth.py test_cachingservice.py 
	test_connectionservice.py test_cookiesessionservice.py 
	test_eventservice.py test_field.py test_folder.py 
	test_interface.py test_module.py test_objecthub.py 
	test_pagefolder.py test_principalannotation.py 
	test_roleservice.py test_servicemanager.py test_utility.py 
	test_view.py 
Added Files:
      Tag: cw-mail-branch
	iregistry.py registrationstack.py test_cacheregistration.py 
	test_connectionregistration.py test_nameregistry.py 
	test_registered.py test_registrationmanager.py 
	test_registrations.py test_registrationstack.py 
	test_registrationstatusproperty.py test_serviceregistration.py 
Removed Files:
      Tag: cw-mail-branch
	configurationregistry.py iconfigurable.py servicemanager.py 
	test_cacheconfiguration.py test_configurationmanager.py 
	test_configurationregistry.py test_configurations.py 
	test_configurationstatusproperty.py 
	test_connectionconfiguration.py test_nameconfigurable.py 
	test_serviceconfiguration.py test_useconfiguration.py 
Log Message:
Synced up with HEAD

=== Added File Zope3/src/zope/app/services/tests/iregistry.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: iregistry.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""
from zope.app.interfaces.services.registration import IRegistry
from zope.interface.verify import verifyObject
from zope.context import getWrapperContainer

class TestingIRegistry:
    """Base class for testing implementors of IRegistry

    Subclasses must implement:

      - createTestingRegistry()
        that returns a new registry object with no registrations.

        This registration object must be in the context of something
        that is not None.

      - createTestingRegistration()
        that returns a registration object.

    """

    def _assertInContext(self, ob, parent):
        """Assert that we have the proper context

        The container of ob must be the parent, and the parent must
        have some context.

        """
        self.assertEqual(getWrapperContainer(ob), parent)
        self.failIf(getWrapperContainer(getWrapperContainer(ob)) is None)

    def test_implements_IRegistry(self):
        verifyObject(IRegistry, self.createTestingRegistry())

    def test_queryRegistrationsFor_no_config(self):
        registry = self.createTestingRegistry()
        registration = self.createTestingRegistration()
        self.failIf(registry.queryRegistrationsFor(registration))

        self.assertEqual(
            registry.queryRegistrationsFor(registration, 42),
            42)

    def test_createRegistrationsFor(self):
        registry = self.createTestingRegistry()
        registration = self.createTestingRegistration()
        stack = registry.createRegistrationsFor(registration)

        self.assertEqual(getWrapperContainer(stack), registry)

        # If we call it again, we should get the same object
        self.assertEqual(registry.createRegistrationsFor(registration),
                         stack)

        self._assertInContext(stack, registry)

        return stack

    def test_queryRegistrationsFor(self):
        registry = self.createTestingRegistry()
        registration = self.createTestingRegistration()

        cstack = registry.createRegistrationsFor(registration)


        stack = registry.queryRegistrationsFor(registration)
        self.assertEqual(stack, cstack)
        self._assertInContext(stack, registry)

        stack = registry.queryRegistrationsFor(registration, 42)
        self.assertEqual(stack, cstack)
        self._assertInContext(stack, registry)


=== Added File Zope3/src/zope/app/services/tests/registrationstack.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################

__metaclass__ = type

class TestingRegistration:
    def __init__(self, id):
        self.id = id

    def __eq__(self, other):
        return self.id == getattr(other, 'id', 0)

class TestingRegistrationStack:

    class_ = TestingRegistration

    def __init__(self, *args):
        self._data = args

    def register(self, registration):
        cid = registration.id

        if self._data:
            if cid in self._data:
                return # already registered
        else:
            # Nothing registered. Need to stick None in front so that nothing
            # is active.
            self._data = (None, )

        self._data += (cid, )

    def unregister(self, registration):
        cid = registration.id

        data = self._data
        if data:
            if data[0] == cid:
                # It's active, we need to switch in None
                self._data = (None, ) + data[1:]
            else:
                self._data = tuple([item for item in data if item != cid])

    def registered(self, registration):
        cid = registration.id
        return cid in self._data

    def activate(self, registration):
        cid = registration.id
        if self._data[0] == cid:
            return # already active

        if self._data[0] is None:
            # Remove leading None marker
            self._data = self._data[1:]

        self._data = (cid, ) + tuple(
            [item for item in self._data if item != cid]
            )

    def deactivate(self, registration):
        cid = registration.id
        if self._data[0] != cid:
            return # already inactive

        # Just stick None on the front
        self._data = (None, ) + self._data

    def active(self):
        if self._data:
            return self.class_(self._data[0])

        return None

    def __nonzero__(self):
        return bool(self._data)

    def info(self):
        result = [{'id': path,
                   'active': False,
                   'registration': self.class_(path),
                   }
                  for path in self._data
                  ]

        if result:
            if result[0]['registration'] is None:
                del result[0]
            else:
                result[0]['active'] = True

        return result


=== Added File Zope3/src/zope/app/services/tests/test_cacheregistration.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################
"""Unit test for CacheRegistration.

$Id: test_cacheregistration.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""
__metaclass__ = type

from unittest import TestCase, main, makeSuite
from zope.app.context import ContextWrapper
from zope.app.interfaces.cache.cache import ICache
from zope.app.interfaces.cache.cache import ICachingService
from zope.app.interfaces.dependable import IDependable
from zope.app.interfaces.event import IObjectModifiedEvent
from zope.app.interfaces.services.registration import UnregisteredStatus
from zope.app.interfaces.services.registration import ActiveStatus
from zope.app.interfaces.services.registration import IAttributeRegisterable
from zope.app.interfaces.services.registration import IRegistry
from zope.app.interfaces.services.service import ILocalService
from zope.app.services.cache import CacheRegistration
from zope.app.services.registration import RegistrationStack
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.tests import setup
from zope.app.traversing import traverse
from zope.context import ContextMethod
from zope.interface import implements

class DependableStub:

    implements(IDependable)

    def addDependent(self, location):
        pass

    def removeDependent(self, location):
        pass

    def dependents(self):
        pass


class TestCache(DependableStub):

    implements(ICache, IAttributeRegisterable)

    def invalidateAll(self):
        self.invalidated = True


class CachingServiceStub(DependableStub):

    implements(ICachingService, IRegistry, ILocalService)

    def __init__(self):
        self.bindings = {}
        self.subscriptions = {}

    def queryRegistrationsFor(self, cfg, default=None):
        return self.queryRegistrations(cfg.name)
    queryRegistrationsFor = ContextMethod(queryRegistrationsFor)

    def queryRegistrations(self, name, default=None):
        registry = self.bindings.get(name, default)
        return ContextWrapper(registry, self)
    queryRegistrations = ContextMethod(queryRegistrations)

    def createRegistrationsFor(self, cfg):
        return self.createRegistrations(cfg.name)
    createRegistrationsFor = ContextMethod(createRegistrationsFor)

    def createRegistrations(self, name):
        try:
            registry = self.bindings[name]
        except KeyError:
            self.bindings[name] = registry = RegistrationStack()
        return ContextWrapper(registry, self)
    createRegistrations = ContextMethod(createRegistrations)

    def subscribe(self, obj, event):
        self.subscriptions.setdefault(obj, []).append(event)

    def unsubscribe(self, obj, event):
        self.subscriptions.setdefault(obj, []).remove(event)

    def listSubscriptions(self, obj):
        return self.subscriptions.get(obj, [])


class TestConnectionRegistration(PlacefulSetup, TestCase):

    def setUp(self):
        sm = PlacefulSetup.setUp(self, site=True)
        self.service = setup.addService(sm, 'Caching', CachingServiceStub())


        self.default = traverse(self.rootFolder,
                           '++etc++site/default')
        self.default.setObject('cch', TestCache())
        self.cch = traverse(self.default, 'cch')

        self.cm = self.default.getRegistrationManager()
        key = self.cm.setObject('',
                                CacheRegistration('cache_name',
                                                   '/++etc++site/default/cch'))
        self.config = traverse(self.default.getRegistrationManager(), key)

    def tearDown(self):
        PlacefulSetup.tearDown(self)

    def test_getComponent(self):
        # This should be already tested by ComponentRegistration tests, but
        # let's doublecheck
        self.assertEqual(self.config.getComponent(), self.cch)

    def test_status(self):
        self.assertEqual(self.config.status, UnregisteredStatus)
        self.config.status = ActiveStatus
        self.assertEqual(self.config.status, ActiveStatus)
        cr = self.service.queryRegistrations('cache_name')
        self.assertEqual(cr.active(), self.config)

    def test_activated(self):
        self.config.activated()
        self.assertEqual(self.service.listSubscriptions(self.cch),
                         [IObjectModifiedEvent])

    def test_deactivated(self):
        self.service.subscribe(self.cch, IObjectModifiedEvent)
        self.cch.invalidated = False
        self.config.deactivated()
        self.assertEqual(self.service.listSubscriptions(self.cch), [])
        self.failIf(not self.cch.invalidated,
                    "deactivation should call invalidateAll")


def test_suite():
    return makeSuite(TestConnectionRegistration)


if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_connectionregistration.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################
"""Unit test for ConnectionRegistration.

$Id: test_connectionregistration.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""
__metaclass__ = type

from unittest import TestCase, main, makeSuite
from zope.app.services.connection import ConnectionRegistration
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.traversing import traverse
from zope.app.interfaces.services.registration import UnregisteredStatus
from zope.app.interfaces.services.registration import ActiveStatus
from zope.app.interfaces.rdb import IZopeDatabaseAdapter
from zope.app.interfaces.dependable import IDependable
from zope.app.interfaces.rdb import IConnectionService
from zope.app.interfaces.services.registration import IRegistry
from zope.app.services.registration import RegistrationStack
from zope.context import ContextMethod
from zope.app.context import ContextWrapper
from zope.app.interfaces.services.registration import IRegistered
from zope.app.interfaces.services.registration import IAttributeRegisterable
from zope.app.tests import setup
from zope.app.interfaces.services.service import ILocalService
from zope.interface import implements

class DependableStub:

    implements(IDependable)

    def addDependent(self, location):
        pass

    def removeDependent(self, location):
        pass

    def dependents(self):
        pass


class TestDA(DependableStub):

    implements(IZopeDatabaseAdapter, IDependable, IRegistered)

    def addUsage(self, location):
        pass


class ConnectionServiceStub(DependableStub):

    implements(IConnectionService, IRegistry, IDependable,
               IAttributeRegisterable, ILocalService)

    def __init__(self):
        self.bindings = {}

    def queryRegistrationsFor(self, cfg, default=None):
        return self.queryRegistrations(cfg.name)
    queryRegistrationsFor = ContextMethod(queryRegistrationsFor)

    def queryRegistrations(self, name, default=None):
        registry = self.bindings.get(name, default)
        return ContextWrapper(registry, self)
    queryRegistrations = ContextMethod(queryRegistrations)

    def createRegistrationsFor(self, cfg):
        return self.createRegistrations(cfg.name)
    createRegistrationsFor = ContextMethod(createRegistrationsFor)

    def createRegistrations(self, name):
        try:
            registry = self.bindings[name]
        except KeyError:
            self.bindings[name] = registry = RegistrationStack()
        return ContextWrapper(registry, self)
    createRegistrations = ContextMethod(createRegistrations)


class TestConnectionRegistration(PlacefulSetup, TestCase):

    def setUp(self):
        sm = PlacefulSetup.setUp(self, site=True)
        self.service = setup.addService(sm, 'SQLDatabaseConnections',
                                        ConnectionServiceStub())

        self.default = traverse(self.rootFolder,
                           '++etc++site/default')
        self.default.setObject('da', TestDA())
        self.da = traverse(self.default, 'da')

        self.cm = self.default.getRegistrationManager()
        key = self.cm.setObject('',
                  ConnectionRegistration('conn_name',
                                          '/++etc++site/default/da'))
        self.config = traverse(self.default.getRegistrationManager(), key)

    def tearDown(self):
        PlacefulSetup.tearDown(self)

    def test_getComponent(self):
        # This should be already tested by ComponentRegistration tests, but
        # let's doublecheck
        self.assertEqual(self.config.getComponent(), self.da)

    def test_status(self):
        self.assertEqual(self.config.status, UnregisteredStatus)
        self.config.status = ActiveStatus
        self.assertEqual(self.config.status, ActiveStatus)
        cr = self.service.queryRegistrations('conn_name')
        self.assertEqual(cr.active(), self.config)


def test_suite():
    return makeSuite(TestConnectionRegistration)


if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_nameregistry.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################
"""NameRegistry tests

$Id: test_nameregistry.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

from zope.app.services.registration import NameRegistry
from zope.app.services.registration import NameComponentRegistry
from zope.app.context import ContextWrapper
from zope.context import getWrapperContainer

class RegistrationStub:

    def __init__(self, **kw):
        self.__dict__.update(kw)

    def getComponent(self):
        return self.component


class RegistryStub:

    def __init__(self, nonzero=0, active=None):
        self._nonzero = nonzero or (active and 1 or 0)
        self._active = active

    def __nonzero__(self):
        return self._nonzero

    def active(self):
        return self._active


class TestNameRegistry(TestCase):

    def setUp(self):
        self.container = object()
        self.subject = ContextWrapper(NameRegistry(), self.container)

    def test_queryRegistrationsFor(self):
        subject = self.subject
        cfg = RegistrationStub(name="Foo")
        self.assertEquals(subject.queryRegistrationsFor(cfg), None)
        self.assertEquals(subject.queryRegistrationsFor(cfg, 42), 42)

        registry = RegistryStub()
        subject._bindings["Foo"] = registry
        result = subject.queryRegistrationsFor(cfg)
        self.assertEquals(result, registry)
        self.assertEquals(getWrapperContainer(result), subject)
        self.assertEquals(getWrapperContainer(getWrapperContainer(result)),
                          self.container)

    def test_queryRegistrations(self):
        subject = self.subject
        self.assertEquals(subject.queryRegistrations("Foo"), None)
        self.assertEquals(subject.queryRegistrations("Foo", 42), 42)

        registry = RegistryStub()
        subject._bindings["Foo"] = registry
        result = subject.queryRegistrations("Foo")
        self.assertEquals(result, registry)
        self.assertEquals(getWrapperContainer(result), subject)
        self.assertEquals(getWrapperContainer(getWrapperContainer(result)),
                          self.container)

    def test_createRegistrationsFor(self):
        subject = self.subject
        cfg1 = RegistrationStub(name='Foo')
        cfg2 = RegistrationStub(name='Bar')
        r1 = subject.createRegistrationsFor(cfg1)
        r2 = subject.createRegistrationsFor(cfg2)
        r3 = subject.createRegistrationsFor(cfg1)
        self.assertEquals(r1, r3)
        self.assertNotEquals(r1, r2)
        self.assertNotEquals(r2, r3)
        self.assertEquals(r3, subject._bindings['Foo'])
        self.assertEquals(getWrapperContainer(r3), subject)
        self.assertEquals(getWrapperContainer(getWrapperContainer(r3)),
                          self.container)
        self.failUnless(subject._p_changed)

    def test_createRegistrations(self):
        subject = self.subject
        r1 = subject.createRegistrations('Foo')
        r2 = subject.createRegistrations('Bar')
        r3 = subject.createRegistrations('Foo')
        self.assertEquals(r1, r3)
        self.assertNotEquals(r1, r2)
        self.assertNotEquals(r2, r3)
        self.assertEquals(r3, subject._bindings['Foo'])
        self.assertEquals(getWrapperContainer(r3), subject)
        self.assertEquals(getWrapperContainer(getWrapperContainer(r3)),
                          self.container)
        self.failUnless(subject._p_changed)

    def test_listRegistrationNames(self):
        subject = self.subject
        self.assertEquals(tuple(subject.listRegistrationNames()), ())
        subject._bindings['Foo'] = 1
        self.assertEquals(tuple(subject.listRegistrationNames()), ('Foo',))
        subject._bindings['Bar'] = 0   # false values should be filtered out
        self.assertEquals(tuple(subject.listRegistrationNames()), ('Foo',))

class TestNameComponentRegistry(TestNameRegistry):

    def setUp(self):
        self.container = object()
        self.subject = ContextWrapper(NameComponentRegistry(),
                                      self.container)

    def test_queryActiveComponent(self):
        subject = self.subject
        self.assertEquals(subject.queryActiveComponent('xyzzy'), None)
        self.assertEquals(subject.queryActiveComponent('xyzzy', 'No'), 'No')
        subject._bindings['xyzzy'] = RegistryStub()
        self.assertEquals(subject.queryActiveComponent('xyzzy'), None)
        subject._bindings['xyzzy'] = RegistryStub(nonzero=1)
        self.assertEquals(subject.queryActiveComponent('xyzzy'), None)
        cfg = RegistrationStub(component='X')
        subject._bindings['xyzzy'] = RegistryStub(active=cfg)
        self.assertEquals(subject.queryActiveComponent('xyzzy'), 'X')


def test_suite():
    return TestSuite((
        makeSuite(TestNameRegistry),
        makeSuite(TestNameComponentRegistry),
        ))


if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_registered.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: test_registered.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.services.registration import Registered
from zope.app.interfaces.annotation import IAnnotations
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.interface import implements

class C(dict):
    implements(IAnnotations)

class TestRegistered(PlacelessSetup, TestCase):

    def testVerifyInterface(self):
        from zope.interface.verify import verifyObject
        from zope.app.interfaces.services.registration import IRegistered
        obj = Registered(C())
        verifyObject(IRegistered, obj)

    def testBasic(self):
        obj = Registered(C())
        self.failIf(obj.usages())
        obj.addUsage('/a/b')
        obj.addUsage('/c/d')
        obj.addUsage('/c/e')
        obj.addUsage('/c/d')
        locs = list(obj.usages())
        locs.sort()
        self.assertEqual(locs, ['/a/b', '/c/d', '/c/e'])
        obj.removeUsage('/c/d')
        locs = list(obj.usages())
        locs.sort()
        self.assertEqual(locs, ['/a/b', '/c/e'])
        obj.removeUsage('/c/d')
        locs = list(obj.usages())
        locs.sort()
        self.assertEqual(locs, ['/a/b', '/c/e'])

    def testRelativeAbsolute(self):
        obj = Registered(C())
        # Hack the object to have a parent path
        obj.pp = "/a/"
        obj.pplen = len(obj.pp)
        obj.addUsage("foo")
        self.assertEqual(obj.usages(), ("/a/foo",))
        obj.removeUsage("/a/foo")
        self.assertEqual(obj.usages(), ())
        obj.addUsage("/a/bar")
        self.assertEqual(obj.usages(), ("/a/bar",))
        obj.removeUsage("bar")
        self.assertEqual(obj.usages(), ())

def test_suite():
    return TestSuite((
        makeSuite(TestRegistered),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_registrationmanager.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: test_registrationmanager.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""

from unittest import TestCase, main, makeSuite
from zope.app.interfaces.container import IContainer
from zope.app.interfaces.container import IDeleteNotifiable
from zope.app.interfaces.container import IZopeContainer
from zope.app.interfaces.services.registration import IRegistrationManager
from zope.app.services.registration import RegistrationManager
from zope.app.services.tests import placefulsetup
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.app.traversing import traverse
from zope.component.adapter import provideAdapter
from zope.interface.common.tests.basemapping import BaseTestIEnumerableMapping
from zope.interface.verify import verifyObject
from zope.interface import implements
from zope.app.context import ContextWrapper

class Undeletable:

    implements(IDeleteNotifiable)

    def beforeDeleteHook(self, object, container):
        self.was_called = 1


class Test(BaseTestIEnumerableMapping, PlacelessSetup, TestCase):
    """Testing for Registration Manager """

    def setUp(self):
        PlacelessSetup.setUp(self)
        self.__manager = manager = RegistrationManager()
        for l in 'abcdefghijklmnop':
            manager.setObject('', l)
        del manager['8']
        del manager['10']

    def test_implements_IRegistrationManager(self):
        verifyObject(IRegistrationManager, self.__manager)

    def _IEnumerableMapping__stateDict(self):
        # Hook needed by BaseTestIEnumerableMapping
        # also, effectively test setObject and __delitem__.
        return {
            '1': 'a', '2': 'b', '3': 'c', '4': 'd', '5': 'e',
            '6': 'f', '7': 'g', '9': 'i', '11': 'k', '12': 'l',
            '13': 'm', '14': 'n', '15': 'o', '16': 'p',
            }

    def _IEnumerableMapping__sample(self):
        # Hook needed by BaseTestIEnumerableMapping
        # also, effectively test setObject and __delitem__.
        return self.__manager

    def _IEnumerableMapping__absentKeys(self):
        # Hook needed by BaseTestIEnumerableMapping
        # also, effectively test setObject and __delitem__.
        return ['-1', '8', '10', '17', '100', '10000']

    #########################################################
    # Move Top

    def test_moveTop_nothing(self):
        self.__manager.moveTop([])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveTop_1_no_effect(self):
        self.__manager.moveTop(['1'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveTop_many_no_effect(self):
        self.__manager.moveTop(['1', '88', '3', '2', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveTop_1(self):
        self.__manager.moveTop(['3'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['3', '1', '2', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveTop_many(self):
        self.__manager.moveTop(['1', '3', '88', '4', '11', '15', '16', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '3', '4', '11', '15', '16', '2', '5', '6', '7', '9',
             '12', '13', '14'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveTop_one_element_container(self):
        manager = RegistrationManager()
        manager.setObject('', 'a')
        manager.moveTop(['1'])
        self.assertEqual(list(manager.items()), [('1', 'a')])

    #########################################################
    # Move Bottom

    def test_moveBottom_nothing(self):
        self.__manager.moveBottom([])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveBottom_1_no_effect(self):
        self.__manager.moveBottom(['16'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveBottom_many_no_effect(self):
        self.__manager.moveBottom(['14', '88', '16', '15', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveBottom_1(self):
        self.__manager.moveBottom(['3'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16', '3'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveBottom_many(self):
        self.__manager.moveBottom(
            ['1', '3', '88', '4', '11', '16', '15', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['2', '5', '6', '7', '9',
             '12', '13', '14', '1', '3', '4', '11', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveBottom_one_element_container(self):
        manager = RegistrationManager()
        manager.setObject('', 'a')
        manager.moveBottom(['1'])
        self.assertEqual(list(manager.items()), [('1', 'a')])

    #########################################################
    # Move Up

    def test_moveUp_nothing(self):
        self.__manager.moveUp([])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveUp_1_no_effect(self):
        self.__manager.moveUp(['1'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveUp_many_no_effect(self):
        self.__manager.moveUp(['1', '88', '3', '2', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveUp_1(self):
        self.__manager.moveUp(['3'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '3', '2', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveUp_many(self):
        self.__manager.moveUp(
            ['1', '3', '88', '4', '11', '16', '15', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '3', '4', '2', '5', '6', '7', '11', '9',
             '12', '13', '15', '16', '14'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveUp_one_element_container(self):
        manager = RegistrationManager()
        manager.setObject('', 'a')
        manager.moveUp(['1'])
        self.assertEqual(list(manager.items()), [('1', 'a')])

    #########################################################
    # Move Down

    def test_moveDown_nothing(self):
        self.__manager.moveDown([])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveDown_1_no_effect(self):
        self.__manager.moveDown(['16'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveDown_many_no_effect(self):
        self.__manager.moveDown(['16', '88', '14', '15', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '3', '4', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveDown_1(self):
        self.__manager.moveDown(['3'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['1', '2', '4', '3', '5', '6', '7', '9',
             '11', '12', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveDown_many(self):
        self.__manager.moveDown(
            ['1', '3', '88', '4', '11', '16', '15', '99'])
        self.assertEqual(
            list(self.__manager.keys()),
            ['2', '1', '5', '3', '4', '6', '7', '9',
             '12', '11', '13', '14', '15', '16'],
            )

        # Make sure we still have thye right items
        self.test_items()

    def test_moveDown_one_element_container(self):
        manager = RegistrationManager()
        manager.setObject('', 'a')
        manager.moveDown(['1'])
        self.assertEqual(list(manager.items()), [('1', 'a')])

    #########################################################

    def test_manageBeforeDelete(self):
        container = []
        manager = RegistrationManager()
        manager = ContextWrapper(manager, None)  # decorate to IZopeContainer
        thingy = Undeletable()
        manager.setObject('xyzzy', thingy)
        manager.beforeDeleteHook(manager, container)
        self.failUnless(thingy.was_called)

class RegistrationManagerContainerTests(placefulsetup.PlacefulSetup):

    def test_getRegistrationManager(self):
        sm = self.buildFolders(site=True)
        default = traverse(sm, 'default')
        self.assertEqual(default.getRegistrationManager(),
                         default['RegistrationManager'])
        default.setObject('xxx', RegistrationManager())
        del default['RegistrationManager']
        self.assertEqual(default.getRegistrationManager(),
                         default['xxx'])


#       Can't test empty because there's no way to make it empty.
##         del default['xxx']
##         self.assertRaises(Exception,
##                           default.getRegistrationManager)

    def test_cant_remove_last_cm(self):
        sm = self.buildFolders(site=True)
        default = traverse(sm, 'default')
        self.assertRaises(Exception,
                          default.__delitem__, 'registration')
        default.setObject('xxx', RegistrationManager())
        del default['RegistrationManager']


def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_registrations.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################
"""Unit tests for registration classes

$Id: test_registrations.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

from zope.interface import Interface, implements
from zope.app.interfaces.services.registration import UnregisteredStatus
from zope.app.interfaces.services.registration import RegisteredStatus
from zope.app.interfaces.services.registration import ActiveStatus
from zope.app.interfaces.dependable import DependencyError
from zope.app.services.registration import SimpleRegistration
from zope.app.services.registration import ComponentRegistration
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.context import ContextWrapper
from zope.app.interfaces.dependable import IDependable
from zope.app.traversing import traverse
from zope.security.proxy import Proxy


class ITestComponent(Interface):
    pass

class ComponentStub:

    implements(IDependable)

    _dependents = ()

    def addDependent(self, location):
        self._dependents = tuple(
            [d for d in self._dependents if d != location]
            +
            [location]
            )

    def removeDependent(self, location):
        self._dependents = tuple(
            [d for d in self._dependents if d != location]
            )

    def dependents(self):
        return self._dependents


class TestSimpleRegistration(TestCase):

    def test_beforeDeleteHook(self):
        container = object()
        cfg = SimpleRegistration()

        # cannot delete an active registration
        cfg.status = ActiveStatus
        self.assertRaises(DependencyError, cfg.beforeDeleteHook, cfg,
                          container)

        # deletion of a registered registration causes it to become
        # unregistered
        cfg.status = RegisteredStatus
        cfg.beforeDeleteHook(cfg, container)
        self.assertEquals(cfg.status, UnregisteredStatus)


class TestComponentRegistration(TestSimpleRegistration, PlacefulSetup):

    def setUp(self):
        PlacefulSetup.setUp(self, site=True)
        self.name = 'foo'

    def test_getComponent(self):
        # set up a component
        name, component = 'foo', object()
        self.rootFolder.setObject(name, component)
        # set up a registration
        cfg = ComponentRegistration("/"+name)
        cfg = ContextWrapper(cfg, self.rootFolder)
        # check that getComponent finds the registration
        self.assertEquals(cfg.getComponent(), component)

    def test_getComponent_permission(self):
        # set up a component
        name, component = 'foo', object()
        self.rootFolder.setObject(name, component)
        # set up a registration
        cfg = ComponentRegistration("/"+name, 'zope.TopSecret')
        cfg.getInterface = lambda: ITestComponent
        cfg = ContextWrapper(cfg, self.rootFolder)
        # check that getComponent finds the registration
        result = cfg.getComponent()
        self.assertEquals(result, component)
        self.failUnless(type(result) is Proxy)

    def test_afterAddHook(self):
        # set up a component
        name, component = 'foo', ComponentStub()
        self.rootFolder.setObject(name, component)
        # set up a registration
        cfg = ComponentRegistration("/"+name)
        self.rootFolder.setObject('cfg', cfg)
        cfg = traverse(self.rootFolder, 'cfg')
        # simulate IAddNotifiable
        cfg.afterAddHook(cfg, self.rootFolder)
        # check that the dependency tracking works
        self.assertEquals(component.dependents(), ('/cfg',))

    def test_beforeDeleteHook_dependents(self):
        # set up a component
        name, component = 'foo', ComponentStub()
        self.rootFolder.setObject(name, component)
        component.addDependent('/cfg')
        # set up a registration
        cfg = ComponentRegistration("/"+name)
        cfg.status = UnregisteredStatus
        self.rootFolder.setObject('cfg', cfg)
        cfg = traverse(self.rootFolder, 'cfg')
        # simulate IDeleteNotifiable
        cfg.beforeDeleteHook(cfg, self.rootFolder)
        # check that the dependency tracking works
        self.assertEquals(component.dependents(), ())


# NamedRegistration is too simple to need testing at the moment


def test_suite():
    return TestSuite((
        makeSuite(TestSimpleRegistration),
        makeSuite(TestComponentRegistration),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_registrationstack.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_registrationstack.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.context import ContextWrapper, getItem
from zope.app.services.registration import RegistrationStack
from zope.app.traversing import traverse

class Registration:

    active = 0

    def activated(self):
        self.active += 1

    def deactivated(self):
        self.active -= 1


class Test(PlacefulSetup, TestCase):

    def setUp(self):
        PlacefulSetup.setUp(self, site=True)
        root = self.rootFolder
        self.__default = traverse(root, "++etc++site/default")
        self.__registry = ContextWrapper(RegistrationStack(), root)

    def __config(self, name):
        self.__default.setObject(name, Registration())
        return getItem(self.__default, name)

    def test_register_and_registered_and_nonzero_and_active(self):
        registry = self.__registry

        self.assertEqual(registry.active(), None)

        self.failIf(registry)
        self.__c1 = c1 = self.__config("1")
        registry.register(c1)
        self.failUnless(registry)
        self.failUnless(registry.registered(c1))
        self.assertEqual(c1.active, 0)

        self.assertEqual(registry.active(), None)

        self.__c2 = c2 = self.__config("2")
        self.failIf(registry.registered(c2))
        registry.register(c2)
        self.failUnless(registry)
        self.failUnless(registry.registered(c2))
        self.assertEqual(c2.active, 0)


    def test_unregister_and_registered_and_nonzero(self):
        # reuse registration test to set things up (more)
        self.test_register_and_registered_and_nonzero_and_active()

        registry = self.__registry

        c1 = self.__c1
        registry.unregister(c1)
        self.failIf(registry.registered(c1))
        self.assertEqual(c1.active, 0)

        c2 = self.__c2
        registry.unregister(c2)
        self.failIf(registry.registered(c2))
        self.assertEqual(c2.active, 0)

        self.failIf(registry)

    def test_activate_and_active(self):
        # reuse registration test to set things up (more)
        self.test_register_and_registered_and_nonzero_and_active()

        registry = self.__registry
        self.assertEqual(registry.active(), None)

        c1 = self.__c1
        c2 = self.__c2

        registry.activate(c2)
        self.assertEqual(c1.active, 0)
        self.failUnless(registry.registered(c1))
        self.assertEqual(c2.active, 1)
        self.failUnless(registry.registered(c2))
        self.assertEqual(registry.active(), c2)

        registry.activate(c2)
        self.assertEqual(c1.active, 0)
        self.failUnless(registry.registered(c1))
        self.assertEqual(c2.active, 1)
        self.failUnless(registry.registered(c2))
        self.assertEqual(registry.active(), c2)

        registry.activate(c1)
        self.assertEqual(c1.active, 1)
        self.failUnless(registry.registered(c1))
        self.assertEqual(c2.active, 0)
        self.failUnless(registry.registered(c2))
        self.assertEqual(registry.active(), c1)

    def test_activate_none(self):
        self.test_activate_and_active()

        registry = self.__registry
        c1 = self.__c1
        c2 = self.__c2

        registry.activate(None)

        self.assertEqual(c1.active, 0)
        self.failUnless(registry.registered(c1))
        self.assertEqual(c2.active, 0)
        self.failUnless(registry.registered(c2))
        self.assertEqual(registry.active(), None)

    def test_activate_unregistered(self):
        registry = self.__registry
        self.assertRaises(ValueError, registry.activate, self.__config('3'))
        self.test_activate_and_active()
        self.assertRaises(ValueError, registry.activate, self.__config('4'))

    def test_deactivate(self):
        self.test_activate_and_active()

        registry = self.__registry
        c1 = self.__c1
        c2 = self.__c2
        self.assertEqual(registry.active(), c1)

        registry.deactivate(c2)
        self.assertEqual(c2.active, 0)
        self.assertEqual(registry.active(), c1)

        registry.deactivate(c1)
        self.assertEqual(c1.active, 0)
        self.assertEqual(c2.active, 1)
        self.assertEqual(registry.active(), c2)

        self.failUnless(registry.registered(c1))
        self.failUnless(registry.registered(c2))

    def test_unregister_active(self):
        self.test_activate_and_active()

        registry = self.__registry
        c1 = self.__c1
        c2 = self.__c2
        self.assertEqual(registry.active(), c1)

        registry.unregister(c1)
        self.assertEqual(c1.active, 0)
        self.assertEqual(c2.active, 1)
        self.assertEqual(registry.active(), c2)

        self.failIf(registry.registered(c1))
        self.failUnless(registry.registered(c2))

    def test_deactivate_unregistered(self):
        registry = self.__registry
        self.assertRaises(ValueError, registry.deactivate, self.__config('3'))

    def test_info(self):
        self.test_activate_and_active()

        registry = self.__registry
        c1 = self.__c1
        c2 = self.__c2

        info = registry.info()
        self.assertEqual(
            info,
            [
              {'id': 'default/1',
               'active': True,
               'registration': c1,
               },
              {'id': 'default/2',
               'active': False,
               'registration': c2,
               },
              ])

        registry.deactivate(c1)

        info = registry.info()
        self.assertEqual(
            info,
            [
              {'id': 'default/2',
               'active': True,
               'registration': c2,
               },
              {'id': 'default/1',
               'active': False,
               'registration': c1,
               },
              ])

        info = registry.info(True)
        self.assertEqual(
            info,
            [
              {'id': 'default/2',
               'active': True,
               'registration': c2,
               },
              {'id': '',
               'active': False,
               'registration': None,
               },
              {'id': 'default/1',
               'active': False,
               'registration': c1,
               },
              ])

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_registrationstatusproperty.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_registrationstatusproperty.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from zope.component.interfaces import IServiceService
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.services.tests.registrationstack import TestingRegistration
from zope.app.services.tests.registrationstack import TestingRegistrationStack
from zope.app.services.registration import RegistrationStatusProperty
from zope.app.interfaces.services.registration import RegisteredStatus
from zope.app.interfaces.services.registration import UnregisteredStatus
from zope.app.interfaces.services.registration import ActiveStatus
from zope.app.context import ContextWrapper
from zope.component.exceptions import ComponentLookupError
from zope.app.interfaces.services.registration import NoLocalServiceError
from zope.interface import implements


class TestingRegistration(TestingRegistration):
    serviceType = "Services"
    status = RegistrationStatusProperty()
    service_type = "Test"

class PassiveRegistration(TestingRegistration):
    serviceType = "NoSuchService"
    status = RegistrationStatusProperty()

class UtilityRegistration(TestingRegistration):
    serviceType = "Utilities"
    status = RegistrationStatusProperty()

class TestingRegistrationStack(TestingRegistrationStack):
    class_ = TestingRegistration

class TestingServiceManager:

    implements(IServiceService) # I lied

    registry = None

    def getService(self, name):
        if name in ("Services", "Utilities"):
            return self
        raise ComponentLookupError("Wrong service name", name)

    def queryService(self, name, default=None):
        if name in ("Services", "Utilities"):
            return self
        else:
            return default

    def queryLocalService(self, name, default=None):
        if name == "Services":
            return self
        else:
            return default

    def queryRegistrationsFor(self, registration, default=None):
        if registration.service_type != "Test":
            raise ValueError("Bad service type", registration.service_type)
        return self.registry

    def createRegistrationsFor(self, registration):
        if registration.service_type != "Test":
            raise ValueError("Bad service type", registration.service_type)
        self.registry = TestingRegistrationStack()
        return self.registry


class Test(PlacefulSetup, TestCase):

    def setUp(self):
        PlacefulSetup.setUp(self, folders=True)
        self.__sm = TestingServiceManager()
        self.rootFolder.setServiceManager(self.__sm)

    def test_property(self):

        configa = ContextWrapper(TestingRegistration('a'), self.rootFolder)
        self.assertEqual(configa.status, UnregisteredStatus)

        configa.status = RegisteredStatus
        self.assertEqual(self.__sm.registry._data, (None, 'a'))
        self.assertEqual(configa.status, RegisteredStatus)

        configa.status = ActiveStatus
        self.assertEqual(self.__sm.registry._data, ('a', ))
        self.assertEqual(configa.status, ActiveStatus)

        configb = ContextWrapper(TestingRegistration('b'), self.rootFolder)
        self.assertEqual(self.__sm.registry._data, ('a', ))
        self.assertEqual(configb.status, UnregisteredStatus)

        configb.status = RegisteredStatus
        self.assertEqual(self.__sm.registry._data, ('a', 'b'))
        self.assertEqual(configb.status, RegisteredStatus)

        configc = ContextWrapper(TestingRegistration('c'), self.rootFolder)
        self.assertEqual(configc.status, UnregisteredStatus)
        self.assertEqual(self.__sm.registry._data, ('a', 'b'))

        configc.status = RegisteredStatus
        self.assertEqual(self.__sm.registry._data, ('a', 'b', 'c'))
        self.assertEqual(configc.status, RegisteredStatus)

        configc.status = ActiveStatus
        self.assertEqual(self.__sm.registry._data, ('c', 'a', 'b'))
        self.assertEqual(configc.status, ActiveStatus)

        configc.status = UnregisteredStatus
        self.assertEqual(self.__sm.registry._data, (None, 'a', 'b'))
        self.assertEqual(configc.status, UnregisteredStatus)
        self.assertEqual(configb.status, RegisteredStatus)
        self.assertEqual(configa.status, RegisteredStatus)

    def test_passive(self):
        # scenario:
        #   1. create and configure an SQLConnectionService
        #   2. create and configure a database adapter&connection
        #   3. disable SQLConnectionService
        # now the ConnectionRegistration.status cannot access the
        # SQLConnectionService

        configa = ContextWrapper(PassiveRegistration('a'), self.rootFolder)
        self.assertEqual(configa.status, UnregisteredStatus)

        try:
            configa.status = RegisteredStatus
        except NoLocalServiceError:
            self.assertEqual(configa.status, UnregisteredStatus)
        else:
            self.fail("should complain about missing service")

        try:
            configa.status = ActiveStatus
        except NoLocalServiceError:
            self.assertEqual(configa.status, UnregisteredStatus)
        else:
            self.fail("should complain about missing service")


        # we should also get an error if there *is a matching service,
        # not it is non-local

        configa = ContextWrapper(UtilityRegistration('a'), self.rootFolder)
        self.assertEqual(configa.status, UnregisteredStatus)

        try:
            configa.status = RegisteredStatus
        except NoLocalServiceError:
            self.assertEqual(configa.status, UnregisteredStatus)
        else:
            self.fail("should complain about missing service")

        try:
            configa.status = ActiveStatus
        except NoLocalServiceError:
            self.assertEqual(configa.status, UnregisteredStatus)
        else:
            self.fail("should complain about missing service")


def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/services/tests/test_serviceregistration.py ===
##############################################################################
#
# 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.0 (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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_serviceregistration.py,v 1.1.2.1 2003/06/22 14:23:28 gregweb Exp $
"""

from unittest import TestCase, main, makeSuite

from zope.interface import Interface, implements

from zope.component import getServiceManager, getAdapter
from zope.app.traversing import traverse, getPath
from zope.app.services.service import ServiceRegistration
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.component.service import defineService
from zope.app.interfaces.services.service import IBindingAware
from zope.app.interfaces.services.registration import ActiveStatus
from zope.app.interfaces.services.registration import RegisteredStatus
from zope.app.interfaces.services.registration import IRegistered
from zope.app.interfaces.services.service import ISimpleService

from zope.app.interfaces.dependable import IDependable
from zope.app.interfaces.dependable import DependencyError


class ITestService(Interface):
    pass

class TestServiceBase:
    implements(ITestService, IBindingAware, IDependable)

    _bound = _unbound = ()

    def bound(self, name):
        self._bound += (name, )

    def unbound(self, name):
        self._unbound += (name, )

    _dependents = ()

    def addDependent(self, location):
        self._dependents = tuple(
            [d for d in self._dependents if d != location]
            +
            [location]
            )

    def removeDependent(self, location):
        self._dependents = tuple(
            [d for d in self._dependents if d != location]
            )

    def dependents(self):
        return self._dependents

class TestService(TestServiceBase):
    implements(ISimpleService)

class Test(PlacefulSetup, TestCase):

    def setUp(self):
        PlacefulSetup.setUp(self, site=True)

        defineService('test_service', ITestService)

        default = traverse(self.rootFolder,
                           '++etc++site/default')
        self.__default = default

        default.setObject('c', TestService())


        registration = ServiceRegistration(
            'test_service', '/++etc++site/default/c')

        self.__c = traverse(default, 'c')
        self.__cm = default.getRegistrationManager()

        self.__cm.setObject('', registration)

        self.__config = traverse(default.getRegistrationManager(), '1')
        self.__configpath = getPath(self.__config)

    def test_activated(self):
        old = self.__c._bound
        self.__config.activated()
        self.assertEqual(self.__c._bound, old+('test_service',))

    def test_deactivated(self):
        old = self.__c._unbound
        self.__config.deactivated()
        self.assertEqual(self.__c._unbound, old+('test_service',))

    def test_getInterface(self):
        self.assertEquals(self.__config.getInterface(), ITestService)

    # XXX the following tests check the same things as
    # zope.app.services.tests.testregistrations, but in a different way

    def test_getComponent(self):
        self.assertEqual(self.__config.getComponent(), self.__c)

    def test_afterAddHook(self):
        self.assertEqual(self.__c._dependents,
                         (self.__configpath, ))
        u = getAdapter(self.__c, IRegistered)
        self.assertEqual(list(u.usages()),
                         [self.__configpath])

    def test_beforeDeleteHook_and_unregistered(self):
        self.__config.status = RegisteredStatus

        sm = getServiceManager(self.__default)
        registry = sm.queryRegistrationsFor(self.__config)
        self.failUnless(registry, "The components should be registered")

        del self.__cm['1']
        self.assertEqual(self.__c._dependents, ())
        u = getAdapter(self.__c, IRegistered)
        self.assertEqual(len(u.usages()), 0)

        self.failIf(registry, "The components should not be registered")

    def test_disallow_delete_when_active(self):
        self.__config.status = ActiveStatus
        try:
            del self.__cm['1']
        except DependencyError:
            pass # OK
        else:
            self.failUnless(0, "Should have gotten a depency error")

    def test_not_a_local_service(self):
        defineService('test_service_2', ITestService)
        self.__default.setObject('c2', TestServiceBase())

        self.assertRaises(
            TypeError,
            ServiceRegistration,
            'test_service',
            '/++etc++site/default/c2',
            self.__default
            )


def test_suite():
    return makeSuite(Test)

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Zope3/src/zope/app/services/tests/eventsetup.py 1.7 => 1.7.10.1 ===
--- Zope3/src/zope/app/services/tests/eventsetup.py:1.7	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/eventsetup.py	Sun Jun 22 10:23:28 2003
@@ -17,15 +17,10 @@
 $Id$
 """
 from zope.app.services.tests.placefulsetup import PlacefulSetup
-from zope.app.services.service import ServiceManager
 
 class EventSetup(PlacefulSetup):
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-        self.buildFolders()
+        PlacefulSetup.setUp(self, site=True)
         self.createStandardServices()
-
-    def createServiceManager(self, folder):
-        folder.setServiceManager(ServiceManager())
 


=== Zope3/src/zope/app/services/tests/objecthubsetup.py 1.10 => 1.10.10.1 ===
--- Zope3/src/zope/app/services/tests/objecthubsetup.py:1.10	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/objecthubsetup.py	Sun Jun 22 10:23:28 2003
@@ -22,14 +22,16 @@
 from zope.app.services.servicenames import HubIds
 from zope.app.traversing import traverse, canonicalPath
 
-from zope.app.interfaces.event import IObjectAddedEvent
+from zope.app.interfaces.event import IObjectAddedEvent, IObjectMovedEvent
 from zope.app.interfaces.event import ISubscriber
 
+from zope.interface import implements
+
 class LoggingSubscriber:
     # XXX Jim mentioned there is a new generic
     # version of this in zope.app somewhere...
 
-    __implements__ = ISubscriber
+    implements(ISubscriber)
 
     def __init__(self):
         self.events_received = []
@@ -76,7 +78,9 @@
 
     def notify(self, event):
         LoggingSubscriber.notify(self, event)
-        if IObjectAddedEvent.isImplementedBy(event):
+        # The policy is to register on object adds and object copies.
+        if (IObjectAddedEvent.isImplementedBy(event)
+            and not IObjectMovedEvent.isImplementedBy(event)):
             self.hub.register(event.location)
 
 class ObjectHubSetup(EventSetup):
@@ -92,7 +96,7 @@
         self.rootFolder.setObject('logging_subscriber', subscriber)
         self.subscriber = traverse(self.rootFolder, 'logging_subscriber')
         self.object_hub.subscribe(self.subscriber)
-        
+
     def setUp(self):
         EventSetup.setUp(self)
         self.object_hub = getService(self.rootFolder, HubIds)


=== Zope3/src/zope/app/services/tests/placefulsetup.py 1.20 => 1.20.2.1 ===
--- Zope3/src/zope/app/services/tests/placefulsetup.py:1.20	Sun May 18 14:06:43 2003
+++ Zope3/src/zope/app/services/tests/placefulsetup.py	Sun Jun 22 10:23:28 2003
@@ -16,226 +16,77 @@
 Revision information:
 $Id$
 """
-from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.browser.absoluteurl import SiteAbsoluteURL, AbsoluteURL
-from zope.app.component import hooks
-from zope.app.container.traversal import ContainerTraversable
-from zope.app.dependable import Dependable
-from zope.app.interfaces.annotation import IAnnotations
-from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.interfaces.container import ISimpleReadContainer
-from zope.app.interfaces.dependable import IDependable
-from zope.app.interfaces.services.configuration import Active
-from zope.app.interfaces.services.configuration import IAttributeUseConfigurable
-from zope.app.interfaces.services.configuration import IUseConfiguration
-from zope.app.interfaces.traversing import IContainmentRoot
-from zope.app.interfaces.traversing import IContainmentRoot
-from zope.app.interfaces.traversing import IPhysicallyLocatable
-from zope.app.interfaces.traversing import ITraverser, ITraversable
-from zope.app.services.configuration import UseConfiguration
-from zope.app.services.service import ServiceManager, ServiceConfiguration
-from zope.app.services.servicenames import EventPublication, EventSubscription
-from zope.app.services.servicenames import HubIds
+
+from zope.app import zapi
+from zope.app.tests import setup
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.app.traversing.adapters import DefaultTraversable
-from zope.app.traversing.adapters import Traverser, RootPhysicallyLocatable
-from zope.app.traversing.adapters import WrapperPhysicallyLocatable
-from zope.app.traversing import traverse, getPath
-from zope.app.traversing.namespace import etc, provideNamespaceHandler
-from zope.component.adapter import provideAdapter
-from zope.component.view import provideView
-from zope import component as CA
-from zope.publisher.interfaces.browser import IBrowserPresentation
+from zope.app.content.folder import RootFolder
+from zope.app.context import ContextWrapper
+
+class Place(object):
+
+    def __init__(self, path):
+        self.path = path
+
+    def __get__(self, inst, cls=None):
+        if inst is None:
+            return self
+
+        try:
+            # Use __dict__ directly to avoid infinite recursion
+            root = inst.__dict__['rootFolder']
+        except KeyError:
+            root = inst.rootFolder = setup.buildSampleFolderTree()
+
+        root = ContextWrapper(root, None)
+        return zapi.traverse(root, self.path)
 
 class PlacefulSetup(PlacelessSetup):
 
-    def setUp(self):
-        PlacelessSetup.setUp(self)
-        # set up placeful hooks, saving originals for tearDown
-        CA.getServiceManager.sethook(hooks.getServiceManager_hook)
-        self.setUpTraversal()
-
-    def setUpTraversal(self):
-
-        provideAdapter(None, ITraverser, Traverser)
-        provideAdapter(None, ITraversable, DefaultTraversable)
-
-        provideAdapter(
-            ISimpleReadContainer, ITraversable, ContainerTraversable)
-        provideAdapter(
-            None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
-        provideAdapter(
-            IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
-
-        provideAdapter(IAttributeUseConfigurable, IUseConfiguration,
-                       UseConfiguration)
-        provideAdapter(IAttributeAnnotatable, IAnnotations,
-                       AttributeAnnotations)
-
-        provideAdapter(IAttributeAnnotatable, IDependable, Dependable)
-
-        # set up etc namespace
-        provideNamespaceHandler("etc", etc)
-
-        provideView(None, "absolute_url", IBrowserPresentation,
-                    AbsoluteURL)
-        provideView(IContainmentRoot, "absolute_url", IBrowserPresentation,
-                    SiteAbsoluteURL)
+    # Places :)
+    rootFolder  = Place('')
 
+    folder1     = Place('folder1')
+    folder1_1   = Place('folder1/folder1_1')
+    folder1_1_1 = Place('folder1/folder1_1/folder1_1_1')
+    folder1_1_2 = Place('folder1/folder1_2/folder1_1_2')
+    folder1_2   = Place('folder1/folder1_2')
+    folder1_2_1 = Place('folder1/folder1_2/folder1_2_1')
+
+    folder2     = Place('folder2')
+    folder2_1   = Place('folder2/folder2_1')
+    folder2_1_1 = Place('folder2/folder2_1/folder2_1_1')
+
+
+    def setUp(self, folders=False, site=False):
+        setup.placefulSetUp()
+        if folders or site:
+            return self.buildFolders(site)
 
     def tearDown(self):
+        setup.placefulTearDown()
         # clean up folders and placeful service managers and services too?
-        CA.getServiceManager.reset()
-        PlacelessSetup.tearDown(self)
 
-    def buildFolders(self):
-        # set up a reasonably complex folder structure
-        #
-        #     ____________ rootFolder ____________
-        #    /                                    \
-        # folder1 __________________            folder2
-        #   |                       \             |
-        # folder1_1 ____           folder1_2    folder2_1
-        #   |           \            |            |
-        # folder1_1_1 folder1_1_2  folder1_2_1  folder2_1_1
-        from zope.app.content.folder import Folder
-        from zope.proxy.context import ContextWrapper
-        # top
-        self.createRootFolder()
-        # level 1
-        self.folder1 = Folder()
-        self.rootFolder.setObject("folder1", self.folder1)
-        self.folder1 = ContextWrapper(self.folder1, self.rootFolder,
-             name = "folder1")
-        self.folder2 = Folder()
-        self.rootFolder.setObject("folder2", self.folder2)
-        self.folder2 = ContextWrapper(self.folder2, self.rootFolder,
-             name = "folder2")
-        # level 2
-        self.folder1_1 = Folder()
-        self.folder1.setObject("folder1_1", self.folder1_1)
-        self.folder1_1 = ContextWrapper(self.folder1_1, self.folder1,
-             name = "folder1_1")
-        self.folder1_2 = Folder()
-        self.folder1.setObject("folder1_2", self.folder1_2)
-        self.folder1_2 = ContextWrapper(self.folder1_2, self.folder1,
-             name = "folder1_2")
-        self.folder2_1 = Folder()
-        self.folder2.setObject("folder2_1", self.folder2_1)
-        self.folder2_1 = ContextWrapper(self.folder2_1, self.folder2,
-             name = "folder2_1")
-        # level 3
-        self.folder1_1_1 = Folder()
-        self.folder1_1.setObject("folder1_1_1", self.folder1_1_1)
-        self.folder1_1_1 = ContextWrapper(self.folder1_1_1, self.folder1_1,
-             name = "folder1_1_1")
-        self.folder1_1_2 = Folder()
-        self.folder1_1.setObject("folder1_1_2", self.folder1_1_2)
-        self.folder1_1_2 = ContextWrapper(self.folder1_1_2, self.folder1_1,
-             name = "folder1_1_2")
-        self.folder1_2_1 = Folder()
-        self.folder1_2.setObject("folder1_2_1", self.folder1_2_1)
-        self.folder1_2_1 = ContextWrapper(self.folder1_2_1, self.folder1_2,
-             name = "folder1_2_1")
-        self.folder2_1_1 = Folder()
-        self.folder2_1.setObject("folder2_1_1", self.folder2_1_1)
-        self.folder2_1_1 = ContextWrapper(self.folder2_1_1, self.folder2_1,
-             name = "folder2_1_1")
-
-    def createServiceManager(self, folder=None):
-        if folder is None:
-            folder = self.rootFolder
-        from zope.app.services.tests.servicemanager \
-             import TestingServiceManager
-        folder.setServiceManager(TestingServiceManager())
+    def buildFolders(self, site=False):
+        self.rootFolder = setup.buildSampleFolderTree()
+        if site:
+            return self.makeSite()
+
+    def makeSite(self, path='/'):
+        folder = zapi.traverse(self.rootFolder, path)
+        return setup.createServiceManager(folder)
 
     def createRootFolder(self):
-        from zope.app.content.folder import RootFolder
         self.rootFolder = RootFolder()
 
+    # The following is a hook that some base classes might want to override.
     def getObjectHub(self):
         from zope.app.services.hub import ObjectHub
         return ObjectHub()
 
-    def createEventService(self, folder_path):
-        """Create an event service in 'folder', and configure it for
-        EventPublication and EventSubscription services."""
-        folder = traverse(self.rootFolder, folder_path)
-        if not folder.hasServiceManager():
-            folder.setServiceManager(ServiceManager())
-        sm = traverse(folder, '++etc++site')
-        default = traverse(sm, 'default')
-        service_name = 'anEventService'
-        from zope.app.services.event import EventService
-        default.setObject(service_name, EventService())
-
-        path = "%s/%s" % (getPath(default), service_name)
-        configuration = ServiceConfiguration(EventPublication, path, self.rootFolder)
-        default.getConfigurationManager().setObject(
-                "%sEventsDir" % service_name, configuration)
-        traverse(default.getConfigurationManager(), '1').status = Active
-
-        configuration = ServiceConfiguration(EventSubscription, path,
-                                             self.rootFolder)
-        default.getConfigurationManager().setObject(
-                "%sSubscriptionServiceDir" % service_name, configuration)
-        traverse(default.getConfigurationManager(), '2').status = Active
-
     def createStandardServices(self):
         '''Create a bunch of standard placeful services'''
-        if not hasattr(self, 'rootFolder'):
-            self.createRootFolder()
-        root = self.rootFolder
-        if root.hasServiceManager():
-            raise RuntimeError('ServiceManager already exists, so cannot '
-                               'create standard services')
-        root.setServiceManager(ServiceManager())
-        from zope.component import getServiceManager
-        defineService = getServiceManager(None).defineService
-
-        from zope.app.interfaces.services.hub import IObjectHub
-        from zope.app.interfaces.services.event import ISubscriptionService
-        from zope.app.services.event import EventService
-        defineService(EventSubscription, ISubscriptionService)
-
-        # EventPublication service already defined by
-        # zope.app.events.tests.PlacelessSetup
-
-        defineService(HubIds, IObjectHub)
-
-        sm = traverse(root, '++etc++site')
-        default = traverse(sm, 'default')
-        default.setObject("myEventService", EventService())
-        default.setObject("myObjectHub", self.getObjectHub())
-
-        path = "%s/default/myEventService" % getPath(sm)
-        configuration = ServiceConfiguration(EventPublication, path,
-                                             self.rootFolder)
-        default.getConfigurationManager().setObject(
-            "myEventServiceDir", configuration)
-        traverse(default.getConfigurationManager(), '1').status = Active
-
-        configuration = ServiceConfiguration(EventSubscription, path,
-                                             self.rootFolder)
-        default.getConfigurationManager().setObject(
-                "mySubscriptionServiceDir", configuration)
-        traverse(default.getConfigurationManager(), '2').status = Active
-
-        path = "%s/default/myObjectHub" % getPath(sm)
-        configuration = ServiceConfiguration(HubIds, path, self.rootFolder)
-        default.getConfigurationManager().setObject("myHubIdsServiceDir",
-                                                    configuration)
-        traverse(default.getConfigurationManager(), '3').status = Active
-
-def addService(servicemanager, name, service):
-    default = traverse(servicemanager, 'default')
-    default.setObject(name, service)
-    path = "%s/default/%s" % (getPath(servicemanager), name)
-    configuration = ServiceConfiguration(name, path, servicemanager)
-    default.getConfigurationManager().setObject("", configuration)
-    traverse(default.getConfigurationManager(), '1').status = Active
-    
-
-def createServiceManager(folder):
-    folder.setServiceManager(ServiceManager())
-    return traverse(folder, "++etc++site")
+
+        setup.createStandardServices(self.rootFolder,
+                                     hubids=self.getObjectHub())
+


=== Zope3/src/zope/app/services/tests/test_adapter.py 1.12 => 1.12.2.1 ===
--- Zope3/src/zope/app/services/tests/test_adapter.py:1.12	Wed May 21 16:30:05 2003
+++ Zope3/src/zope/app/services/tests/test_adapter.py	Sun Jun 22 10:23:28 2003
@@ -17,18 +17,18 @@
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
-from zope.app.services.tests.iconfigurable import TestingIConfigurable
+from zope.app.services.tests.iregistry import TestingIRegistry
 from zope.app.services.adapter import AdapterService
-from zope.interface import Interface, directlyProvides
-from zope.proxy.context import ContextWrapper
+from zope.interface import Interface, directlyProvides, implements
+from zope.app.context import ContextWrapper
 from zope.component.exceptions import ComponentLookupError
 from zope.app.services.tests.placefulsetup import PlacefulSetup
-from zope.app.services.service import ServiceManager
-from zope.app.services.adapter import AdapterConfiguration
+from zope.app.services.adapter import AdapterRegistration
 from zope.app.content.folder import RootFolder
 from zope.app.traversing import traverse
 from zope.component.interfaces import IServiceService
 from zope.component.adapter import provideAdapter
+from zope.component.service import serviceManager
 
 class I1(Interface):
     pass
@@ -49,7 +49,7 @@
     pass
 
 
-class Configuration:
+class Registration:
     forInterface = I1
     providedInterface = I2
     adapterName = ''
@@ -67,12 +67,10 @@
         self.context = object
 
 
-class TestAdapterService(PlacefulSetup, TestingIConfigurable, TestCase):
+class TestAdapterService(PlacefulSetup, TestingIRegistry, TestCase):
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-        self.buildFolders()
-        self.rootFolder.setServiceManager(ServiceManager())
+        PlacefulSetup.setUp(self, site=True)
         self._service = ContextWrapper(AdapterService(), self.rootFolder)
 
     def test_implements_IAdapterService(self):
@@ -81,11 +79,11 @@
 
         verifyObject(IAdapterService, self._service)
 
-    def createTestingConfigurable(self):
+    def createTestingRegistry(self):
         return ContextWrapper(AdapterService(), C())
 
-    def createTestingConfiguration(self):
-        return Configuration()
+    def createTestingRegistration(self):
+        return Registration()
 
     def test_conforms(self):
         service = self._service
@@ -111,7 +109,7 @@
     def test_queryAdapter_no_adapter(self):
         service = self._service
         class O:
-            __implements__ = I1
+            implements(I1)
 
         o = O()
         self.assertEqual(service.queryAdapter(o, I2), None)
@@ -123,7 +121,7 @@
     def test_getAdapter_no_adapter(self):
         service = self._service
         class O:
-            __implements__ = I1
+            implements(I1)
 
         o = O()
         self.assertRaises(ComponentLookupError, service.getAdapter, O(), I2)
@@ -134,19 +132,19 @@
 
         sm = traverse(self.rootFolder, '++etc++site')
 
-        configure = traverse(sm, 'default').getConfigurationManager()
-        configuration = Configuration()
-        configure.setObject('', configuration)
-        configuration = traverse(configure, '1')
+        registration_manager = traverse(sm, 'default').getRegistrationManager()
+        registration = Registration()
+        registration_manager.setObject('', registration)
+        registration = traverse(registration_manager, '1')
 
         class O:
-            __implements__ = I1
+            implements(I1)
 
-        configuration.factory = A
+        registration.factory = A
 
-        registry = service.createConfigurationsFor(configuration)
-        registry.register(configuration)
-        registry.activate(configuration)
+        registry = service.createRegistrationsFor(registration)
+        registry.register(registration)
+        registry.activate(registration)
 
         o = O()
 
@@ -172,20 +170,20 @@
 
         sm = traverse(self.rootFolder, '++etc++site')
 
-        configure = traverse(sm, 'default').getConfigurationManager()
-        configuration = Configuration()
-        configuration.adapterName = u"Yatta!"
-        configure.setObject('', configuration)
-        configuration = traverse(configure, '1')
+        registration_manager = traverse(sm, 'default').getRegistrationManager()
+        registration = Registration()
+        registration.adapterName = u"Yatta!"
+        registration_manager.setObject('', registration)
+        registration = traverse(registration_manager, '1')
 
         class O:
-            __implements__ = I1
+            implements(I1)
 
-        configuration.factory = A
+        registration.factory = A
 
-        registry = service.createConfigurationsFor(configuration)
-        registry.register(configuration)
-        registry.activate(configuration)
+        registry = service.createRegistrationsFor(registration)
+        registry.register(registration)
+        registry.activate(registration)
 
         o = O()
 
@@ -220,24 +218,21 @@
     def test_queryAdapter_delegation(self):
         service = self._service
 
-        self.buildFolders()
-        self.rootFolder.setServiceManager(ServiceManager())
-
         sm = traverse(self.rootFolder, '++etc++site')
 
-        configure = traverse(sm, 'default').getConfigurationManager()
-        configuration = Configuration()
-        configure.setObject('', configuration)
-        configuration = traverse(configure, '1')
+        registration_manager = traverse(sm, 'default').getRegistrationManager()
+        registration = Registration()
+        registration_manager.setObject('', registration)
+        registration = traverse(registration_manager, '1')
 
         class O:
-            __implements__ = I1
+            implements(I1)
 
-        configuration.factory = A
+        registration.factory = A
 
-        registry = service.createConfigurationsFor(configuration)
-        registry.register(configuration)
-        registry.activate(configuration)
+        registry = service.createRegistrationsFor(registration)
+        registry.register(registration)
+        registry.activate(registration)
 
         o = O()
 
@@ -253,7 +248,7 @@
         service = self._service
 
         class O:
-            __implements__ = I1
+            implements(I1)
 
         o = O()
 
@@ -267,7 +262,7 @@
 
     def test_getRegisteredMatching(self):
         self.test_queryAdapter_and_getAdapter()
-        registry = self._service.queryConfigurations(I1, I2, '')
+        registry = self._service.queryRegistrations(I1, I2, '')
 
         for args in ((), (I1E, ), (None, I2), (I1E, I2), ):
             r = self._service.getRegisteredMatching(*args)
@@ -275,35 +270,40 @@
 
 class PhonyServiceManager:
 
-    __implements__ = IServiceService
+    implements(IServiceService)
 
     def resolve(self, name):
         if name == 'Foo.Bar.A':
             return A
 
-class TestAdapterConfiguration(PlacefulSetup, TestCase):
+    def getService(self, name):
+        return serviceManager.getService(name)
+
+
+class TestAdapterRegistration(PlacefulSetup, TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self)
         rootFolder = RootFolder()
         rootFolder.setServiceManager(PhonyServiceManager())
-        self.configuration = ContextWrapper(
-            AdapterConfiguration(I1, I2, "Foo.Bar.A", "adapter"),
+
+        self.registration = ContextWrapper(
+            AdapterRegistration(I1, I2, "Foo.Bar.A", "adapter"),
             rootFolder,
             )
 
     def test_getAdapter(self):
         c = C()
-        adapter = self.configuration.getAdapter(c)
+        adapter = self.registration.getAdapter(c)
         self.assertEqual(adapter.__class__, A)
         self.assertEqual(adapter.context, c)
-        self.assertEqual(self.configuration.forInterface, I1)
-        self.assertEqual(self.configuration.providedInterface, I2)
+        self.assertEqual(self.registration.forInterface, I1)
+        self.assertEqual(self.registration.providedInterface, I2)
 
 def test_suite():
     return TestSuite((
         makeSuite(TestAdapterService),
-        makeSuite(TestAdapterConfiguration),
+        makeSuite(TestAdapterRegistration),
         ))
 
 if __name__=='__main__':


=== Zope3/src/zope/app/services/tests/test_auth.py 1.13 => 1.13.10.1 ===
--- Zope3/src/zope/app/services/tests/test_auth.py:1.13	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_auth.py	Sun Jun 22 10:23:28 2003
@@ -22,16 +22,16 @@
 
 from zope.exceptions import NotFoundError
 from zope.publisher.interfaces.http import IHTTPCredentials
-from zope.app.services.service import ServiceConfiguration
 from zope.app.services.tests.eventsetup import EventSetup
-from zope.app.traversing import getPath, traverse
-from zope.app.interfaces.services.configuration import Active
+from zope.app.traversing import traverse
 
 from zope.app.container.tests.test_icontainer import BaseTestIContainer
+from zope.interface import implements
+from zope.app.tests import setup
 
 class Request:
 
-    __implements__ = IHTTPCredentials
+    implements(IHTTPCredentials)
 
     def __init__(self, lpw):
         self.__lpw = lpw
@@ -55,20 +55,8 @@
         getService(None, Adapters).provideAdapter(
             IHTTPCredentials, ILoginPassword, BasicAuthAdapter)
 
-        folder = self.rootFolder
-
-        if not folder.hasServiceManager():
-            self.createServiceManager(folder)
-
-        default = traverse(folder, '++etc++site/default')
-        key = default.setObject("AuthenticationService", AuthenticationService())
-        auth = traverse(default, key)
-
-        path = getPath(auth)
-        configuration = ServiceConfiguration(Authentication, path)
-        configure = default.getConfigurationManager()
-        key = configure.setObject(None, configuration)
-        traverse(configure, key).status = Active
+        sm = traverse(self.rootFolder, '++etc++site')
+        auth = setup.addService(sm, Authentication, AuthenticationService())
 
         auth.setObject('srichter', User('srichter', 'Stephan', 'Richter',
                                         'srichter', 'hello'))


=== Zope3/src/zope/app/services/tests/test_cachingservice.py 1.8 => 1.8.16.1 ===
--- Zope3/src/zope/app/services/tests/test_cachingservice.py:1.8	Sun Mar 23 17:35:42 2003
+++ Zope3/src/zope/app/services/tests/test_cachingservice.py	Sun Jun 22 10:23:28 2003
@@ -17,24 +17,25 @@
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.tests import setup
 from zope.interface.verify import verifyObject
+from zope.interface import implements
 from zope.app.interfaces.cache.cache import ICache
 from zope.app.interfaces.cache.cache import ICachingService
-from zope.app.services.cache import CacheConfiguration
-from zope.app.interfaces.services.configuration import Active, Registered
+from zope.app.services.cache import CacheRegistration
+from zope.app.interfaces.services.registration import RegisteredStatus
+from zope.app.interfaces.services.registration import ActiveStatus
 from zope.app.services.tests.eventsetup import EventSetup
-from zope.app.services.service import ServiceConfiguration
 from zope.app.traversing import getPath, traverse
-
+from zope.app.interfaces.annotation import IAttributeAnnotatable
 
 def sort(list):
     list.sort()
     return list
 
-
 class CacheStub:
 
-    __implements__ = ICache
+    implements(ICache, IAttributeAnnotatable)
 
     def __init__(self, name):
         self.name = name
@@ -50,37 +51,21 @@
     def createCachingService(self, path=None):
         from zope.app.services.cache import CachingService
 
-        folder = self.rootFolder
-        if path is not None:
-            folder = traverse(folder, path)
-
-        if not folder.hasServiceManager():
-            self.createServiceManager(folder)
-
-        default = traverse(folder, '++etc++site/default')
-        key = default.setObject("myCachingService", CachingService())
-        service = traverse(default, key)
-
-        path = getPath(service)
-        configuration = ServiceConfiguration("Caching", path)
-        configure = default.getConfigurationManager()
-        key = configure.setObject(None, configuration)
-        traverse(configure, key).status = Active
+        sm = self.makeSite(path)
+        return setup.addService(sm, "Caching", CachingService())
 
         return service
 
-    def addCache(self, name, cache=None, cname=None, status=Active, folder=''):
+    def addCache(self, name, cache=None, cname=None, status=ActiveStatus, folder=''):
         if not cache:
             cache = CacheStub("%s/%s" % (folder, name))
         if not cname:
             cname = name
-        default = traverse(self.rootFolder,
-                           folder +'/++etc++site/default')
+        default = traverse(self.rootFolder, folder +'/++etc++site/default')
         key = default.setObject(cname, cache)
         cache = traverse(default, key)
-        configure = default.getConfigurationManager()
-        key = configure.setObject(None, CacheConfiguration(name,
-                                                           getPath(cache)))
+        configure = default.getRegistrationManager()
+        key = configure.setObject('', CacheRegistration(name, getPath(cache)))
         traverse(configure, key).status = status
         return cache
 
@@ -92,7 +77,7 @@
         self.service = self.createCachingService()
         self.cache1 = self.addCache('cache1')
         self.cache2 = self.addCache('cache2')
-        self.cache3 = self.addCache('cache3', status=Registered)
+        self.cache3 = self.addCache('cache3', status=RegisteredStatus)
         self.service_f1 = self.createCachingService('folder1')
         self.cache1_f1 = self.addCache('cache1', folder='folder1')
         self.cache4_f1 = self.addCache('cache4', folder='folder1')


=== Zope3/src/zope/app/services/tests/test_connectionservice.py 1.8 => 1.8.10.1 ===
--- Zope3/src/zope/app/services/tests/test_connectionservice.py:1.8	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_connectionservice.py	Sun Jun 22 10:23:28 2003
@@ -17,35 +17,25 @@
 
 import unittest
 
-from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.container.zopecontainer import ZopeContainerAdapter
-from zope.app.dependable import Dependable
-from zope.app.interfaces.annotation import IAnnotatable
-from zope.app.interfaces.annotation import IAnnotations
 from zope.app.interfaces.annotation import IAttributeAnnotatable
-from zope.app.interfaces.dependable import IDependable
-from zope.app.interfaces.dependable import IDependable
 from zope.app.interfaces.rdb import IZopeDatabaseAdapter
-from zope.app.interfaces.services.configuration import Active, Registered
-from zope.app.interfaces.services.configuration \
-     import IAttributeUseConfigurable, IUseConfiguration
-from zope.app.services.configuration import UseConfiguration
-from zope.app.services.connection import ConnectionConfiguration
+from zope.app.interfaces.services.registration import RegisteredStatus
+from zope.app.interfaces.services.registration import ActiveStatus
+from zope.app.interfaces.services.registration import IAttributeRegisterable
+from zope.app.services.connection import ConnectionRegistration
 from zope.app.services.connection import ConnectionService
-from zope.app.services.service import ServiceConfiguration
-from zope.app.services.service import ServiceManager
 from zope.app.services.tests.placefulsetup import PlacefulSetup
-from zope.app.traversing import traverse
-from zope.component.adapter import provideAdapter
+from zope.app.tests import setup
+from zope.app import zapi
+from zope.interface import implements
 
 class ConnectionServiceForTests(ConnectionService):
 
-    __implements__ = (ConnectionService.__implements__,
-                      IAttributeUseConfigurable)
+    implements(IAttributeRegisterable)
 
 class DAStub:
 
-    __implements__ = IZopeDatabaseAdapter, IAttributeAnnotatable
+    implements(IZopeDatabaseAdapter, IAttributeAnnotatable)
 
     def __init__(self, n):
         self.n = n
@@ -62,65 +52,44 @@
 class TestConnectionService(unittest.TestCase, PlacefulSetup):
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-
-        provideAdapter(IAttributeAnnotatable,
-                       IAnnotations, AttributeAnnotations)
-        provideAdapter(IAnnotatable, IDependable, Dependable)
-        provideAdapter(IAttributeAnnotatable, IUseConfiguration,
-                       UseConfiguration)
-
-        # Set up a local connection service
-        self.buildFolders()
-        self.rootFolder.setServiceManager(ServiceManager())
-
-        self.default = traverse(self.rootFolder,
-                                '++etc++site/default')
-        self.default.setObject('conn_srv', ConnectionServiceForTests())
-        self.service = traverse(self.default, 'conn_srv')
-
-        self.cm = ZopeContainerAdapter(self.default.getConfigurationManager())
-        self.cm.setObject('', ServiceConfiguration('SQLDatabaseConnections',
-                                '/++etc++site/default/conn_srv'))
-        traverse(self.default.getConfigurationManager(), '1').status = Active
+        sm = PlacefulSetup.setUp(self, site=True)
+        self.service = setup.addService(sm, 'SQLDatabaseConnections',
+                                        ConnectionServiceForTests())
+        self.default = zapi.traverse(sm, 'default')
 
         self.default.setObject('da1', DAStub(1))
         self.default.setObject('da2', DAStub(2))
 
-        self.cm.setObject('', ConnectionConfiguration('conn1',
+        self.cm = self.default.getRegistrationManager()
+
+        k = self.cm.setObject('', ConnectionRegistration('conn1',
                                 '/++etc++site/default/da1'))
-        traverse(self.default.getConfigurationManager(), '2').status = Active
-        self.cm.setObject('', ConnectionConfiguration('conn2',
+        zapi.traverse(self.default.getRegistrationManager(), k).status = ActiveStatus
+        k = self.cm.setObject('', ConnectionRegistration('conn2',
                                 '/++etc++site/default/da2'))
-        traverse(self.default.getConfigurationManager(), '3').status = Active
-        self.cm.setObject('', ConnectionConfiguration('conn3',
+        zapi.traverse(self.default.getRegistrationManager(), k).status = ActiveStatus
+        k = self.cm.setObject('', ConnectionRegistration('conn3',
                                 '/++etc++site/default/da1'))
-        traverse(self.default.getConfigurationManager(),
-                 '4').status = Registered
+        zapi.traverse(self.default.getRegistrationManager(),
+                 k).status = RegisteredStatus
         # Now self.service has conn1 and conn2 available and knows about conn3
 
-        # Set up a more local connection service
-        folder1 = traverse(self.rootFolder, 'folder1')
-        folder1.setServiceManager(ServiceManager())
-
-        default1 = traverse(folder1, '++etc++site/default')
-        default1.setObject('conn_srv1', ConnectionServiceForTests())
-        self.service1 = traverse(default1, 'conn_srv1')
-
-        cm1 = ZopeContainerAdapter(default1.getConfigurationManager())
-        cm1.setObject('', ServiceConfiguration('SQLDatabaseConnections',
-                '/folder1/++etc++site/default/conn_srv1'))
-        traverse(default1.getConfigurationManager(), '1').status = Active
+        sm = self.makeSite('folder1')
+        self.service1 = setup.addService(sm, 'SQLDatabaseConnections',
+                                         ConnectionServiceForTests())
 
+        default1 = zapi.traverse(sm, 'default')
         default1.setObject('da3', DAStub(3))
         default1.setObject('da4', DAStub(4))
 
-        cm1.setObject('', ConnectionConfiguration('conn1',
+        cm1 = default1.getRegistrationManager()
+
+        k = cm1.setObject('', ConnectionRegistration('conn1',
                             '/folder1/++etc++site/default/da3'))
-        traverse(default1.getConfigurationManager(), '2').status = Active
-        cm1.setObject('', ConnectionConfiguration('conn4',
+        zapi.traverse(default1.getRegistrationManager(), k).status = ActiveStatus
+        k = cm1.setObject('', ConnectionRegistration('conn4',
                             '/folder1/++etc++site/default/da4'))
-        traverse(default1.getConfigurationManager(), '3').status = Active
+        zapi.traverse(default1.getRegistrationManager(), k).status = ActiveStatus
         # Now self.service1 overrides conn1, adds new conn4 available, and
         # inherits conn2 from self.service
 


=== Zope3/src/zope/app/services/tests/test_cookiesessionservice.py 1.3 => 1.3.18.1 ===
--- Zope3/src/zope/app/services/tests/test_cookiesessionservice.py:1.3	Fri Feb 28 09:19:38 2003
+++ Zope3/src/zope/app/services/tests/test_cookiesessionservice.py	Sun Jun 22 10:23:28 2003
@@ -20,12 +20,13 @@
 from zope.app.interfaces.services.session import ISessionService
 from zope.app.interfaces.services.session import ISessionDataManager
 from zope.app.services.session import CookieSessionService
+from zope.interface import implements
 
 import time
 
 class DummyDataManager:
 
-    __implements__ = ISessionDataManager
+    implements(ISessionDataManager)
 
     def __init__(self):
         self.data = {}


=== Zope3/src/zope/app/services/tests/test_eventservice.py 1.20 => 1.20.10.1 ===
--- Zope3/src/zope/app/services/tests/test_eventservice.py:1.20	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_eventservice.py	Sun Jun 22 10:23:28 2003
@@ -18,8 +18,7 @@
 """
 
 from unittest import TestCase, TestLoader, TextTestRunner
-from zope.interface import Interface
-from zope.app.services.service import ServiceManager, ServiceConfiguration
+from zope.interface import Interface, implements
 from zope.app.services.servicenames import EventPublication, EventSubscription
 from zope.app.services.event import EventService
 from zope.app.traversing import getPath, traverse
@@ -33,13 +32,14 @@
 from zope.app.interfaces.event import ISubscriber
 from zope.app.event.objectevent import ObjectAddedEvent, ObjectModifiedEvent
 from zope.app.interfaces.event import IEvent, ISubscribingAware
-from zope.app.interfaces.services.configuration import Active
-from zope.app.interfaces.services.configuration import Registered
-from zope.proxy.context import ContextWrapper
+from zope.app.interfaces.services.registration import RegisteredStatus
+from zope.app.context import ContextWrapper
 from zope.app.services.tests.eventsetup import EventSetup
 from zope.component.tests.components import RecordingAdapter
 from zope.component.adapter import provideAdapter
 from zope.app.interfaces.services.service import ISimpleService
+from zope.app.services.event import EventService
+from zope.app.tests import setup
 
 class UnpromotingEventService(EventService):
 
@@ -49,11 +49,11 @@
 
 class DummyEvent:
 
-    __implements__ = IObjectAddedEvent, IObjectRemovedEvent
+    implements(IObjectAddedEvent, IObjectRemovedEvent)
 
 class ObjectEvent:
 
-    __implements__ = IObjectEvent
+    implements(IObjectEvent)
 
 class IObjectHub(Interface):
     def getObject(hubid):
@@ -66,7 +66,7 @@
         "gets location"
 
 class DumbObjectHub:
-    __implements__ = IObjectHub, ISimpleService
+    implements(IObjectHub, ISimpleService)
 
     def __init__(self):
         # (location, object)
@@ -93,12 +93,12 @@
     pass
 
 class HasSubscribingAwareAdapter(DummySubscriber):
-    __implements__ = IHasSubscribingAwareAdapter, ISubscriber
+    implements(IHasSubscribingAwareAdapter, ISubscriber)
 
 
 class SubscribingAwareAdapter(RecordingAdapter):
 
-    __implements__ = ISubscribingAware
+    implements(ISubscribingAware)
 
     def subscribedTo(self, subscribable, event_type, filter):
         self.record.append(('subscribed', self.context, subscribable,
@@ -119,9 +119,12 @@
         return self.objectHub
 
     def _createNestedServices(self):
-        self.createEventService('folder1')
-        self.createEventService('folder1/folder1_1')
-        self.createEventService('folder1/folder1_1/folder1_1_1')
+        for path in ('folder1', 'folder1/folder1_1',
+                     'folder1/folder1_1/folder1_1_1'):
+            sm = self.makeSite(path)
+            events = EventService()
+            setup.addService(sm, EventPublication, events)
+            setup.addService(sm, EventSubscription, events, suffix='s')
 
     def _createSubscribers(self):
         self.rootFolder.setObject("rootFolderSubscriber", DummySubscriber())
@@ -223,7 +226,7 @@
         # curve balls:
         unsubscribeAll(self.folder1Subscriber, context=self.folder1_1)
         unsubscribe(2,
-                    event_type=IObjectAddedEvent, 
+                    event_type=IObjectAddedEvent,
                     context=self.folder1_1)
         publish(self.folder1, ObjectAddedEvent(None, '/foo'))
         self.assertEqual(self.rootFolderSubscriber.notified, 1)
@@ -253,15 +256,21 @@
         self.assertEqual(self.folder1Subscriber.notified, 0)
         self.assertEqual(self.folder1_1Subscriber.notified, 1)
 
-        # Now, put folder1Subscriber back. It should not be notified
-        # now, because it was removed as a bad subscriber.
+        # Now, put folder1Subscriber back. This incidentally fires off a
+        # ObjectAddedEvent, since self.folder1 is decorated with a context
+        # decorator.
         self.folder1.setObject('folder1Subscriber', folder1Subscriber)
-
-        publish(self.folder1, ObjectAddedEvent(None, '/foo'))
         self.assertEqual(self.rootFolderSubscriber.notified, 2)
         self.assertEqual(self.folder1Subscriber.notified, 0)
         self.assertEqual(self.folder1_1Subscriber.notified, 2)
 
+        # folder1Subscriber should not be notified now, because it was removed
+        # as a bad subscriber.
+        publish(self.folder1, ObjectAddedEvent(None, '/foo'))
+        self.assertEqual(self.rootFolderSubscriber.notified, 3)
+        self.assertEqual(self.folder1Subscriber.notified, 0)
+        self.assertEqual(self.folder1_1Subscriber.notified, 3)
+
     def testByPathExplicit(self):
         # test complex interaction, with hubids available but explicitly
         # using paths
@@ -826,23 +835,9 @@
             self.folder2,
             name="folder2Subscriber")
 
-        if not self.folder2.hasServiceManager():
-            self.folder2.setServiceManager(ServiceManager())
-
-        sm = traverse(self.rootFolder, 'folder2/++etc++site')
-        default = traverse(sm, 'default')
-
-        default.setObject("myEventService", service)
-
-        path = "%s/default/myEventService" % getPath(sm)
-        configuration = ServiceConfiguration(EventPublication, path)
-        default.getConfigurationManager().setObject("myEventServiceDir", configuration)
-        traverse(default.getConfigurationManager(), '1').status = Active
-
-        configuration = ServiceConfiguration(EventSubscription, path)
-        default.getConfigurationManager().setObject("mySubscriptionServiceDir",
-                                       configuration)
-        traverse(default.getConfigurationManager(), '2').status = Active
+        sm = self.makeSite('folder2')
+        setup.addService(sm, EventPublication, service);
+        setup.addService(sm, EventSubscription, service, suffix='s');
 
         subscribe(
             self.rootFolderSubscriber,
@@ -890,14 +885,14 @@
             )
 
         sm = traverse(self.rootFolder, "folder1/++etc++site")
-        configuration = sm.queryConfigurations(EventPublication).active()
-        configuration.status = Registered
+        registration = sm.queryRegistrations(EventPublication).active()
+        registration.status = RegisteredStatus
         publish(self.rootFolder, ObjectAddedEvent(None, '/foo'))
         self.assertEqual(self.folder1Subscriber.notified, 1)
         self.assertEqual(self.folder1_1Subscriber.notified, 1)
 
-        configuration = sm.queryConfigurations(EventSubscription).active()
-        configuration.status = Registered
+        registration = sm.queryRegistrations(EventSubscription).active()
+        registration.status = RegisteredStatus
 
         publish(self.rootFolder, ObjectAddedEvent(None, '/foo'))
         self.assertEqual(self.folder1Subscriber.notified, 1)
@@ -914,12 +909,12 @@
         self.assertEqual(self.rootFolderSubscriber.notified, 1)
 
         sm = traverse(self.rootFolder, "folder2/++etc++site")
-        configuration = sm.queryConfigurations(EventSubscription).active()
+        registration = sm.queryRegistrations(EventSubscription).active()
         # make sure it doesn't raise any errors
-        configuration.status = Registered
-        configuration = sm.queryConfigurations(EventPublication).active()
+        registration.status = RegisteredStatus
+        registration = sm.queryRegistrations(EventPublication).active()
         # make sure it doesn't raise any errors
-        configuration.status = Registered
+        registration.status = RegisteredStatus
 
     def testSubscriptionAwareInteraction(self):
         adapter = SubscribingAwareAdapter()


=== Zope3/src/zope/app/services/tests/test_field.py 1.6 => 1.6.18.1 ===
--- Zope3/src/zope/app/services/tests/test_field.py:1.6	Thu Mar 13 12:10:37 2003
+++ Zope3/src/zope/app/services/tests/test_field.py	Sun Jun 22 10:23:28 2003
@@ -20,13 +20,13 @@
 from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.traversing import traverse
 from zope.schema.interfaces import ValidationError
-from zope.interface import Interface
+from zope.interface import Interface, implements
 
 from zope.app.interfaces.services.module import IModuleService
 from zope.component.interfaces import IServiceService
 
 class ModuleService:
-    __implements__ = IModuleService, IServiceService
+    implements(IModuleService, IServiceService)
     # I'm lying about implementing IServiceService, but that is needed to get
     # a ModuleService as a service manager.  (See XXX comment in module.py.)
     def __init__(self, name=None, component=None):
@@ -45,7 +45,7 @@
 class I1(Interface):  pass
 
 class C:
-    __implements__ = I1
+    implements(I1)
 
 class D:
     pass
@@ -126,6 +126,11 @@
         some_class = self.__class__
         resolver = ModuleService(dotted_name, some_class)
         self.rootFolder.setServiceManager(resolver)
+
+        # We have to re-traverse to get new wrappers, since the old
+        # wrappers have stale caches.
+        folder2 = traverse(self.rootFolder, 'folder2')
+
         self.assertEqual(locateComponent(dotted_name, folder2),
                          some_class
                          )


=== Zope3/src/zope/app/services/tests/test_folder.py 1.3 => 1.3.16.1 ===
--- Zope3/src/zope/app/services/tests/test_folder.py:1.3	Sun Mar 23 14:24:46 2003
+++ Zope3/src/zope/app/services/tests/test_folder.py	Sun Jun 22 10:23:28 2003
@@ -17,12 +17,12 @@
 """
 
 import unittest
-from zope.app.services.tests.test_configurationmanager \
-     import ConfigurationManagerContainerTests
+from zope.app.services.tests.test_registrationmanager \
+     import RegistrationManagerContainerTests
 
 
-class TestSomething(ConfigurationManagerContainerTests, unittest.TestCase):
-    "Test configuration manager access"
+class TestSomething(RegistrationManagerContainerTests, unittest.TestCase):
+    "Test registration manager access"
         
 
 def test_suite():


=== Zope3/src/zope/app/services/tests/test_interface.py 1.6 => 1.6.4.1 ===
--- Zope3/src/zope/app/services/tests/test_interface.py:1.6	Sat May  3 12:33:22 2003
+++ Zope3/src/zope/app/services/tests/test_interface.py	Sun Jun 22 10:23:28 2003
@@ -48,7 +48,7 @@
 
     def tearDown(self):
         get_transaction().abort() # just in case
-    
+
     def test_creation(self):
         class IFoo(PersistentInterface):
             pass
@@ -66,11 +66,11 @@
 
         # test for a pickling bug
         self.assertEqual(imodule.Foo.__implements__, imodule.IFoo)
-        
+
         self.assert_(imodule.IFoo.isImplementedBy(imodule.aFoo))
         # the conversion should not affect Interface
         self.assert_(imodule.Interface is Interface)
-        
+
 
 def test_suite():
     return unittest.makeSuite(PersistentInterfaceTest)


=== Zope3/src/zope/app/services/tests/test_module.py 1.6 => 1.6.10.1 ===
--- Zope3/src/zope/app/services/tests/test_module.py:1.6	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_module.py	Sun Jun 22 10:23:28 2003
@@ -16,10 +16,9 @@
 Revision information:
 $Id$
 """
-from unittest import TestCase, TestLoader, TextTestRunner
 
-from zope.interface import Interface
-from zope.app.services.service import ServiceManager
+from unittest import TestCase, TestLoader, TextTestRunner
+from zope.interface import Interface, implements
 from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.traversing import traverse
 from zope.app.services.module import Manager
@@ -33,19 +32,14 @@
 
 class TestService:
 
-    __implements__ = ITestService
+    implements(ITestService)
 
 class ServiceManagerTests(PlacefulSetup, TestCase):
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-        self.buildFolders()
-
-    def _Test__new(self):
-        return ServiceManager()
+        PlacefulSetup.setUp(self, site=True)
 
     def test_resolve(self):
-        self.rootFolder.setServiceManager(ServiceManager())
         sm = traverse(self.rootFolder, "++etc++site")
         default = traverse(sm, "default")
         default.setObject('m1', Manager())


=== Zope3/src/zope/app/services/tests/test_objecthub.py 1.9 => 1.9.10.1 ===
--- Zope3/src/zope/app/services/tests/test_objecthub.py:1.9	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_objecthub.py	Sun Jun 22 10:23:28 2003
@@ -40,6 +40,7 @@
 from zope.exceptions import NotFoundError
 
 from zope.app.traversing import canonicalPath
+from zope.interface import implements
 
 # while these tests don't really test much of the placeful aspect of the
 # object hub, they do at least test basic functionality.
@@ -209,7 +210,7 @@
         from zope.app.interfaces.traversing import ITraverser
         from zope.app.traversing.adapters import Traverser
         class DummyTraverser(Traverser):
-            __implements__ = ITraverser
+            implements(ITraverser)
             def traverse(self, location, *args, **kw):
                 if location in TestSearchRegistrations.locations:
                     return fake_object_for_location(location)
@@ -459,7 +460,6 @@
 
         hub.notify(added_event)
         hubid = hub.getHubId(location)
-
         hub.notify(moved_event)
 
         location_from_hub = hub.getPath(hubid)


=== Zope3/src/zope/app/services/tests/test_pagefolder.py 1.3 => 1.3.16.1 ===
--- Zope3/src/zope/app/services/tests/test_pagefolder.py:1.3	Sun Mar 23 17:35:42 2003
+++ Zope3/src/zope/app/services/tests/test_pagefolder.py	Sun Jun 22 10:23:28 2003
@@ -17,54 +17,49 @@
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.tests import setup
 from zope.app.services.tests.placefulsetup import PlacefulSetup
-from zope.app.services.pagefolder import PageFolder
+from zope.app.services.pagefolder import PageFolder, PageFolderContextDecorator
+from zope.app.interfaces.services.pagefolder import IPageFolder
+from zope.app.interfaces.context import IZopeContextWrapper
 from zope.app.traversing import traverse
 from zope.app.services.zpt import ZPTTemplate
 from zope.app.services.view import ViewService
-from zope.app.interfaces.services.configuration import Active
-from zope.app.services.service import ServiceManager
-from zope.app.services.service import ServiceConfiguration
+from zope.app.interfaces.services.registration import ActiveStatus
 from zope.interface import Interface
 from zope.publisher.interfaces.browser import IBrowserPresentation
-from zope.app.services.tests.test_configurationmanager \
-     import ConfigurationManagerContainerTests
+from zope.app.services.tests.test_registrationmanager \
+     import RegistrationManagerContainerTests
+from zope.component.adapter import provideAdapter
 
-class I(Interface): pass
+class I(Interface):
+    pass
 
-class Test(ConfigurationManagerContainerTests, PlacefulSetup, TestCase):
+class Test(RegistrationManagerContainerTests, PlacefulSetup, TestCase):
 
     def test_setObject(self):
-        self.buildFolders()
-        self.rootFolder.setServiceManager(ServiceManager())
+        provideAdapter(IPageFolder, IZopeContextWrapper,
+                       PageFolderContextDecorator)
+        sm = self.buildFolders(site=True)
+        setup.addService(sm, 'Views', ViewService(), suffix='service')
+
         default = traverse(self.rootFolder, '++etc++site/default')
         default.setObject('Views', PageFolder())
         views = traverse(default, 'Views')
         views.forInterface = I
         views.factoryName = None
         views.permission = 'zope.View'
-
-        #set up view service
-        default.setObject('ViewService', ViewService())
-        configure = default.getConfigurationManager()
-        configuration = ServiceConfiguration(
-            'Views',
-            '/++etc++site/default/ViewService')
-        configure.setObject('', configuration)
-        configuration = traverse(configure, '1')
-        configuration.status = Active
-
         views.setObject('foo.html', ZPTTemplate())
 
-        configuration = traverse(views.getConfigurationManager(), '1')
-        self.assertEqual(configuration.status, Active)
-        self.assertEqual(configuration.forInterface, I)
-        self.assertEqual(configuration.presentationType, IBrowserPresentation)
-        self.assertEqual(configuration.viewName, u'foo.html')
-        self.assertEqual(configuration.layer, 'default')
-        self.assertEqual(configuration.class_, None)
-        self.assertEqual(configuration.permission, 'zope.View')
-        self.assertEqual(configuration.attribute, None)
+        registration = traverse(views.getRegistrationManager(), '1')
+        self.assertEqual(registration.status, ActiveStatus)
+        self.assertEqual(registration.forInterface, I)
+        self.assertEqual(registration.presentationType, IBrowserPresentation)
+        self.assertEqual(registration.viewName, u'foo.html')
+        self.assertEqual(registration.layer, 'default')
+        self.assertEqual(registration.class_, None)
+        self.assertEqual(registration.permission, 'zope.View')
+        self.assertEqual(registration.attribute, None)
 
         self.assertRaises(TypeError,
                           views.setObject, 'bar.html', PageFolder())


=== Zope3/src/zope/app/services/tests/test_principalannotation.py 1.3 => 1.3.10.1 ===
--- Zope3/src/zope/app/services/tests/test_principalannotation.py:1.3	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_principalannotation.py	Sun Jun 22 10:23:28 2003
@@ -19,7 +19,7 @@
 from unittest import TestCase, TestLoader, TextTestRunner
 from zope.app.services.tests.placefulsetup \
     import PlacefulSetup
-from zope.component import getServiceManager, getService
+from zope.component import getServiceManager
 from zope.app.services.principalannotation import \
      PrincipalAnnotationService, AnnotationsForPrincipal
 from zope.app.interfaces.services.principalannotation import \
@@ -28,11 +28,13 @@
 from zope.component import getAdapter
 from zope.app.interfaces.annotation import IAnnotations
 from zope.app.interfaces.security import IPrincipal
+from zope.app.tests import setup
+from zope.interface import implements
 
 
 class Principal:
 
-    __implements__ = IPrincipal
+    implements(IPrincipal)
 
     def __init__(self, id):
         self.id = id
@@ -45,45 +47,50 @@
 
     def setUp(self):
         PlacefulSetup.setUp(self)
-        self.buildFolders()
+        sm = self.buildFolders(site='/')
 
         root_sm = getServiceManager(None)
 
         svc = PrincipalAnnotationService()
 
-        root_sm.defineService("PrincipalAnnotation", IPrincipalAnnotationService)
+        root_sm.defineService("PrincipalAnnotation",
+                              IPrincipalAnnotationService)
         root_sm.provideService("PrincipalAnnotation", svc)
 
-        self.createServiceManager()
-
-        sm = getServiceManager(self.rootFolder)
-        sm.PrincipalAnnotation = svc
-
-        self.svc = getService(self.rootFolder, "PrincipalAnnotation")
+        self.svc = setup.addService(sm, 'PrincipalAnnotation', svc)
 
     def testGetSimple(self):
         prince = Principal('somebody')
-        self.assert_(not self.svc.hasAnnotation(prince.getId()))
+        self.assert_(not self.svc.hasAnnotations(prince))
 
-        princeAnnotation = self.svc.getAnnotation(prince.getId())
-        self.assert_(self.svc.hasAnnotation(prince.getId()))
+        princeAnnotation = self.svc.getAnnotations(prince)
+        # Just getting doesn't actualy store. We don't want to store unless
+        # we make a change.
+        self.assert_(not self.svc.hasAnnotations(prince))
 
         princeAnnotation['something'] = 'whatever'
 
+        # But now we should have the annotation:
+        self.assert_(self.svc.hasAnnotations(prince))
+
     def testGetFromLayered(self):
         princeSomebody = Principal('somebody')
-        self.createServiceManager(self.folder1)
-        sm1 = getServiceManager(self.folder1)
-        sm1.PrincipalAnnotation = PrincipalAnnotationService()
-        subService = getService(self.folder1, "PrincipalAnnotation")
-
-        parentAnnotation = self.svc.getAnnotation(princeSomebody.getId())
-        self.assert_(self.svc.hasAnnotation(princeSomebody.getId()))
-        self.assert_(not subService.hasAnnotation(princeSomebody.getId()))
+        sm1 = self.makeSite('folder1')
+        subService = setup.addService(sm1, 'PrincipalAnnotation',
+                                      PrincipalAnnotationService())
+
+        parentAnnotation = self.svc.getAnnotations(princeSomebody)
+
+        # Just getting doesn't actualy store. We don't want to store unless
+        # we make a change.
+        self.assert_(not subService.hasAnnotations(princeSomebody))
 
         parentAnnotation['hair_color'] = 'blue'
 
-        subAnnotation = subService.getAnnotation(princeSomebody.getId())
+        # But now we should have the annotation:
+        self.assert_(self.svc.hasAnnotations(princeSomebody))
+
+        subAnnotation = subService.getAnnotations(princeSomebody)
         self.assertEquals(subAnnotation['hair_color'], 'blue')
 
         subAnnotation['foo'] = 'bar'
@@ -93,7 +100,8 @@
 
     def testAdapter(self):
         p = Principal('somebody')
-        provideAdapter(IPrincipal, IAnnotations, AnnotationsForPrincipal(self.svc))
+        provideAdapter(IPrincipal, IAnnotations,
+                       AnnotationsForPrincipal(self.svc))
         annotations = getAdapter(p, IAnnotations)
         annotations["test"] = "bar"
         annotations = getAdapter(p, IAnnotations)


=== Zope3/src/zope/app/services/tests/test_roleservice.py 1.2 => 1.2.26.1 ===
--- Zope3/src/zope/app/services/tests/test_roleservice.py:1.2	Wed Dec 25 09:13:20 2002
+++ Zope3/src/zope/app/services/tests/test_roleservice.py	Sun Jun 22 10:23:28 2003
@@ -16,10 +16,11 @@
 Revision information:
 $Id$
 """
+
 from unittest import TestCase, TestLoader, TextTestRunner
-from zope.app.services.tests.placefulsetup \
-    import PlacefulSetup
-from zope.component import getServiceManager, getService
+from zope.app.tests import setup
+from zope.app.services.tests.placefulsetup import PlacefulSetup
+from zope.component import getServiceManager
 from zope.app.interfaces.security import IRoleService
 from zope.app.security.registries.roleregistry import roleRegistry
 from zope.app.services.role import RoleService
@@ -31,8 +32,7 @@
         return RoleService()
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-        self.buildFolders()
+        sm = PlacefulSetup.setUp(self, site=True)
 
         root_sm = getServiceManager(None)
 
@@ -40,13 +40,7 @@
         self.roleRegistry = roleRegistry
         root_sm.provideService("Roles", roleRegistry)
 
-        self.createServiceManager()
-
-        sm = getServiceManager(self.rootFolder)
-        rs = RoleService()
-        sm.Roles = rs
-
-        self.rs = getService(self.rootFolder,"Roles")
+        self.rs = setup.addService(sm, 'Roles', RoleService())
 
     def testGetRole(self):
         self.roleRegistry.defineRole('Manager', 'Manager', '')
@@ -67,11 +61,8 @@
         r = Role("Hacker","","")
         self.rs.setObject("Hacker", r)
 
-        self.createServiceManager(self.folder1)
-        sm1 = getServiceManager(self.folder1)
-        sm1.Roles = RoleService()
-
-        rs1 = getService(self.folder1, "Roles")
+        sm1 = self.makeSite('folder1')
+        rs1 = setup.addService(sm1, 'Roles', RoleService())
 
         r1 = Role("Reviewer",'','')
         rs1.setObject("Reviewer", r1)


=== Zope3/src/zope/app/services/tests/test_servicemanager.py 1.8 => 1.8.10.1 ===
--- Zope3/src/zope/app/services/tests/test_servicemanager.py:1.8	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_servicemanager.py	Sun Jun 22 10:23:28 2003
@@ -18,51 +18,43 @@
 """
 from unittest import TestCase, TestLoader, TextTestRunner
 
-from zope.interface import Interface
-from zope.proxy.context import getWrapperContainer
+from zope.interface import Interface, implements
+from zope.context import getWrapperContainer
 from zope.app.services.service import ServiceManager
-from zope.app.services.service import ServiceConfiguration
+from zope.app.services.service import ServiceRegistration
 from zope.component import getService, getServiceManager
 from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.traversing import traverse
-from zope.app.interfaces.services.configuration import Active, Unregistered
-from zope.app.interfaces.services.configuration import Registered
+from zope.app.interfaces.services.registration import UnregisteredStatus
+from zope.app.interfaces.services.registration import ActiveStatus
+from zope.app.interfaces.services.registration import RegisteredStatus
 from zope.component.service import serviceManager
+from zope.app.interfaces.annotation import IAttributeAnnotatable
 
 class ITestService(Interface):
     pass
 
 class TestService:
-
-    __implements__ = ITestService
+    implements(ITestService, IAttributeAnnotatable)
 
 class ServiceManagerTests(PlacefulSetup, TestCase):
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-        self.buildFolders()
-
+        PlacefulSetup.setUp(self, site=True)
         serviceManager.defineService('test_service', ITestService)
 
-    def _Test__new(self):
-        return ServiceManager()
-
-    def createServiceManager(self):
-        self.rootFolder.setServiceManager(ServiceManager())
-
     def testGetService(self):
-        self.createServiceManager()
         sm = traverse(self.rootFolder, '++etc++site')
         default = traverse(sm, 'default')
 
         ts = TestService()
         default.setObject('test_service1', ts)
-        configuration = ServiceConfiguration(
+        registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service1')
 
-        default.getConfigurationManager().setObject('', configuration)
-        traverse(default.getConfigurationManager(), '1').status = Active
+        default.getRegistrationManager().setObject('', registration)
+        traverse(default.getRegistrationManager(), '1').status = ActiveStatus
 
         testOb = getService(self.rootFolder, 'test_service')
         c = getWrapperContainer
@@ -70,7 +62,6 @@
         self.assertEqual(testOb, ts)
 
     def test_queryLocalService(self):
-        self.createServiceManager()
         sm = traverse(self.rootFolder, '++etc++site')
 
         # Test no service case
@@ -84,11 +75,11 @@
         default = traverse(sm, 'default')
         ts = TestService()
         default.setObject('test_service1', ts)
-        configuration = ServiceConfiguration(
+        registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service1')
-        default.getConfigurationManager().setObject('', configuration)
-        traverse(default.getConfigurationManager(), '1').status = Active
+        default.getRegistrationManager().setObject('', registration)
+        traverse(default.getRegistrationManager(), '1').status = ActiveStatus
 
         testOb = sm.queryLocalService('test_service')
         c = getWrapperContainer
@@ -97,32 +88,31 @@
 
 
     def test_get(self):
-        self.createServiceManager()
         sm = traverse(self.rootFolder, '++etc++site')
         default = sm.get('default')
         self.assertEqual(default, sm.Packages['default'])
         self.assertEqual(sm.get('spam'), None)
 
     def testAddService(self):
-        self.createServiceManager()
         sm = traverse(self.rootFolder, '++etc++site')
         default = traverse(sm, 'default')
 
         ts1 = TestService()
         default.setObject('test_service1', ts1)
-        configuration = ServiceConfiguration(
+        registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service1')
-        default.getConfigurationManager().setObject('', configuration)
-        traverse(default.getConfigurationManager(), '1').status = Active
+        default.getRegistrationManager().setObject('', registration)
+        traverse(default.getRegistrationManager(), '1').status = ActiveStatus
 
         ts2 = TestService()
         default.setObject('test_service2', ts2)
-        configuration = ServiceConfiguration(
+        registration = ServiceRegistration(
             'test_service',
             '/++etc++site/default/test_service2')
-        default.getConfigurationManager().setObject('', configuration)
-        traverse(default.getConfigurationManager(), '2').status = Registered
+        default.getRegistrationManager().setObject('', registration)
+        traverse(default.getRegistrationManager(), '2'
+                 ).status = RegisteredStatus
 
         testOb = getService(self.rootFolder, 'test_service')
         self.assertEqual(testOb, ts1)
@@ -137,8 +127,8 @@
         self.testGetService() # set up localservice
 
         sm = traverse(self.rootFolder, '++etc++site')
-        cm = traverse(sm, 'default').getConfigurationManager()
-        traverse(cm, '1').status = Unregistered
+        cm = traverse(sm, 'default').getRegistrationManager()
+        traverse(cm, '1').status = UnregisteredStatus
 
         self.assertEqual(getService(self.rootFolder, 'test_service'), root_ts)
 
@@ -152,15 +142,14 @@
         self.testGetService() # set up root localservice
         sm=getServiceManager(self.rootFolder)
 
-        self.folder1.setServiceManager(ServiceManager())
-        sm2=getServiceManager(self.folder1)
+        sm2 = self.makeSite('folder1')
 
         self.assertEqual(getService(self.folder1, 'test_service'),
                          sm['default']['test_service1'])
 
     def testComponentArchitectureServiceLookup(self):
-        self.rootFolder.setServiceManager(ServiceManager())
-        self.folder1.setServiceManager(ServiceManager())
+        self.makeSite()
+        self.makeSite('folder1')
 
         ts = TestService()
 
@@ -171,13 +160,13 @@
         self.assertEqual(service, ts)
 
     def test_resolve(self):
-        from zope.proxy.context import ContextWrapper as cw
+        from zope.app.context import ContextWrapper as cw
         from zope.app.services.module import Manager
         import zope.app.services.tests.sample1
         import zope.app.services.tests.sample2
 
-        self.rootFolder.setServiceManager(ServiceManager())
-        sm=getServiceManager(self.rootFolder)
+        sm = self.makeSite()
+
         default = cw(sm['default'], self.rootFolder, name='default')
         default.setObject('m1', Manager())
         manager = cw(default['m1'], default, name='m1')


=== Zope3/src/zope/app/services/tests/test_utility.py 1.5 => 1.5.10.1 ===
--- Zope3/src/zope/app/services/tests/test_utility.py:1.5	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_utility.py	Sun Jun 22 10:23:28 2003
@@ -19,20 +19,23 @@
 """
 
 import unittest
+from zope.app.tests import setup
 from zope.app.services.tests import placefulsetup
 from zope.app.services import utility
 from zope.component.utility import utilityService as globalUtilityService
-from zope.interface import Interface
+from zope.interface import Interface, implements
 from zope.component import getService
 from zope.component.exceptions import ComponentLookupError
 from zope.app.traversing import traverse
-from zope.app.interfaces.services.configuration import IConfigurationRegistry
-from zope.app.interfaces.services.configuration \
-     import Active, Registered, Unregistered
+from zope.app.interfaces.services.registration import IRegistrationStack
+from zope.app.interfaces.services.registration import UnregisteredStatus
+from zope.app.interfaces.services.registration import RegisteredStatus
+from zope.app.interfaces.services.registration import ActiveStatus
 from zope.app.interfaces.services.utility import ILocalUtility
-from zope.app.interfaces.services.configuration import IUseConfiguration
+from zope.app.interfaces.services.registration import IRegistered
 from zope.app.interfaces.dependable import IDependable
-from zope.proxy.context import getWrapperContainer
+from zope.context import getWrapperContainer
+from zope.app.tests import setup
 
 class IFo(Interface): pass
 
@@ -43,9 +46,9 @@
 
 
 class Foo:
-    # We implement IUseConfiguration and IDependable directly to
+    # We implement IRegistered and IDependable directly to
     # depend as little  as possible on other infrastructure.
-    __implements__ = IFoo, ILocalUtility, IUseConfiguration, IDependable
+    implements(IFoo, ILocalUtility, IRegistered, IDependable)
 
     def __init__(self, name):
         self.name = name
@@ -56,16 +59,16 @@
         return 'foo ' + self.name
     
     def addUsage(self, location):
-        "See zope.app.interfaces.services.configuration.IUseConfiguration"
+        "See zope.app.interfaces.services.registration.IRegistered"
         if location not in self._usages:
             self._usages.append(location)
     
     def removeUsage(self, location):
-        "See zope.app.interfaces.services.configuration.IUseConfiguration"
+        "See zope.app.interfaces.services.registration.IRegistered"
         self._usages.remove(location)
             
     def usages(self):
-        "See zope.app.interfaces.services.configuration.IUseConfiguration"
+        "See zope.app.interfaces.services.registration.IRegistered"
         return self._usages
 
     def addDependent(self, location):
@@ -84,11 +87,9 @@
 class TestUtilityService(placefulsetup.PlacefulSetup, unittest.TestCase):
 
     def setUp(self):
-        placefulsetup.PlacefulSetup.setUp(self)
-        self.buildFolders()
-        sm = placefulsetup.createServiceManager(self.rootFolder)
-        placefulsetup.addService(sm, "Utilities",
-                                 utility.LocalUtilityService())
+        sm = placefulsetup.PlacefulSetup.setUp(self, site=True)
+        setup.addService(sm, "Utilities",
+                         utility.LocalUtilityService())
 
     def test_queryUtility_delegates_to_global(self):
         globalUtilityService.provideUtility(IFoo, Foo("global"))
@@ -137,19 +138,19 @@
                           utility_service.getUtility, IFoo, name='rob')
 
 
-    def test_configurationsFor_methods(self):
+    def test_registrationsFor_methods(self):
         utilities = getService(self.rootFolder, "Utilities")
         default = traverse(self.rootFolder, "++etc++Services/default")
         default.setObject('foo', Foo("local"))
         path = "/++etc++Services/default/foo"
 
         for name in ('', 'bob'):
-            configuration = utility.UtilityConfiguration(name, IFoo, path)
-            self.assertEqual(utilities.queryConfigurationsFor(configuration),
+            registration = utility.UtilityRegistration(name, IFoo, path)
+            self.assertEqual(utilities.queryRegistrationsFor(registration),
                              None)
-            registery = utilities.createConfigurationsFor(configuration)
-            self.assert_(IConfigurationRegistry.isImplementedBy(registery))
-            self.assertEqual(utilities.queryConfigurationsFor(configuration),
+            registery = utilities.createRegistrationsFor(registration)
+            self.assert_(IRegistrationStack.isImplementedBy(registery))
+            self.assertEqual(utilities.queryRegistrationsFor(registration),
                              registery)
 
 
@@ -162,23 +163,23 @@
         default = traverse(self.rootFolder, "++etc++Services/default")
         default.setObject('foo', Foo("local"))
         path = "/++etc++Services/default/foo"
-        cm = default.getConfigurationManager()
+        cm = default.getRegistrationManager()
 
         for name in ('', 'bob'):
-            configuration = utility.UtilityConfiguration(name, IFoo, path)
-            cname = cm.setObject('', configuration)
-            configuration = traverse(cm, cname)
+            registration = utility.UtilityRegistration(name, IFoo, path)
+            cname = cm.setObject('', registration)
+            registration = traverse(cm, cname)
 
             gout = name and "foo global "+name or "foo global"
 
             self.assertEqual(utilities.getUtility(IFoo, name=name).foo(), gout)
 
-            configuration.status = Active
+            registration.status = ActiveStatus
 
             self.assertEqual(utilities.getUtility(IFoo, name=name).foo(),
                              "foo local")
 
-            configuration.status = Registered
+            registration.status = RegisteredStatus
 
             self.assertEqual(utilities.getUtility(IFoo, name=name).foo(), gout)
 
@@ -188,16 +189,16 @@
         r = list(utilities.getRegisteredMatching())
         r.sort()
         path = "/++etc++Services/default/foo"
-        cr1 = utilities.queryConfigurationsFor(
-            utility.UtilityConfiguration("", IFoo, path))
-        cr2 = utilities.queryConfigurationsFor(
-            utility.UtilityConfiguration("bob", IFoo, path))
+        cr1 = utilities.queryRegistrationsFor(
+            utility.UtilityRegistration("", IFoo, path))
+        cr2 = utilities.queryRegistrationsFor(
+            utility.UtilityRegistration("bob", IFoo, path))
         self.assertEqual(r, [(IFoo, "", cr1), (IFoo, "bob", cr2)])
         self.assertEqual(getWrapperContainer(r[0][2]), utilities)
         self.assertEqual(getWrapperContainer(r[1][2]), utilities)
         # Now test that an empty registry doesn't show up
         for cd in cr1.info(): # Remove everything from cr1
-            cd['configuration'].status = Unregistered
+            cd['registration'].status = UnregisteredStatus
         self.assertEqual(bool(cr1), False)
         r = list(utilities.getRegisteredMatching())
         self.assertEqual(r, [(IFoo, "bob", cr2)])


=== Zope3/src/zope/app/services/tests/test_view.py 1.11 => 1.11.10.1 ===
--- Zope3/src/zope/app/services/tests/test_view.py:1.11	Thu May  1 15:35:35 2003
+++ Zope3/src/zope/app/services/tests/test_view.py	Sun Jun 22 10:23:28 2003
@@ -17,14 +17,14 @@
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
-from zope.app.services.tests.iconfigurable import TestingIConfigurable
+from zope.app.services.tests.iregistry import TestingIRegistry
 from zope.app.services.view import ViewService
-from zope.interface import Interface, directlyProvides
-from zope.proxy.context import ContextWrapper
+from zope.interface import Interface, directlyProvides, implements
+from zope.app.context import ContextWrapper
 from zope.component.exceptions import ComponentLookupError
 from zope.app.services.tests.placefulsetup import PlacefulSetup
 from zope.app.services.service import ServiceManager
-from zope.app.services.view import ViewConfiguration
+from zope.app.services.view import ViewRegistration
 from zope.app.content.folder import RootFolder
 from zope.app.traversing import traverse
 from zope.component.interfaces import IServiceService
@@ -32,10 +32,10 @@
 from zope.publisher.browser import TestRequest
 from zope.publisher.interfaces.browser import IBrowserPresentation
 from zope.app.interfaces.services.view import IZPTTemplate
-from zope.app.services.view import PageConfiguration, BoundTemplate
+from zope.app.services.view import PageRegistration, BoundTemplate
 from zope.interface.verify import verifyObject
 from zope.component.interfaces import IViewService
-from zope.proxy.introspection import removeAllProxies
+from zope.proxy import removeAllProxies
 from zope.configuration.exceptions import ConfigurationError
 
 class I1(Interface):
@@ -53,7 +53,7 @@
     pass
 
 
-class Configuration:
+class Registration:
     forInterface = I1
     presentationType = I2
     viewName = 'test'
@@ -69,7 +69,7 @@
 
 class PhonyTemplate:
 
-    __implements__ = IZPTTemplate
+    implements(IZPTTemplate)
 
 class A:
     def __init__(self, object, request):
@@ -78,12 +78,10 @@
 
     run = PhonyTemplate()
 
-class TestViewService(PlacefulSetup, TestingIConfigurable, TestCase):
+class TestViewService(PlacefulSetup, TestingIRegistry, TestCase):
 
     def setUp(self):
-        PlacefulSetup.setUp(self)
-        self.buildFolders()
-        self.rootFolder.setServiceManager(ServiceManager())
+        PlacefulSetup.setUp(self, site=True)
         self._service = ContextWrapper(ViewService(), self.rootFolder)
 
     def test_implements_IViewService(self):
@@ -93,11 +91,11 @@
         verifyObject(IViewService, self._service)
 
 
-    def createTestingConfigurable(self):
+    def createTestingRegistry(self):
         return ContextWrapper(ViewService(), C())
 
-    def createTestingConfiguration(self):
-        return Configuration()
+    def createTestingRegistration(self):
+        return Registration()
 
     def test_implements_IViewService(self):
         verifyObject(IViewService, ViewService())
@@ -105,7 +103,7 @@
     def test_queryView_no_view(self):
         service = self._service
         class O:
-            __implements__ = I1
+            implements(I1)
 
         o = O()
         request = TestRequest()
@@ -115,7 +113,7 @@
     def test_getView_no_view(self):
         service = self._service
         class O:
-            __implements__ = I1
+            implements(I1)
 
         o = O()
         request = TestRequest()
@@ -127,19 +125,19 @@
 
         sm = traverse(self.rootFolder, '++etc++site')
 
-        configure = traverse(sm, 'default').getConfigurationManager()
-        configuration = Configuration()
-        configure.setObject('', configuration)
-        configuration = traverse(configure, '1')
+        registration_manager = traverse(sm, 'default').getRegistrationManager()
+        registration = Registration()
+        registration_manager.setObject('', registration)
+        registration = traverse(registration_manager, '1')
 
         class O:
-            __implements__ = I1
+            implements(I1)
 
-        configuration.factory = A
+        registration.factory = A
 
-        registry = service.createConfigurationsFor(configuration)
-        registry.register(configuration)
-        registry.activate(configuration)
+        registry = service.createRegistrationsFor(registration)
+        registry.register(registration)
+        registry.activate(registration)
 
         o = O()
         request = TestRequest()
@@ -157,18 +155,14 @@
     def test_queryView_delegation(self):
         service = self._service
 
-        self.buildFolders()
-        self.rootFolder.setServiceManager(ServiceManager())
-
-        sm = traverse(self.rootFolder, '++etc++site')
-
-        configure = traverse(sm, 'default').getConfigurationManager()
-        configuration = Configuration()
-        configure.setObject('', configuration)
-        configuration = traverse(configure, '1')
+        sm = self.buildFolders(site=True)
+        registration_manager = traverse(sm, 'default').getRegistrationManager()
+        registration = Registration()
+        registration_manager.setObject('', registration)
+        registration = traverse(registration_manager, '1')
 
         class O:
-            __implements__ = I1
+            implements(I1)
 
         o = O()
         request = TestRequest()
@@ -184,7 +178,7 @@
 
     def test_getRegisteredMatching(self):
         self.test_queryView_and_getView()
-        registry = self._service.queryConfigurationsFor(Configuration())
+        registry = self._service.queryRegistrationsFor(Registration())
 
         for args in ((), (I1E, ), (None, I2), (I1E, I2), ):
             r = self._service.getRegisteredMatching(*args)
@@ -192,20 +186,20 @@
 
 class PhonyServiceManager(ServiceManager):
 
-    __implements__ = IServiceService
+    implements(IServiceService)
 
     def resolve(self, name):
         if name == 'Foo.Bar.A':
             return A
 
-class TestViewConfiguration(PlacefulSetup, TestCase):
+class TestViewRegistration(PlacefulSetup, TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self)
         rootFolder = RootFolder()
         rootFolder.setServiceManager(PhonyServiceManager())
-        self.configuration = ContextWrapper(
-            ViewConfiguration(I1, 'test', IBrowserPresentation, "Foo.Bar.A",
+        self.registration = ContextWrapper(
+            ViewRegistration(I1, 'test', IBrowserPresentation, "Foo.Bar.A",
                               'zope.View'),
             rootFolder,
             )
@@ -213,15 +207,15 @@
     def test_getView(self):
         c = C()
         request = TestRequest()
-        view = self.configuration.getView(c, request)
+        view = self.registration.getView(c, request)
         self.assertEqual(view.__class__, A)
         self.assertEqual(view.context, c)
         self.assertEqual(view.request, request)
-        self.assertEqual(self.configuration.forInterface, I1)
-        self.assertEqual(self.configuration.presentationType, I2)
+        self.assertEqual(self.registration.forInterface, I1)
+        self.assertEqual(self.registration.presentationType, I2)
 
 
-class TestPageConfiguration(PlacefulSetup, TestCase):
+class TestPageRegistration(PlacefulSetup, TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self)
@@ -232,8 +226,8 @@
         default.setObject('t', self.__template)
 
     def test_getView_template(self):
-        configuration = ContextWrapper(
-            PageConfiguration(I1, 'test', 'zope.View',
+        registration = ContextWrapper(
+            PageRegistration(I1, 'test', 'zope.View',
                               "Foo.Bar.A",
                               template='/++etc++site/default/t',
                               ),
@@ -242,7 +236,7 @@
 
         c = C()
         request = TestRequest()
-        view = configuration.getView(c, request)
+        view = registration.getView(c, request)
         self.assertEqual(view.__class__, BoundTemplate)
         self.assertEqual(removeAllProxies(view).template, self.__template)
 
@@ -250,12 +244,12 @@
         self.assert_(issubclass(view.__class__, A))
         self.assertEqual(view.context, c)
         self.assertEqual(view.request, request)
-        self.assertEqual(configuration.forInterface, I1)
-        self.assertEqual(configuration.presentationType, I2)
+        self.assertEqual(registration.forInterface, I1)
+        self.assertEqual(registration.presentationType, I2)
 
     def test_getView_attribute(self):
-        configuration = ContextWrapper(
-            PageConfiguration(I1, 'test', 'zope.View',
+        registration = ContextWrapper(
+            PageRegistration(I1, 'test', 'zope.View',
                               "Foo.Bar.A",
                               attribute='run',
                               ),
@@ -263,29 +257,29 @@
             )
         c = C()
         request = TestRequest()
-        view = configuration.getView(c, request)
+        view = registration.getView(c, request)
         self.assertEquals(view, A.run)
 
     def test_getView_errors(self):
-        configuration = ContextWrapper(
-            PageConfiguration(I1, 'test', 'zope.View',
+        registration = ContextWrapper(
+            PageRegistration(I1, 'test', 'zope.View',
                               "Foo.Bar.A",
                               ),
             self.rootFolder,
             )
         c = C()
         request = TestRequest()
-        self.assertRaises(ConfigurationError, configuration.getView, c, request)
-        configuration.template = '/++etc++site/default/t'
-        configuration.attribute = 'run'
-        self.assertRaises(ConfigurationError, configuration.getView, c, request)
+        self.assertRaises(ConfigurationError, registration.getView, c, request)
+        registration.template = '/++etc++site/default/t'
+        registration.attribute = 'run'
+        self.assertRaises(ConfigurationError, registration.getView, c, request)
 
 
 def test_suite():
     return TestSuite((
         makeSuite(TestViewService),
-        makeSuite(TestViewConfiguration),
-        makeSuite(TestPageConfiguration),
+        makeSuite(TestViewRegistration),
+        makeSuite(TestPageRegistration),
         ))
 
 if __name__=='__main__':

=== Removed File Zope3/src/zope/app/services/tests/configurationregistry.py ===

=== Removed File Zope3/src/zope/app/services/tests/iconfigurable.py ===

=== Removed File Zope3/src/zope/app/services/tests/servicemanager.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_cacheconfiguration.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_configurationmanager.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_configurationregistry.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_configurations.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_configurationstatusproperty.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_connectionconfiguration.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_nameconfigurable.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_serviceconfiguration.py ===

=== Removed File Zope3/src/zope/app/services/tests/test_useconfiguration.py ===