Example #1
0
 def __conform__(self, i):
     if i is IServiceService:
         from zope.component.bbb import getServices
         return getServices()
     from zope.component.interfaces import ISiteManager
     from zope.component import getSiteManager
     if i is ISiteManager:
         return getSiteManager()
Example #2
0
    def test_getServices(self):
        from zope.component import getServices

        # We don't know anything about the default service manager, except
        # that it is an IServiceService.
        self.assert_(IServiceService.providedBy(getServices()))

        # Calling getServices with no args is equivalent to calling it
        # with a context of None.
        self.assert_(getServices().sm is getServices(None).sm)

        # If the context passed to getServices is not None, it is
        # adapted to IServiceService and this adapter returned.
        # So, we create a context that can be adapted to IServiceService
        # using the __conform__ API.
        servicemanager = StubServiceService()
        context = ConformsToIServiceService(servicemanager)
        self.assert_(getServices(context) is servicemanager)

        # Using a context that is not adaptable to IServiceService should
        # fail.
        self.assertRaises(ComponentLookupError, getServices, object())
Example #3
0
    def test_getService(self):
        from zope.component import getService, getServices

        # Getting the adapter service with no context given is the same
        # as getting the adapter service from the no-context service manager.
        self.assert_(getService(Adapters).sm is
                     getServices().getService(Adapters).sm)
        # And, a context of 'None' is the same as not providing a context.
        self.assert_(getService(Adapters, None).sm is getService(Adapters).sm)

        # If the context is adaptable to IServiceService then we use that
        # adapter.
        servicemanager = StubServiceService()
        adapterservice = object()
        servicemanager.setService(Adapters, adapterservice)
        context = ConformsToIServiceService(servicemanager)
        self.assert_(getService(Adapters, context) is adapterservice)

        # Using a context that is not adaptable to IServiceService should
        # fail.
        self.assertRaises(ComponentLookupError,
                          getService, Adapters, object())