Esempio n. 1
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.failUnless(util is None)
Esempio n. 2
0
def disableLocalSiteHook(obj):
    """Remove __before_traverse__ hook for Local Site
    """
    # This method is of course deprecated too, but issuing a warning is
    # silly.
    disableSite(obj)
    clearSite()
    obj.setSiteManager(None)
Esempio n. 3
0
    def unmakeSite(self):
        if not self.isSite():
            raise ValueError('This is not a site')

        disableSite(self.context)

        # disableLocalSiteHook circumcised our context so that it's
        # not an ISite anymore.  That can mean that certain things for
        # it can't be found anymore.  So, for the rest of this request
        # (which will be over in about 20 CPU cycles), already clear
        # the local site from the thread local.
        clearSite()

        self.context.setSiteManager(None)
Esempio n. 4
0
    def unmakeSite(self):
        if not self.isSite():
            raise ValueError('This is not a site')

        disableSite(self.context)

        # disableLocalSiteHook circumcised our context so that it's
        # not an ISite anymore.  That can mean that certain things for
        # it can't be found anymore.  So, for the rest of this request
        # (which will be over in about 20 CPU cycles), already clear
        # the local site from the thread local.
        clearSite()

        self.context.setSiteManager(None)
Esempio n. 5
0
    def unmakeSite(self):
        """Convert a site to a possible site"""
        if not self.isSite():
            raise ValueError('This is not a site')

        disableSite(self.context)

        # disableLocalSiteHook circumcised our context so that it's
        # not an ISite anymore.  That can mean that certain things for
        # it can't be found anymore.  So, for the rest of this request
        # (which will be over in about 20 CPU cycles), already clear
        # the local site from the thread local.
        clearSite()

        return "This object is no longer a site"
Esempio n. 6
0
    def unmakeSite(self):
        """Convert a site to a possible site"""
        if not self.isSite():
            raise ValueError('This is not a site')

        disableLocalSiteHook(self.context)

        # disableLocalSiteHook circumcised our context so that it's
        # not an ISite anymore.  That can mean that certain things for
        # it can't be found anymore.  So, for the rest of this request
        # (which will be over in about 20 CPU cycles), already clear
        # the local site from the thread local.
        clearSite()

        return "This object is no longer a site"
Esempio n. 7
0
    def testSiteManagerSetup(self):
        clearSite()
        # The portal should be an ISite
        self.failUnless(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.failUnless(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.failUnless(aq_base(sm) is aq_base(comp))
Esempio n. 8
0
 def tearDown(self):
     clearSite()
Esempio n. 9
0
 def beforeTearDown(self):
     clearSite()
Esempio n. 10
0
 def beforeTearDown(self):
     clearSite()
Esempio n. 11
0
 def tearDown(self):
     clearSite()
     # Make sure our global utility is gone again
     gsm = getGlobalSiteManager()
     gsm.unregisterUtility(provided=IComponentsHandlerBlacklist,
                           name=u'dummy')
Esempio n. 12
0
 def beforeTearDown(self):
     hooks.clearSite()
 def beforeTearDown(self):
     hooks.clearSite()