[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture/tests - testServiceManagerContainer.py:1.1 testNextService.py:1.4

Jim Fulton jim@zope.com
Thu, 1 Aug 2002 14:42:40 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv5741/lib/python/Zope/App/ComponentArchitecture/tests

Modified Files:
	testNextService.py 
Added Files:
	testServiceManagerContainer.py 
Log Message:
Removed dependcies of:

  Zope.ComponentArchitecture
  Zope.Configuration
  Zope.Exceptions
  Zope.Testing

on other packages, especially App, in preparation for making these
packages part of Zope 2 and useful outside of the Zope application.

In particular, all placeful service support was moved to
Zope.App.ComponentArchitecture.  

Placeful service implementors should get the nextService and
nextServiceManager functions from
Zope.App.ComponentArchitecture.NextService. 




=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testServiceManagerContainer.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.
# 
##############################################################################
"""

Revision information:
$Id: testServiceManagerContainer.py,v 1.1 2002/08/01 18:42:09 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.ComponentArchitecture.IServiceService import IServiceService
from Zope.App.ComponentArchitecture.IServiceManagerContainer \
     import IServiceManagerContainer
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Interface.Verify import verifyObject
from Zope.ContextWrapper import getbaseobject

class ServiceManager:

    __implements__ =  IServiceService

    ############################################################
    # Implementation methods for interface
    # Zope.ComponentArchitecture.IServiceService.

    def getService(self, object, name):
        '''See interface IServiceService'''
        raise ComponentLookupError(name)

    def getServiceDefinitions(self):
        '''See interface IServiceService'''
        return ()

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

class BaseTestServiceManagerContainer:

    """This test is for objects that don't have service managers by
    default and that always give back the service manager they were
    given.


    Subclasses need to define a method, '_Test__new', that takes no
    arguments and that returns a new service manager
    container that has no service manager."""

    def testIServiceManagerContainerVerify(self):
        verifyObject(IServiceManagerContainer, self._Test__new())
    
    def testHas(self):
        smc=self._Test__new()
        self.failIf(smc.hasServiceManager())
        smc.setServiceManager(ServiceManager())
        self.failUnless(smc.hasServiceManager())

    def testGet(self):
        smc=self._Test__new()
        # since the managers are now wrapped, need to look at base object
        self.failUnless(getbaseobject(smc.queryServiceManager()) is None)
        self.assertRaises(ComponentLookupError, smc.getServiceManager)
        sm=ServiceManager()
        smc.setServiceManager(sm)
        self.failUnless(getbaseobject(smc.getServiceManager()) is sm)
        self.failUnless(getbaseobject(smc.queryServiceManager(self)) is sm)

    def testSet(self):
        smc=self._Test__new()
        self.assertRaises(Exception, smc.setServiceManager, self)



class Test(BaseTestServiceManagerContainer, TestCase):
    def _Test__new(self):
        from Zope.App.ComponentArchitecture.ServiceManagerContainer \
             import ServiceManagerContainer
        return ServiceManagerContainer()


def test_suite():
    return makeSuite(Test)

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


=== Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testNextService.py 1.3 => 1.4 ===
 
 from Zope.ContextWrapper import Wrapper
 
-from Zope.ComponentArchitecture.IServiceManagerContainer \
+from Zope.App.ComponentArchitecture.IServiceManagerContainer \
      import IServiceManagerContainer
 
 from Zope.ComponentArchitecture.IServiceService import IServiceService
@@ -69,15 +69,15 @@
     def test_getNextServiceManager(self):
         from Zope.ComponentArchitecture.GlobalServiceManager \
              import serviceManager
-        from Zope.App.ComponentArchitecture.hooks \
-             import getNextServiceManager_hook
+        from Zope.App.ComponentArchitecture.NextService \
+             import getNextServiceManager
 
         self.assertRaises(ComponentLookupError,
-                          getNextServiceManager_hook, root)
+                          getNextServiceManager, root)
 
-        self.assertEqual(getNextServiceManager_hook(Wrapper(sm1, f1)),
-                                                    serviceManager)
-        self.assertEqual(getNextServiceManager_hook(Wrapper(sm2, f2)), sm1)
+        self.assertEqual(getNextServiceManager(Wrapper(sm1, f1)),
+                         serviceManager)
+        self.assertEqual(getNextServiceManager(Wrapper(sm2, f2)), sm1)
         
 
 def test_suite():