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
def testEnableZope3Site(self): # First we remove the site and site manager self.disableSite(self.portal) clearSite(self.portal) self.portal.setSiteManager(None) gsm = getGlobalSiteManager() # Test it twice for i in range(2): enableZope3Site(self.portal) # And see if we have an ISite with a local site manager self.assertTrue(ISite.providedBy(self.portal)) sm = getSiteManager(self.portal) self.assertFalse(gsm is sm) lc = sm.utilities.LookupClass self.assertEqual(lc, FiveVerifyingAdapterLookup) # Test the lookupclass migration sm.utilities.LookupClass = None # Test it twice for i in range(2): enableZope3Site(self.portal) self.assertEqual(sm.utilities.LookupClass, FiveVerifyingAdapterLookup) self.assertEqual(sm.utilities.__parent__, sm) self.assertEqual(sm.__parent__, self.portal)
def tearDown(self): clearSite() # Make sure our global utility is gone again gsm = getGlobalSiteManager() gsm.unregisterUtility(provided=IComponentsHandlerBlacklist, name=u'dummy')
def tearDown(self): clearSite() cleanUp() TransactionalTest.tearDown(self)