[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Service/tests - testServiceManagerBindings.py:1.1.2.1

Michael McLay mclay@nist.gov
Sat, 9 Feb 2002 17:56:05 -0500


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

Added Files:
      Tag: Zope-3x-branch
	testServiceManagerBindings.py 
Log Message:
Added preliminary test for ServiceManagerBindings
Fixed minor bugs for ServicesManagerBindingsView and ServiceManager

Note: Known bug (test commented out) in ServiceManagerBindingsView - 
  It returns 'Acquired' when it should return 'None' in the bound variable of
  the service map.


=== Added File Zope3/lib/python/Zope/App/Service/tests/testServiceManagerBindings.py ===
##############################################################################
#
# Copyright (c) 2001 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: testServiceManagerBindings.py,v 1.1.2.1 2002/02/09 22:56:04 mclay Exp $
"""
import unittest

from Interface import Interface

from Zope.App.Service.ServiceManager import ServiceManager
from Zope.App.Service.ServiceManagerBindingsView import ServiceManagerBindingsView


class ITestService1(Interface): pass
class ITestService2(Interface): pass

class TestService1:

    __implements__ = ITestService1

class TestService2:

    __implements__ = ITestService2


class ServiceManagerTests(unittest.TestCase):

    def setUp(self):
	sm = ServiceManager()
	sm.defineService('service1', ITestService1)
	sm.defineService('service2', ITestService2)
	
	sA = TestService1()
	sB = TestService1()
	sC = TestService2()

	sm.setObject('TestServiceA', sA)
	sm.setObject('TestServiceB', sB)
	sm.setObject('TestServiceC', sC)

	sm.bindService('service1', 'TestServiceA')
	
	self.sm = sm

    def testGetServicesTable(self):
	view = ServiceManagerBindingsView(self.sm)
	self.assertEqual(len(view.getServicesTable()), 2)

    def testServiceTableBound(self):
	view = ServiceManagerBindingsView(self.sm)
	services = view.getServicesTable()
	serviceMap = None
	for sMap in services:
	    if sMap['name'] == 'service1':
		serviceMap = sMap
		break
	    
	self.assertEqual(serviceMap['bound'], 'TestServiceA')

## This test is not working (bug in getServicesTable(), returning
## 'Acquired' instead of 'None'
	
##    def testServiceTableNone(self):
##	view = ServiceManagerBindingsView(self.sm)
##	services = view.getServicesTable()
##	serviceMap = None
##	for sMap in services:
##	    if sMap['name'] == 'service2':
##		serviceMap = sMap
##		break
	    
##	self.assertEqual(serviceMap['bound'], 'None')
        
def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(ServiceManagerTests)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())