[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - iregistry.py:1.1 registrationstack.py:1.1 test_cacheregistration.py:1.1 test_connectionregistration.py:1.1 test_nameregistry.py:1.1 test_registered.py:1.1 test_registrationmanager.py:1.1 test_registrations.py:1.1 test_registrationstack.py:1.1 test_registrationstatusproperty.py:1.1 test_serviceregistration.py:1.1 test_adapter.py:1.19 test_cachingservice.py:1.12 test_connectionservice.py:1.12 test_eventservice.py:1.27 test_folder.py:1.4 test_pagefolder.py:1.6 test_servicemanager.py:1.13 test_utility.py:1.9 test_view.py:1.17 configurationregistry.py:NONE iconfigurable.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

Jim Fulton jim@zope.com
Sat, 21 Jun 2003 17:22:46 -0400


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

Modified Files:
	test_adapter.py test_cachingservice.py 
	test_connectionservice.py test_eventservice.py test_folder.py 
	test_pagefolder.py test_servicemanager.py test_utility.py 
	test_view.py 
Added Files:
	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:
	configurationregistry.py iconfigurable.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:
Major refactoring to reflect change in terminology from
"configuration" to "registration" to refer to the configuration of how
objects are used (as opposed to their internal configuration).


=== 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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 2003/06/21 21:22:13 jim 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/test_adapter.py 1.18 => 1.19 ===
--- Zope3/src/zope/app/services/tests/test_adapter.py:1.18	Sat Jun  7 01:32:01 2003
+++ Zope3/src/zope/app/services/tests/test_adapter.py	Sat Jun 21 17:22:13 2003
@@ -17,13 +17,13 @@
 """
 
 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, 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.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
@@ -49,7 +49,7 @@
     pass
 
 
-class Configuration:
+class Registration:
     forInterface = I1
     providedInterface = I2
     adapterName = ''
@@ -67,7 +67,7 @@
         self.context = object
 
 
-class TestAdapterService(PlacefulSetup, TestingIConfigurable, TestCase):
+class TestAdapterService(PlacefulSetup, TestingIRegistry, TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self, site=True)
@@ -79,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
@@ -132,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)
 
-        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()
 
@@ -170,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)
 
-        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,19 +220,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)
 
-        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()
 
@@ -262,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)
@@ -280,30 +280,30 @@
         return serviceManager.getService(name)
 
 
-class TestAdapterConfiguration(PlacefulSetup, TestCase):
+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_cachingservice.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/services/tests/test_cachingservice.py:1.11	Thu Jun  5 08:03:18 2003
+++ Zope3/src/zope/app/services/tests/test_cachingservice.py	Sat Jun 21 17:22:13 2003
@@ -22,8 +22,9 @@
 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.traversing import getPath, traverse
 from zope.app.interfaces.annotation import IAttributeAnnotatable
@@ -55,7 +56,7 @@
 
         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:
@@ -63,8 +64,8 @@
         default = traverse(self.rootFolder, folder +'/++etc++site/default')
         key = default.setObject(cname, cache)
         cache = traverse(default, key)
-        configure = default.getConfigurationManager()
-        key = configure.setObject('', CacheConfiguration(name, getPath(cache)))
+        configure = default.getRegistrationManager()
+        key = configure.setObject('', CacheRegistration(name, getPath(cache)))
         traverse(configure, key).status = status
         return cache
 
@@ -76,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.11 => 1.12 ===
--- Zope3/src/zope/app/services/tests/test_connectionservice.py:1.11	Thu Jun  5 08:03:18 2003
+++ Zope3/src/zope/app/services/tests/test_connectionservice.py	Sat Jun 21 17:22:13 2003
@@ -19,10 +19,10 @@
 
 from zope.app.interfaces.annotation import IAttributeAnnotatable
 from zope.app.interfaces.rdb import IZopeDatabaseAdapter
-from zope.app.interfaces.services.configuration import Active, Registered
-from zope.app.interfaces.services.configuration \
-     import IAttributeUseConfigurable
-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.tests.placefulsetup import PlacefulSetup
 from zope.app.tests import setup
@@ -31,7 +31,7 @@
 
 class ConnectionServiceForTests(ConnectionService):
 
-    implements(IAttributeUseConfigurable)
+    implements(IAttributeRegisterable)
 
 class DAStub:
 
@@ -60,18 +60,18 @@
         self.default.setObject('da1', DAStub(1))
         self.default.setObject('da2', DAStub(2))
 
-        self.cm = self.default.getConfigurationManager()
+        self.cm = self.default.getRegistrationManager()
 
-        k = self.cm.setObject('', ConnectionConfiguration('conn1',
+        k = self.cm.setObject('', ConnectionRegistration('conn1',
                                 '/++etc++site/default/da1'))
-        zapi.traverse(self.default.getConfigurationManager(), k).status = Active
-        k = self.cm.setObject('', ConnectionConfiguration('conn2',
+        zapi.traverse(self.default.getRegistrationManager(), k).status = ActiveStatus
+        k = self.cm.setObject('', ConnectionRegistration('conn2',
                                 '/++etc++site/default/da2'))
-        zapi.traverse(self.default.getConfigurationManager(), k).status = Active
-        k = self.cm.setObject('', ConnectionConfiguration('conn3',
+        zapi.traverse(self.default.getRegistrationManager(), k).status = ActiveStatus
+        k = self.cm.setObject('', ConnectionRegistration('conn3',
                                 '/++etc++site/default/da1'))
-        zapi.traverse(self.default.getConfigurationManager(),
-                 k).status = Registered
+        zapi.traverse(self.default.getRegistrationManager(),
+                 k).status = RegisteredStatus
         # Now self.service has conn1 and conn2 available and knows about conn3
 
         sm = self.makeSite('folder1')
@@ -82,14 +82,14 @@
         default1.setObject('da3', DAStub(3))
         default1.setObject('da4', DAStub(4))
 
-        cm1 = default1.getConfigurationManager()
+        cm1 = default1.getRegistrationManager()
 
-        k = cm1.setObject('', ConnectionConfiguration('conn1',
+        k = cm1.setObject('', ConnectionRegistration('conn1',
                             '/folder1/++etc++site/default/da3'))
-        zapi.traverse(default1.getConfigurationManager(), k).status = Active
-        k = cm1.setObject('', ConnectionConfiguration('conn4',
+        zapi.traverse(default1.getRegistrationManager(), k).status = ActiveStatus
+        k = cm1.setObject('', ConnectionRegistration('conn4',
                             '/folder1/++etc++site/default/da4'))
-        zapi.traverse(default1.getConfigurationManager(), k).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_eventservice.py 1.26 => 1.27 ===
--- Zope3/src/zope/app/services/tests/test_eventservice.py:1.26	Thu Jun  5 08:03:18 2003
+++ Zope3/src/zope/app/services/tests/test_eventservice.py	Sat Jun 21 17:22:13 2003
@@ -32,7 +32,7 @@
 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 Registered
+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
@@ -885,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)
@@ -909,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_folder.py 1.3 => 1.4 ===
--- 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	Sat Jun 21 17:22:13 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_pagefolder.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/services/tests/test_pagefolder.py:1.5	Thu Jun  5 08:03:18 2003
+++ Zope3/src/zope/app/services/tests/test_pagefolder.py	Sat Jun 21 17:22:13 2003
@@ -25,17 +25,17 @@
 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.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 Test(ConfigurationManagerContainerTests, PlacefulSetup, TestCase):
+class Test(RegistrationManagerContainerTests, PlacefulSetup, TestCase):
 
     def test_setObject(self):
         provideAdapter(IPageFolder, IZopeContextWrapper,
@@ -51,15 +51,15 @@
         views.permission = 'zope.View'
         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_servicemanager.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/services/tests/test_servicemanager.py:1.12	Thu Jun  5 08:03:18 2003
+++ Zope3/src/zope/app/services/tests/test_servicemanager.py	Sat Jun 21 17:22:13 2003
@@ -21,12 +21,13 @@
 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
 
@@ -48,12 +49,12 @@
 
         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
@@ -74,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
@@ -98,19 +99,20 @@
 
         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)
@@ -125,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)
 


=== Zope3/src/zope/app/services/tests/test_utility.py 1.8 => 1.9 ===
--- Zope3/src/zope/app/services/tests/test_utility.py:1.8	Sat Jun  7 01:32:01 2003
+++ Zope3/src/zope/app/services/tests/test_utility.py	Sat Jun 21 17:22:13 2003
@@ -27,11 +27,12 @@
 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.context import getWrapperContainer
 from zope.app.tests import setup
@@ -45,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
@@ -58,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):
@@ -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.16 => 1.17 ===
--- Zope3/src/zope/app/services/tests/test_view.py:1.16	Sat Jun  7 01:32:01 2003
+++ Zope3/src/zope/app/services/tests/test_view.py	Sat Jun 21 17:22:13 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, 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,7 +32,7 @@
 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 import removeAllProxies
@@ -53,7 +53,7 @@
     pass
 
 
-class Configuration:
+class Registration:
     forInterface = I1
     presentationType = I2
     viewName = 'test'
@@ -78,7 +78,7 @@
 
     run = PhonyTemplate()
 
-class TestViewService(PlacefulSetup, TestingIConfigurable, TestCase):
+class TestViewService(PlacefulSetup, TestingIRegistry, TestCase):
 
     def setUp(self):
         PlacefulSetup.setUp(self, site=True)
@@ -91,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())
@@ -125,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)
 
-        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()
@@ -156,10 +156,10 @@
         service = self._service
 
         sm = self.buildFolders(site=True)
-        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)
@@ -178,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,14 +192,14 @@
         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,
             )
@@ -207,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)
@@ -226,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',
                               ),
@@ -236,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)
 
@@ -244,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',
                               ),
@@ -257,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/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 ===