Exemple #1
0
    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)
Exemple #2
0
 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))
Exemple #3
0
 def testInvalid(self):
     getGlobalServices().defineService('one', IOne)
     getGlobalServices().defineService('two', ITwo)
     c = ServiceOne()
     self.assertRaises(InvalidService,
                       getGlobalServices().provideService,
                       'two', c)
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
 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()
Exemple #7
0
 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())
Exemple #9
0
    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)])
Exemple #10
0
    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))
Exemple #11
0
 def getInterfaceFor(self, name):
     """Retrieve the service interface for the given name
     """
     return getGlobalServices().getInterfaceFor(name)
Exemple #12
0
    def getServiceDefinitions(self):
        """Retrieve all Service Definitions

        Should return a list of tuples (name, interface)
        """
        return getGlobalServices().getServiceDefinitions()
Exemple #13
0
 def testNormal(self):
     ss = getGlobalServices()
     ss.defineService('one', IOne)
     c = ServiceOne()
     ss.provideService('one', c)
     self.assertEqual(id(getService('one',)), id(c))
Exemple #14
0
    def getServiceDefinitions(self):
        """Retrieve all Service Definitions

        Should return a list of tuples (name, interface)
        """
        return getGlobalServices().getServiceDefinitions()
Exemple #15
0
 def getSiteManager(self):
     return getGlobalServices()
Exemple #16
0
 def testUndefined(self):
     c = ServiceOne()
     self.assertRaises(UndefinedService,
                       getGlobalServices().provideService,
                       'one', c)
Exemple #17
0
 def getSiteManager(self):
     return getGlobalServices()
Exemple #18
0
 def getInterfaceFor(self, name):
     """Retrieve the service interface for the given name
     """
     return getGlobalServices().getInterfaceFor(name)