[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/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

Christian Theune ct@gocept.com
Sat, 25 May 2002 05:29:20 -0400


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

Added Files:
      Tag: ctheune-services_move-branch
	__init__.py testAdder.py testBindings.py testContents.py 
Log Message:
First part of moving Zope.App.OFS.ServiceManager to Zope.App.OFS.Services.ServiceManager
(physically moved the files)


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



=== Added File Zope3/lib/python/Zope/App/OFS/Services/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/05/25 09:29:19 ctheune Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.OFS.Container.Views.Browser.tests.AdderBaseTests \
     import BaseRegistryTest, BaseAddingTest
from Zope.App.OFS.Services.AddableService.tests.AddableSetup import \
  AddableSetup
from Zope.ComponentArchitecture import getServiceManager

class Methods(AddableSetup):
    # Supply the methods 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 'AddableServices'


class RegistryTest(Methods, BaseRegistryTest, TestCase): pass
class AddingTest(Methods, BaseAddingTest, TestCase):
    def setUp(self):
        Methods.setUp(self)
        BaseAddingTest.setUp(self)

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

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


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

$Id: testBindings.py,v 1.1.2.1 2002/05/25 09:29:19 ctheune Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Interface import Interface

from Zope.App.OFS.ServiceManager.Views.Browser.Bindings \
    import Bindings
from Zope.App.OFS.ServiceManager.tests.PlacefulSetup import \
    PlacefulSetup
from Zope.ComponentArchitecture import getService, getServiceManager

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

class TestService1:

    __implements__ = ITestService1

class TestService2:

    __implements__ = ITestService2


class ServiceManagerTests(PlacefulSetup, TestCase):

    def setUp(self):
        PlacefulSetup.setUp(self)
        self.buildFolders()
        self.createServiceManager()
        self.sm=getServiceManager(self.rootFolder)
        getServiceManager(None).defineService('service1', ITestService1)
        getServiceManager(None).defineService('service2', ITestService2)

        sA = TestService1()
        sB = TestService1()
        sC = TestService2()

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

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

    def testGetServicesTable(self):
        view = Bindings(self.sm)
        self.assertEqual(len(view.getServicesTable()), 8) #that is, 2+6

    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')

## XXX Was commented:
## """This test is not working (bug in getServicesTable(), returning
## 'Acquired' instead of 'None'"""
##
## Then further commented:
## However, we're now acquiring from the globally defined services,
## so it is appropriate to return 'Acquired'.
##
## To which I now add:
## I actually think that it should be 'None' after all.  Where is
## service2 provided globally?
##        
    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/Services/ServiceManager/Views/Browser/tests/testContents.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.
# 
##############################################################################
"""

$Id: testContents.py,v 1.1.2.1 2002/05/25 09:29:19 ctheune 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()