def test_getGlobalServices(self): from zope.component import getGlobalServices from zope.component.service import IGlobalServiceManager gsm = getGlobalServices() self.assert_(IGlobalServiceManager.providedBy(gsm)) self.assert_(getGlobalServices().sm is gsm.sm)
def testGetService(self): # Testing looking up a service from a service manager container that # doesn't have a service manager. getGlobalServices().defineService('one', IOne) c = ServiceOne() getGlobalServices().provideService('one', c) self.assertEqual(id(getService('one')), id(c))
def testInvalid(self): getGlobalServices().defineService('one', IOne) getGlobalServices().defineService('two', ITwo) c = ServiceOne() self.assertRaises(InvalidService, getGlobalServices().provideService, 'two', c)
def getService(self, name): """Retrieve a service implementation Raises ComponentLookupError if the service can't be found. """ if name in (Utilities,): return SimpleLocalUtilityService(self.context) return getGlobalServices().getService(name)
def getService(self, name): """Retrieve a service implementation Raises ComponentLookupError if the service can't be found. """ if name in (Utilities, ): return SimpleLocalUtilityService(self.context) return getGlobalServices().getService(name)
def next(self): obj = self.context while obj is not None: obj = aq_parent(aq_inner(obj)) if ISite.providedBy(obj): return obj.getSiteManager() # only with Zope X3 3.0 always return something else than None # in Zope 3.1+, returning None means global site manager will # be used return getGlobalServices()
def setUp(self): from zope.component import bbb bbb.__warn__ = False bbb.service.__warn__ = False CleanUp.setUp(self) sm = getGlobalServices() defineService = sm.defineService provideService = sm.provideService from zope.component.interfaces import IUtilityService defineService('Utilities',IUtilityService) from zope.component.utility import GlobalUtilityService provideService('Utilities', GlobalUtilityService())
def testGetServiceDefinitions(self): # test that the service definitions are the ones we added sm = getGlobalServices() sm.defineService('one', IOne) c = ServiceOne() sm.provideService('one', c) sm.defineService('two', ITwo) d = ServiceTwo() sm.provideService('two', d) defs = getServiceDefinitions() defs.sort() self.assertEqual(defs, [('Services', IServiceService), ('one', IOne), ('two', ITwo)])
def testDup(self): getGlobalServices().defineService('one', IOne) self.assertRaises(DuplicationError, getGlobalServices().defineService, 'one', ITwo) c = ServiceOne() getGlobalServices().provideService('one', c) c2 = ServiceOne() self.assertRaises(DuplicationError, getGlobalServices().provideService, 'one', c2) self.assertEqual(id(getService('one')), id(c))
def getInterfaceFor(self, name): """Retrieve the service interface for the given name """ return getGlobalServices().getInterfaceFor(name)
def getServiceDefinitions(self): """Retrieve all Service Definitions Should return a list of tuples (name, interface) """ return getGlobalServices().getServiceDefinitions()
def testNormal(self): ss = getGlobalServices() ss.defineService('one', IOne) c = ServiceOne() ss.provideService('one', c) self.assertEqual(id(getService('one',)), id(c))
def getSiteManager(self): return getGlobalServices()
def testUndefined(self): c = ServiceOne() self.assertRaises(UndefinedService, getGlobalServices().provideService, 'one', c)