def setUp(self): super(AuthZopePublicationTests, self).setUp() principalRegistry.defineDefaultPrincipal('anonymous', '') root = self.db.open().root() app = root[ZopePublication.root_name] app['f1'] = rootFolder() f1 = app['f1'] f1['f2'] = Folder() if not ISite.providedBy(f1): f1.setSiteManager(LocalSiteManager(f1)) sm1 = f1.getSiteManager() addUtility(sm1, '', IAuthentication, AuthUtility1()) f2 = f1['f2'] if not ISite.providedBy(f2): f2.setSiteManager(LocalSiteManager(f2)) sm2 = f2.getSiteManager() addUtility(sm2, '', IAuthentication, AuthUtility2()) transaction.commit() from zope.container.interfaces import ISimpleReadContainer from zope.container.traversal import ContainerTraverser component.provideAdapter(ContainerTraverser, (ISimpleReadContainer, IRequest), IPublishTraverse, name='') from zope.site.interfaces import IFolder from zope.security.checker import defineChecker, InterfaceChecker defineChecker(Folder, InterfaceChecker(IFolder))
def setUp(test): from zope.component.testing import setUp setUp() from zope.container.testing import setUp setUp() from zope.component import hooks hooks.setHooks() from zope.traversing.testing import setUp setUp() from zope.publisher.browser import BrowserLanguages from zope.publisher.interfaces.http import IHTTPRequest from zope.i18n.interfaces import IUserPreferredLanguages zope.component.provideAdapter(BrowserLanguages, [IHTTPRequest], IUserPreferredLanguages) from zope.site.folder import rootFolder site = rootFolder() from zope.site.site import LocalSiteManager from zope.component.interfaces import ISite if not ISite.providedBy(site): site.setSiteManager(LocalSiteManager(site)) hooks.setSite(site) test.globs = { 'print_function': print_function, 'root': site, 'pprint': pprint.pprint}
def setUp(self): """Test setUp based on z3c.form.testing.setUp minus their globals. """ from zope.component.testing import setUp setUp() from zope.container.testing import setUp setUp() from zope.component import hooks hooks.setHooks() from zope.traversing.testing import setUp setUp() from zope.publisher.browser import BrowserLanguages from zope.publisher.interfaces.http import IHTTPRequest from zope.i18n.interfaces import IUserPreferredLanguages import zope.component zope.component.provideAdapter(BrowserLanguages, [IHTTPRequest], IUserPreferredLanguages) from zope.site.folder import rootFolder site = rootFolder() from zope.site.site import LocalSiteManager from zope.component.interfaces import ISite if not ISite.providedBy(site): site.setSiteManager(LocalSiteManager(site)) hooks.setSite(site)
def test_restores_site_and_fires_events(self): from zope.component.hooks import site as current_site from zope.component.hooks import setSite from zope.component.hooks import getSite from zope.location.interfaces import LocationError from nti.site.transient import TrivialSite from zope.site.site import LocalSiteManager from zope.traversing.interfaces import BeforeTraverseEvent site1 = TrivialSite(LocalSiteManager(None)) site2 = TrivialSite(LocalSiteManager(None)) site2.installed = 0 def before_traverse(evnt): self.assertIsInstance(evnt, BeforeTraverseEvent) setSite(site2) # Increment to see if this event is fired multiple times. site2.installed += 1 event.subscribers.append(before_traverse) context = TraversablePersistentMapping() context['foo'] = 42 with current_site(site1): t = self._makeOne(context) # Note the trailing slashes; even so we only fire # the event once. result = t.traverse(u'/foo//') self.assertEqual(result, 42) # The site was restored self.assertIs(getSite(), site1) self.assertEqual(site2.installed, 1) site2.installed = 0 # Even when we raise an error it gets restored. with current_site(site1): t = self._makeOne(context) with self.assertRaises(LocationError): t.traverse(u'/bar') self.assertIs(getSite(), site1) self.assertTrue(site2.installed)
def test(self): zope.traversing.testing.setUp() root = Root() f1 = contained(C(), root, name='f1') f2 = contained(SiteManagerContainer(), f1, name='f2') f3 = contained(C(), f2, name='f3') adapter = ILocationInfo(f3) self.assertEqual(adapter.getPath(), '/f1/f2/f3') self.assertEqual(adapter.getName(), 'f3') self.assertEqual(adapter.getRoot(), root) self.assertEqual(adapter.getNearestSite(), root) f2.setSiteManager(LocalSiteManager(f2)) self.assertEqual(adapter.getNearestSite(), f2)
def createSiteManager(folder, setsite=False): if not ISite.providedBy(folder): folder.setSiteManager(LocalSiteManager(folder)) if setsite: setSite(folder) return api.traverse(folder, "++etc++site")