[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testUtilityService.py:1.1

Gary Poster garyposter@earthlink.net
Mon, 1 Jul 2002 10:10:00 -0400


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

Added Files:
	testUtilityService.py 
Log Message:
fixed a few small typos I noticed regarding the utility service.  added a simple unit test for the utility service.


=== Added File Zope3/lib/python/Zope/ComponentArchitecture/tests/testUtilityService.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.
#
##############################################################################
"""test utility service

XXX longer description goes here.

$Id: testUtilityService.py,v 1.1 2002/07/01 14:09:59 poster Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.ComponentArchitecture import \
     getUtility, getService, queryUtility, getServiceManager
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError 
from Interface import Interface

from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup

class IDummyService(Interface):
    pass

class DummyService:
    __implements__ = IDummyService

dummyService = DummyService()

class Test(TestCase, CleanUp):
    def setUp(self):
        CleanUp.setUp(self)
        sm=getServiceManager(None)
        defineService=sm.defineService
        provideService=sm.provideService
        from Zope.ComponentArchitecture.IUtilityService import IUtilityService
        defineService('Utilities',IUtilityService)
        from Zope.ComponentArchitecture.GlobalUtilityService import\
             utilityService
        provideService('Utilities', utilityService)
    
    def testGetUtility(self):
        us = getService(None, "Utilities")
        self.assertRaises(
            ComponentLookupError, getUtility, None, IDummyService)
        us.provideUtility(IDummyService, dummyService)
        self.assertEqual(getUtility(None, IDummyService), dummyService)
    
    def testQueryUtility(self):
        us = getService(None, "Utilities")
        self.assertEqual(queryUtility(None, IDummyService), None)
        self.assertEqual(queryUtility(None, IDummyService, self), self)
        us.provideUtility(IDummyService, dummyService)
        self.assertEqual(queryUtility(None, IDummyService), dummyService)
        

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

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