def testUtilityRegistration(self):
        gsm = getGlobalSiteManager()
        global_util = dummy.DummyUtility()

        # Register a global utility and see if we can get it
        gsm.registerUtility(global_util, dummy.IDummyUtility)
        getutil = getUtility(dummy.IDummyUtility)
        self.assertEquals(getutil, global_util)

        # Register a local utility and see if we can get it
        sm = getSiteManager()
        local_util = dummy.DummyUtility()

        sm.registerUtility(local_util, dummy.IDummyUtility)
        getutil = getUtility(dummy.IDummyUtility)
        self.assertEquals(getutil, local_util)
        # Clean up the site again
        clearSite()

        # Without a site we get the global utility
        getutil = getUtility(dummy.IDummyUtility)
        self.assertEquals(getutil, global_util)

        # Clean up again and unregister the utilites
        gsm.unregisterUtility(provided=dummy.IDummyUtility)
        sm.unregisterUtility(provided=dummy.IDummyUtility)

        # Make sure unregistration was successful
        util = queryUtility(dummy.IDummyUtility)
        self.failUnless(util is None)
Exemplo n.º 2
0
    def testUtilityRegistration(self):
        gsm = getGlobalSiteManager()
        global_util = dummy.DummyUtility()

        # Register a global utility and see if we can get it
        gsm.registerUtility(global_util, dummy.IDummyUtility)
        getutil = getUtility(dummy.IDummyUtility)
        self.assertEquals(getutil, global_util)

        # Register a local utility and see if we can get it
        sm = getSiteManager()
        local_util = dummy.DummyUtility()

        sm.registerUtility(local_util, dummy.IDummyUtility)
        getutil = getUtility(dummy.IDummyUtility)
        self.assertEquals(getutil, local_util)
        # Clean up the site again
        clearSite()

        # Without a site we get the global utility
        getutil = getUtility(dummy.IDummyUtility)
        self.assertEquals(getutil, global_util)

        # Clean up again and unregister the utilites
        gsm.unregisterUtility(provided=dummy.IDummyUtility)
        sm.unregisterUtility(provided=dummy.IDummyUtility)

        # Make sure unregistration was successful
        util = queryUtility(dummy.IDummyUtility)
        self.assertTrue(util is None)
    def testSiteManagerSetup(self):
        clearSite()
        # The portal should be an ISite
        self.assertTrue(ISite.providedBy(self.portal))
        # There should be a IComponentRegistry
        comp = IComponentLookup(self.portal)
        IComponentRegistry.providedBy(comp)

        # Test if we get the right site managers
        gsm = getGlobalSiteManager()
        sm = getSiteManager()
        # Without setting the site we should get the global site manager
        self.assertTrue(sm is gsm)

        # Now we set the site, as it is done in url traversal normally
        setSite(self.portal)
        # And should get the local site manager
        sm = getSiteManager()
        self.assertTrue(aq_base(sm) is aq_base(comp))
    def testUtilityRegistration(self):
        gsm = getGlobalSiteManager()
        # Work around five.localsitemanger assuming the global site manager
        # has no bases, which is not true in the test layer.
        old_bases = gsm.__bases__
        gsm.__bases__ = ()

        try:
            global_util = dummy.DummyUtility()

            # Register a global utility and see if we can get it
            gsm.registerUtility(global_util, dummy.IDummyUtility)
            getutil = getUtility(dummy.IDummyUtility)
            self.assertEqual(getutil, global_util)

            # Register a local utility and see if we can get it
            sm = getSiteManager()
            local_util = dummy.DummyUtility()

            sm.registerUtility(local_util, dummy.IDummyUtility)
            getutil = getUtility(dummy.IDummyUtility)
            self.assertEqual(getutil, local_util)
            # Clean up the site again
            clearSite()

            # Without a site we get the global utility
            getutil = getUtility(dummy.IDummyUtility)
            self.assertEqual(getutil, global_util)

            # Clean up again and unregister the utilites
            gsm.unregisterUtility(provided=dummy.IDummyUtility)
            sm.unregisterUtility(provided=dummy.IDummyUtility)

            # Make sure unregistration was successful
            util = queryUtility(dummy.IDummyUtility)
            self.assertTrue(util is None)
        finally:
            gsm.__bases__ = old_bases
Exemplo n.º 5
0
 def tearDown(self):
     clearSite()
     # Make sure our global utility is gone again
     gsm = getGlobalSiteManager()
     gsm.unregisterUtility(provided=IComponentsHandlerBlacklist,
                           name=u'dummy')
Exemplo n.º 6
0
 def tearDown(self):
     clearSite()
     tearDown()
Exemplo n.º 7
0
 def tearDown(self):
     clearSite()
Exemplo n.º 8
0
 def tearDown(self):
     clearSite()
     # Make sure our global utility is gone again
     gsm = getGlobalSiteManager()
     gsm.unregisterUtility(provided=IComponentsHandlerBlacklist,
                           name=u'dummy')