[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests - TestServiceManager.py:1.1

Jim Fulton jim@zope.com
Mon, 11 Nov 2002 15:17:51 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests
In directory cvs.zope.org:/tmp/cvs-serv15018

Added Files:
	TestServiceManager.py 
Log Message:
Added a service manager implementation suitable for testing placeful
services. This has the advantage that it is much easier to set up
services in it than in full-blown service managers. In particular,
service directives aren't needed.


=== Added File Zope3/lib/python/Zope/App/OFS/Services/ServiceManager/tests/TestServiceManager.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: TestServiceManager.py,v 1.1 2002/11/11 20:17:51 jim Exp $
"""

__metaclass__ = type

from Zope.ComponentArchitecture.IServiceService import IServiceService
from Zope.App.ComponentArchitecture.NextService \
     import getNextService, getNextServiceManager
from Zope.Proxy.ContextWrapper import ContextWrapper

class TestServiceManager:
    """Simple placeful service manager used for writing tests
    """
    __implements__ =  IServiceService


    def getServiceDefinitions(self):
        "See Zope.ComponentArchitecture.IServiceService.IServiceService"
        return getNextServiceManager.getServiceDefinitions()

    def getInterfaceFor(self, name):
        "See Zope.ComponentArchitecture.IServiceService.IServiceService"
        return getNextServiceManager.getServiceDefinitions()

    def getService(self, name):
        "See Zope.ComponentArchitecture.IServiceService.IServiceService"
        if hasattr(self, name):
            return ContextWrapper(getattr(self, name), self, name=name)
        return getNextServiceManager.getService(name)

    def queryService(self, name, default=None):
        "See Zope.ComponentArchitecture.IServiceService.IServiceService"
        if hasattr(self, name):
            return ContextWrapper(getattr(self, name), self, name=name)
        return getNextServiceManager.queryService(name, default)

__doc__ = TestServiceManager.__doc__ + __doc__