[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ServiceManager/Views/Browser/tests - __init__.py:1.1.2.1 testAdder.py:1.1.2.1 testBindings.py:1.1.2.1 testContents.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 4 Mar 2002 11:48:20 -0500


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

Added Files:
      Tag: Zope-3x-branch
	__init__.py testAdder.py testBindings.py testContents.py 
Log Message:
Moved ServiceManager code to OFS, which is just a logical place for
standard/default TTW object implementations.

Refactored SecurityManager to use container framework.



=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/Views/Browser/tests/__init__.py ===



=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/Views/Browser/tests/testAdder.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: testAdder.py,v 1.1.2.1 2002/03/04 16:48:19 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.OFS.Container.Views.Browser.tests.AdderBaseTests \
     import BaseRegistryTest, BaseAddingTest
from Zope.App.ZMI.Addable import ServiceAddables

class Methods:
    # Supply the methds needed by the bases.

    def _TestView__newContext(self):
        from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
        return ServiceManager()

    def _TestView__newView(self, container):
        from Zope.App.OFS.ServiceManager.Views.Browser.Adder import Adder 
        return Adder(container)

    def _TestAdderView__registry(self):
        return ServiceAddables
    

class RegistryTest(Methods, BaseRegistryTest, TestCase): pass
class AddingTest(Methods, BaseAddingTest, TestCase): pass

def test_suite():
    return TestSuite([makeSuite(RegistryTest),
                      makeSuite(AddingTest),
                      ])

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


=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/Views/Browser/tests/testBindings.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
# 
##############################################################################
"""

$Id: testBindings.py,v 1.1.2.1 2002/03/04 16:48:19 jim Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Interface import Interface

from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
from Zope.App.OFS.ServiceManager.Views.Browser.Bindings \
        import Bindings
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup


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

class TestService1:

    __implements__ = ITestService1

class TestService2:

    __implements__ = ITestService2


class ServiceManagerTests(CleanUp, TestCase):

    def setUp(self):
        CleanUp.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 = Bindings(self.sm)
	self.assertEqual(len(view.getServicesTable()), 2)

    def testServiceTableBound(self):
	view = Bindings(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 = Bindings(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():
    return TestSuite([makeSuite(ServiceManagerTests)])

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


=== Added File Zope3/lib/python/Zope/App/OFS/ServiceManager/Views/Browser/tests/testContents.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors.  All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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: testContents.py,v 1.1.2.1 2002/03/04 16:48:19 jim Exp $
"""

import unittest

from Interface import Interface
from Zope.App.OFS.ServiceManager.Views.Browser.Contents \
     import ServiceManagerContents
from Zope.App.OFS.ServiceManager.ServiceManager import ServiceManager
from Zope.App.OFS.Container.Views.Browser.tests.testContents \
     import BaseTestContentsBrowserView

class IDummy(Interface):
    pass

class Dummy:
    __implements__ = IDummy
    
class Test(BaseTestContentsBrowserView, unittest.TestCase):

    def _TestView__newContext(self):
        return ServiceManager()

    def _TestView__newView(self, container):
        return ServiceManagerContents(container)

    def testExtractContents( self ):
        """ Does _extractContents return the correct information? """

        smc = ServiceManagerContents( None )
        info = smc._extractContentInfo( ('dummy', Dummy(),) )

        self.assert_( 'IDummy' in info['interfaces'] )

    def testInfo( self ):
        """ Do we get the correct information back from
            ServiceManagerContents?
        """

        sm = ServiceManager()
        dummy = Dummy()
        sm.setObject( 'dummy', dummy )

        smc = ServiceManagerContents( sm )
        info_list = smc.listContentInfo()

        self.assertEquals( len( info_list ), 1 )

        interfaces = [ x['interfaces'] for x in info_list ]
        self.assert_( 'IDummy' in interfaces[0] )

def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )

if __name__=='__main__':
    unittest.main()