def test_getNextUtility(self): # test local site vs. global site global_dummy = DummyUtility() provideUtility(global_dummy, IDummyUtility) local_dummy = DummyUtility() sm = getSiteManager() sm.registerUtility(IDummyUtility, local_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy) # test local site vs. nested local site manage_addDummySite(self.folder.site, 'subsite') import warnings showwarning = warnings.showwarning warnings.showwarning = lambda *a, **k: None enableLocalSiteHook(self.folder.site.subsite) warnings.showwarning = showwarning sublocal_dummy = DummyUtility() sm = getSiteManager() sm.registerUtility(IDummyUtility, sublocal_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), sublocal_dummy) self.assertEquals(getNextUtility(self.folder.site.subsite, IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy)
def test_getNextUtility(self): # test local site vs. global site global_dummy = DummyUtility() provideUtility(global_dummy, IDummyUtility) local_dummy = DummyUtility() sm = zapi.getSiteManager() sm.registerUtility(IDummyUtility, local_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy) # test local site vs. nested local site manage_addDummySite(self.folder.site, 'subsite') enableLocalSiteHook(self.folder.site.subsite) setSite(self.folder.site.subsite) sublocal_dummy = DummyUtility() sm = zapi.getSiteManager() sm.registerUtility(IDummyUtility, sublocal_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), sublocal_dummy) self.assertEquals( getNextUtility(self.folder.site.subsite, IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy)
def test_getNextUtility(self): # test local site vs. global site global_dummy = DummyUtility() provideUtility(global_dummy, IDummyUtility) local_dummy = DummyUtility() sm = getSiteManager() sm.registerUtility(IDummyUtility, local_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy) # test local site vs. nested local site manage_addDummySite(self.folder.site, 'subsite') import warnings showwarning = warnings.showwarning warnings.showwarning = lambda *a, **k: None enableLocalSiteHook(self.folder.site.subsite) warnings.showwarning = showwarning sublocal_dummy = DummyUtility() sm = getSiteManager() sm.registerUtility(IDummyUtility, sublocal_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), sublocal_dummy) self.assertEquals( getNextUtility(self.folder.site.subsite, IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy)
def afterSetUp(self): setUp() zcml.load_config("meta.zcml", Products.Five) zcml.load_config("permissions.zcml", Products.Five) zcml.load_config("configure.zcml", Products.Five.component) zcml.load_config("configure.zcml", Products.Five.site) zcml_text = """\ <five:localsite xmlns:five="http://namespaces.zope.org/five" class="Products.Five.site.tests.dummy.DummySite" />""" import warnings showwarning = warnings.showwarning warnings.showwarning = lambda *a, **k: None zcml.load_string(zcml_text) manage_addDummySite(self.folder, 'site') enableLocalSiteHook(self.folder.site) warnings.showwarning = showwarning # Hook up custom component architecture calls; we need to do # this here because zope.app.component.hooks registers a # cleanup with the testing cleanup framework, so the hooks get # torn down by placelesssetup each time. setHooks()
def makeSite(self): """Convert a possible site to a site""" if self.isSite(): raise ValueError('This is already a site') enableLocalSiteHook(self.context) return "This object is now a site"
def test_nestedSitesDontConflictButStillAcquire(self): # let's register a dummy utility in the dummy site dummy = DummyUtility() sm = zapi.getSiteManager() sm.registerUtility(IDummyUtility, dummy) # let's also create a subsite and make that our site manage_addDummySite(self.folder.site, 'subsite') enableLocalSiteHook(self.folder.site.subsite) setSite(self.folder.site.subsite) # we should still be able to lookup the original utility from # the site one level above self.assertEqual(zapi.getUtility(IDummyUtility), dummy) # now we register a dummy utility in the subsite and see that # its registration doesn't conflict subdummy = DummyUtility() sm = zapi.getSiteManager() sm.registerUtility(IDummyUtility, subdummy) # when we look it up we get the more local one now because the # more local one shadows the less local one self.assertEqual(zapi.getUtility(IDummyUtility), subdummy) # getAllUtilitiesFor gives us both the more local and the less # local utility (XXX not sure if this is the right semantics # for getAllUtilitiesFor) self.assertEqual(sets.Set(zapi.getAllUtilitiesRegisteredFor(IDummyUtility)), sets.Set([subdummy, dummy])) # getUtilitiesFor will only find one, because the more local # one shadows the less local one self.assertEqual(list(zapi.getUtilitiesFor(IDummyUtility)), [('', subdummy)])
def test_getNextUtility(self): # test local site vs. global site global_dummy = DummyUtility() provideUtility(global_dummy, IDummyUtility) local_dummy = DummyUtility() sm = zapi.getSiteManager() sm.registerUtility(IDummyUtility, local_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy) # test local site vs. nested local site manage_addDummySite(self.folder.site, 'subsite') enableLocalSiteHook(self.folder.site.subsite) setSite(self.folder.site.subsite) sublocal_dummy = DummyUtility() sm = zapi.getSiteManager() sm.registerUtility(IDummyUtility, sublocal_dummy) self.assertEquals(zapi.getUtility(IDummyUtility), sublocal_dummy) self.assertEquals(getNextUtility(self.folder.site.subsite, IDummyUtility), local_dummy) self.assertEquals(getNextUtility(self.folder.site, IDummyUtility), global_dummy)
def readme_setup(tc): oc_setup.fresh_skin(tc) if not ISite.providedBy(tc.portal): enableLocalSiteHook(tc.portal) setSite(tc.portal) setHooks() setup_mock_geocoder()
def afterSetUp(self): setUp() zcml.load_config("meta.zcml", Products.Five) zcml.load_config("permissions.zcml", Products.Five) zcml.load_config("configure.zcml", Products.Five.component) zcml.load_config("configure.zcml", Products.Five.site) zcml_text = """\ <five:localsite xmlns:five="http://namespaces.zope.org/five" class="Products.Five.site.tests.dummy.DummySite" />""" import warnings showwarning = warnings.showwarning warnings.showwarning = lambda *a, **k: None zcml.load_string(zcml_text) manage_addDummySite(self.folder, 'site') enableLocalSiteHook(self.folder.site) warnings.showwarning = showwarning # Hook up custom component architecture calls; we need to do # this here because zope.app.component.hooks registers a # cleanup with the testing cleanup framework, so the hooks get # torn down by placelesssetup each time. setHooks()
def initSiteManager(context): """ init portal object as a site manager if not already done """ if context.readDataFile('membrane-init-site-manager.txt') is None: return portal = context.getSite() if not ISite.providedBy(portal): enableLocalSiteHook(portal) logger = context.getLogger("membrane-sitemanager") logger.info("Portal initialized as local site.")
def setupUtilities(site): """ Register a local utility """ if not ISite.providedBy(site): enableLocalSiteHook(site) setSite(site) sm = getSiteManager() if not sm.queryUtility(IContentLicensingUtility): sm.registerUtility(ContentLicensingUtility('contentlicensing'), IContentLicensingUtility)
def setupUtilities(site): """ Register a local utility """ if not ISite.providedBy(site): enableLocalSiteHook(site) setSite(site) sm = getSiteManager() if not sm.queryUtility(IZipFileTransportUtility): sm.registerUtility(ZipFileTransportUtility('zipfiletransport'), IZipFileTransportUtility)
def setupUtilities(site): """ Register a local utility """ if not ISite.providedBy(site): enableLocalSiteHook(site) setSite(site) sm = getSiteManager() if not sm.queryUtility(IZipFileTransportUtility): sm.registerUtility(ZipFileTransportUtility('zipfiletransport'), IZipFileTransportUtility)
def setupUtilities(site): """ Register a local utility """ if not ISite.providedBy(site): enableLocalSiteHook(site) setSite(site) sm = getSiteManager() if not sm.queryUtility(IECUtility): sm.registerUtility(eduCommonsUtility('educommonsutility'), IECUtility)
def setupUtilities(site): """ Register a local utility """ if not ISite.providedBy(site): enableLocalSiteHook(site) setSite(site) sm = getSiteManager() if not sm.queryUtility(IPloneBookmarkletsUtility): sm.registerUtility(PloneBookmarkletsUtility('plonebookmarklets'), IPloneBookmarkletsUtility)
def afterSetUp(self): setUp() zcml.load_config("meta.zcml", Products.Five) zcml.load_config("permissions.zcml", Products.Five) zcml.load_config("configure.zcml", Products.Five.site) zcml_text = """\ <five:localsite xmlns:five="http://namespaces.zope.org/five" class="Products.Five.site.tests.dummy.DummySite" />""" zcml.load_string(zcml_text) manage_addDummySite(self.folder, 'site') enableLocalSiteHook(self.folder.site) setSite(self.folder.site)
def afterSetUp(self): setUp() zcml.load_config("meta.zcml", Products.Five) zcml.load_config("permissions.zcml", Products.Five) zcml.load_config("configure.zcml", Products.Five.site) zcml_text = """\ <five:localsite xmlns:five="http://namespaces.zope.org/five" class="Products.Five.site.tests.dummy.DummySite" />""" zcml.load_string(zcml_text) manage_addDummySite(self.folder, 'site') enableLocalSiteHook(self.folder.site) setSite(self.folder.site)
def ensure_site(context): """Ensure the given context implements ISite. The importance of this method is that it will ensure the given context is an ISite regardless of the Zope version (Zope 2.9 had a really hacked up SiteManager mechanism we have to account for). >>> from zope.location.interfaces import ISite, IPossibleSite >>> from OFS.Folder import Folder >>> if not IPossibleSite.implementedBy(Folder): ... from zope import interface ... from Products.Five.site.metaconfigure import (FiveSite, ... classSiteHook) ... classSiteHook(Folder, FiveSite) ... interface.classImplements(Folder, IPossibleSite) >>> om = Folder('foo') >>> ISite.providedBy(om) False >>> try: ... ensure_site(om) ... except TypeError: ... # not supposed to do anything unless enableLocalSiteHook was found ... if enableLocalSiteHook is None: ... True True """ if not IPossibleSite.providedBy(context): if hasattr(context, 'getPhysicalPath'): p = '/'.join(context.getPhysicalPath()) elif hasattr(context, 'getId'): p = context.getId() elif hasattr(context, 'id'): p = id else: p = str(context) raise TypeError('The object, "%s", is not an IPossibleSite' % p) if not ISite.providedBy(context): if enableLocalSiteHook is not None: enableLocalSiteHook(context) setSite(context) else: raise TypeError('"%s" is not configured as an ISite' % '/'.join(context.getPhysicalPath())) if not ISite.providedBy(context): raise TypeError('Somehow trying to configure "%s" as an ISite ' 'has failed' % '/'.join(context.getPhysicalPath()))
def ensure_site(context): """Ensure the given context implements ISite. The importance of this method is that it will ensure the given context is an ISite regardless of the Zope version (Zope 2.9 had a really hacked up SiteManager mechanism we have to account for). >>> from zope.location.interfaces import ISite, IPossibleSite >>> from OFS.Folder import Folder >>> if not IPossibleSite.implementedBy(Folder): ... from zope import interface ... from Products.Five.site.metaconfigure import (FiveSite, ... classSiteHook) ... classSiteHook(Folder, FiveSite) ... interface.classImplements(Folder, IPossibleSite) >>> om = Folder('foo') >>> ISite.providedBy(om) False >>> try: ... ensure_site(om) ... except TypeError: ... # not supposed to do anything unless enableLocalSiteHook was found ... if enableLocalSiteHook is None: ... True True """ if not IPossibleSite.providedBy(context): if hasattr(context, 'getPhysicalPath'): p = '/'.join(context.getPhysicalPath()) elif hasattr(context, 'getId'): p = context.getId() elif hasattr(context, 'id'): p = id else: p = str(context) raise TypeError('The object, "%s", is not an IPossibleSite' % p) if not ISite.providedBy(context): if enableLocalSiteHook is not None: enableLocalSiteHook(context) setSite(context) else: raise TypeError('"%s" is not configured as an ISite' % '/'.join(context.getPhysicalPath())) if not ISite.providedBy(context): raise TypeError('Somehow trying to configure "%s" as an ISite ' 'has failed' % '/'.join(context.getPhysicalPath()))