def silvaRoot(db=None, connection=None, environ=None): """Context manager for working with the Silva root during layer setup:: with silvaRoot() as silvaroot: ... This is based on the ``z2.zopeApp()`` context manager. See the module ``plone.testing.z2`` for details. Do not use this in a test. Use the 'silvaroot' resource from the SilvaFixture layer instead! Pass a ZODB handle as ``db`` to use a specificdatabase. Alternatively, pass an open connection as ``connection`` (the connection will not be closed). """ from zope.app.component.hooks import setHooks setHooks() for app in z2.zopeApp(db, connection, environ): silvaroot = app[SILVA_SITE_ID] login(silvaroot, SITE_OWNER_NAME) try: yield silvaroot # the finally is replaced by the pair except else # 2.4 does not accept yield in a try...finally except: logout() else: logout()
def CMFDefaultPortal(db=None, connection=None, environ=None): """Context manager for working with the Plone portal during layer setup:: with CMFDefaultPortal() as portal: ... This is based on the ``z2.zopeApp()`` context manager. See the module ``plone.testing.z2`` for details. Do not use this in a test. Use the 'portal' resource from the PloneFixture layer instead! Pass a ZODB handle as ``db`` to use a specificdatabase. Alternatively, pass an open connection as ``connection`` (the connection will not be closed). """ from zope.site.hooks import setSite, getSite, setHooks setHooks() site = getSite() with z2.zopeApp(db, connection, environ) as app: portal = app[SITE_ID] setSite(portal) z2.login(portal['acl_users'], TEST_USER_ID) try: yield portal finally: z2.logout() if site is not portal: setSite(site)
def tearDown(self): for app in z2.zopeApp(): silvaroot = app[SILVA_SITE_ID] from zope.app.component.hooks import setHooks setHooks() # Allow subclass to tear down persistent fixture self.tearDownSilvaSite(silvaroot) # Make sure zope.security checkers can be set up and torn down # reliably security.popCheckers() # Pop the component registry, thus removing component # architecture registrations popGlobalRegistry(silvaroot) # Allow subclass to tear down products self.tearDownZope(app) # Zap the configuration context del self['configurationContext'] # Pop the demo storage, thus restoring the database to the # previous state self['zodbDB'].close() del self['zodbDB']
def ploneSite(db=None, connection=None, environ=None): """Context manager for working with the Plone portal during layer setup:: with ploneSite() as portal: ... This is based on the ``z2.zopeApp()`` context manager. See the module ``plone.testing.z2`` for details. Do not use this in a test. Use the 'portal' resource from the PloneFixture layer instead! Pass a ZODB handle as ``db`` to use a specificdatabase. Alternatively, pass an open connection as ``connection`` (the connection will not be closed). """ from zope.site.hooks import setSite, getSite, setHooks setHooks() site = getSite() with z2.zopeApp(db, connection, environ) as app: portal = app[PLONE_SITE_ID] setSite(portal) login(portal, TEST_USER_NAME) try: yield portal finally: logout() if site is not portal: setSite(site)
def tearDown(self): with z2.zopeApp() as app: portal = app[PLONE_SITE_ID] setHooks() setSite(portal) # Allow subclass to tear down persistent fixture self.tearDownPloneSite(portal) setSite(None) # Make sure zope.security checkers can be set up and torn down # reliably security.popCheckers() # Pop the component registry, thus removing component # architecture registrations popGlobalRegistry(portal) # Remove PAS plugins self.tearDownMultiPlugins() # Allow subclass to tear down products self.tearDownZope(app) # Zap the configuration context del self['configurationContext'] # Pop the demo storage, thus restoring the database to the # previous state self['zodbDB'].close() del self['zodbDB']
def setUpContent(self): import plone.app.linkintegrity xmlconfig.file("configure.zcml", plone.app.linkintegrity, context=self["configurationContext"]) with z2.zopeApp() as app: z2.installProduct(app, "plone.app.linkintegrity") with ploneSite() as portal: setRoles(portal, TEST_USER_ID, ["Manager"]) login(portal, TEST_USER_NAME) # Create sample documents type_data = dict(type_name="Document") for i in range(1, 4): type_data["id"] = "doc{0:d}".format(i) type_data["title"] = "Test Page {0:d}".format(i) create(portal, **type_data) create(portal, "File", id="file1", title="File 1", file=GIF) create(portal, "Image", id="image1", title="Image 1", image=GIF) create(portal, "Folder", id="folder1", title="Folder 1") subfolder = portal["folder1"] create(subfolder, "Document", id="doc4", title="Test Page 4") self.setUpMembers(portal)
def setUpContent(self): import plone.app.linkintegrity xmlconfig.file('configure.zcml', plone.app.linkintegrity, context=self['configurationContext']) with z2.zopeApp() as app: z2.installProduct(app, 'plone.app.linkintegrity') with ploneSite() as portal: setRoles(portal, TEST_USER_ID, ['Manager', ]) login(portal, TEST_USER_NAME) # Create sample documents type_data = dict(type_name='Document') for i in range(1, 4): type_data['id'] = 'doc{0:d}'.format(i) type_data['title'] = 'Test Page {0:d}'.format(i) create(portal, **type_data) create(portal, 'File', id='file1', title='File 1', file=GIF) create(portal, 'Image', id='image1', title='Image 1', image=GIF) create(portal, 'Folder', id='folder1', title='Folder 1') subfolder = portal['folder1'] create(subfolder, 'Document', id='doc4', title='Test Page 4') self.setUpMembers(portal)
def setUpContent(self): import plone.app.linkintegrity xmlconfig.file('configure.zcml', plone.app.linkintegrity, context=self['configurationContext']) with z2.zopeApp() as app: z2.installProduct(app, 'plone.app.linkintegrity') with ploneSite() as portal: setRoles(portal, TEST_USER_ID, [ 'Manager', ]) login(portal, TEST_USER_NAME) # Create sample documents type_data = dict(type_name='Document') for i in range(1, 4): type_data['id'] = 'doc{0:d}'.format(i) type_data['title'] = 'Test Page {0:d}'.format(i) create(portal, **type_data) create(portal, 'File', id='file1', title='File 1', file=GIF) create(portal, 'Image', id='image1', title='Image 1', image=GIF) create(portal, 'Folder', id='folder1', title='Folder 1') subfolder = portal['folder1'] create(subfolder, 'Document', id='doc4', title='Test Page 4') self.setUpMembers(portal)
def setUp(self): # Stack a new DemoStorage on top of the one from z2.STARTUP. self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'), name='PloneSubRequestFixture') # Create a new global registry zca.pushGlobalRegistry() self['configurationContext'] = context = zca.stackConfigurationContext( self.get('configurationContext')) # Load out ZCML from zope.configuration import xmlconfig import plone.subrequest xmlconfig.file('testing.zcml', plone.subrequest, context=context) with z2.zopeApp() as app: # Enable virtual hosting z2.installProduct(app, 'Products.SiteAccess') from Products.SiteAccess.VirtualHostMonster import \ VirtualHostMonster vhm = VirtualHostMonster() app._setObject(vhm.getId(), vhm, suppress_events=True) # With suppress_events=False, this is called twice... vhm.manage_afterAdd(vhm, app) # Setup default content app.manage_addFolder('folder1') make_site(app.folder1) app.folder1.manage_addFolder('folder1A') app.folder1.folder1A.manage_addFolder('folder1Ai') app.folder1.manage_addFolder('folder1B') app.manage_addFolder('folder2') make_site(app.folder2) app.folder2.manage_addFolder('folder2A') app.folder2.folder2A.manage_addFolder('folder2Ai space')
def setUp(self): # Stack a new DemoStorage on top of the one from z2.STARTUP. self["zodbDB"] = zodb.stackDemoStorage(self.get("zodbDB"), name="PloneSubRequestFixture") # Create a new global registry zca.pushGlobalRegistry() self["configurationContext"] = context = zca.stackConfigurationContext(self.get("configurationContext")) # Load out ZCML from zope.configuration import xmlconfig import plone.subrequest xmlconfig.file("testing.zcml", plone.subrequest, context=context) with z2.zopeApp() as app: # Enable virtual hosting z2.installProduct(app, "Products.SiteAccess") from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster vhm = VirtualHostMonster() app._setObject(vhm.getId(), vhm, suppress_events=True) # With suppress_events=False, this is called twice... vhm.manage_afterAdd(vhm, app) # Setup default content app.manage_addFolder("folder1") make_site(app.folder1) app.folder1.manage_addFolder("folder1A") app.folder1.folder1A.manage_addFolder("folder1Ai") app.folder1.manage_addFolder("folder1B") app.manage_addFolder("folder2") make_site(app.folder2) app.folder2.manage_addFolder("folder2A") app.folder2.folder2A.manage_addFolder("folder2Ai space")
def setUpZope(self, app, configurationContext): # Load ZCML import Products.CMFContentPanels xmlconfig.file('configure.zcml', Products.CMFContentPanels, context=configurationContext) with z2.zopeApp() as app: z2.installProduct(app, 'Products.CMFContentPanels')
def setUp(self): with zopeApp() as app: self.app = app self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader('Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD))
def tearDown(self): with z2.zopeApp() as app: portal = app[PLONE_SITE_ID] _o_mailhost = getattr(portal, "_original_MailHost", None) if _o_mailhost: portal.MailHost = portal._original_MailHost sm = getSiteManager(context=portal) sm.unregisterUtility(provided=IMailHost) sm.registerUtility(aq_base(portal._original_MailHost), provided=IMailHost)
def testTearDown(self): with z2.zopeApp() as app: # Clean up sessions after each test app.session_data_manager._p_jar.sync() app.session_data_manager._getSessionDataContainer()._reset() # Commit transaction from transaction import commit commit()
def setUpDefaultContent(self, app): # do not create plone site with z2.zopeApp() as app: app['acl_users'].userFolderAddUser( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, ['Manager'], [] )
def setUp(self): with z2.zopeApp() as app: z2.installProduct(app, 'Products.PluggableAuthService') z2.installProduct(app, 'Products.NoDuplicateLogin') z2.installProduct(app, 'Products.PythonScripts') app.manage_addProduct['PythonScripts'].manage_addPythonScript("whoami") whoami = app.whoami whoami.write(WHOAMI_SCRIPT)
def setUpZope(self, app, configuration_context): """Set up Zope for testing""" xmlconfig.file( 'configure.zcml', Products.PloneBooking, context=configuration_context ) with z2.zopeApp() as app: z2.installProduct(app, 'Products.PloneBooking')
def setUpZope(self, app, configurationContext): from plone.testing import z2 with z2.zopeApp() as app: z2.installProduct(app, "Products.CAS4PAS") # Load ZCML import collective.castle self.loadZCML(package=collective.castle, context=configurationContext)
def setUpDefaultContent(self, app): # Do not install plone site in this base layer, # so that we can reuse it an setup multiple sites # with different languages in sequence. with z2.zopeApp() as app: app['acl_users'].userFolderAddUser( SITE_OWNER_NAME, SITE_OWNER_PASSWORD, ['Manager'], [])
def setUp(self): self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'), name='PloneFixture') self.setUpZCML() with z2.zopeApp() as app: self.setUpProducts(app) self.setUpDefaultContent(app) for ADDITIONAL_PAGE in ADDITIONAL_PAGES_TO_SETUP: self.setUpDefaultContent_AdditionalPage( app, ADDITIONAL_PAGE['page_id'], ADDITIONAL_PAGE['page_title'])
def setUp(self): # Stack a new DemoStorage on top of the one from z2.STARTUP. self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'), name='PloneFixture') self.setUpZCML() # Set up products and the default content with z2.zopeApp() as app: self.setUpProducts(app) self.setUpDefaultContent(app)
def setUp(self): # Stack a new DemoStorage on top of the one from z2.STARTUP. self["zodbDB"] = zodb.stackDemoStorage(self.get("zodbDB"), name="PloneFixture") self.setUpZCML() # Set up products and the default content with z2.zopeApp() as app: self.setUpProducts(app) self.setUpDefaultContent(app)
def setUp(self): # Stack a new DemoStorage self['zodbDB'] = zodb.stackDemoStorage( self.get('zodbDB'), name='SimplelayoutTopicsLayer') with z2.zopeApp() as app: z2.installProduct(app, 'simplelayout.types.common') z2.installProduct(app, 'ftw.contentpage') with ploneSite() as portal: applyProfile(portal, 'ftw.topics:simplelayout')
def setUp(self): with z2.zopeApp() as app: portal = app[PLONE_SITE_ID] portal.email_from_address = '*****@*****.**' portal.email_from_name = 'Plone Site' portal._original_MailHost = portal.MailHost portal.MailHost = mailhost = MockMailHost('MailHost') portal.MailHost.smtp_host = 'localhost' sm = getSiteManager(context=portal) sm.unregisterUtility(provided=IMailHost) sm.registerUtility(mailhost, provided=IMailHost)
def tearDown(self): # Tear down products with z2.zopeApp() as app: # note: content tear-down happens by squashing the ZODB self.tearDownProducts(app) self.tearDownZCML() # Zap the stacked ZODB self['zodbDB'].close() del self['zodbDB']
def setUp(self): # Stack a new DemoStorage on top of the one from z2.STARTUP. self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'), name='CMFPortalFixture') self.setUpZCML() # Set up products and the default content with z2.zopeApp() as app: self.setUpProducts(app) self.setUpDefaultContent(app)
def setUpPloneSite(self, portal): applyProfile(portal, 'jarn.xmpp.collaboration:default') registry = getUtility(IRegistry) registry['jarn.xmpp.collaborationJID'] = 'collaboration.localhost' if HAS_DEXTERITY: self.applyProfile(portal, 'plone.app.dexterity:default') # Surely there are better ways of doing this than TTW, feel free to # replace. import transaction from plone.testing.z2 import Browser from plone.app.testing import TEST_USER_ID, TEST_USER_PASSWORD from plone.app.testing import setRoles from plone.testing import z2 setRoles(portal, TEST_USER_ID, ['Manager']) transaction.commit() with z2.zopeApp() as app: browser = Browser(app) browser.handleErrors = False browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_ID, TEST_USER_PASSWORD, )) # Create a type browser.open('http://nohost/plone/@@dexterity-types') browser.getControl('Add New Content Type').click() browser.getControl('Type Name').value = 'MyType' browser.getControl('Short Name').value = 'mytype' browser.getControl('Add').click() #Add fields browser.getLink('MyType').click() fields = [('textline', 'Text line (String)'), ('text', 'Text'), ('richtext', 'Rich Text')] for field_id, field_type in fields: browser.getControl('Add new field').click() browser.getControl('Title').value = field_id browser.getControl('Short Name').value = field_id browser.getControl('Field type').getControl( value=field_type).selected = True browser.getControl('Add').click() # Setup behaviors portal.portal_types.mytype.behaviors = ( 'plone.app.dexterity.behaviors.metadata.IDublinCore', 'plone.app.content.interfaces.INameFromTitle', 'jarn.xmpp.collaboration.interfaces.ICollaborativelyEditable') setRoles(portal, TEST_USER_ID, ['Member'])
def ploneSite(self, plone_site_id, db=None, connection=None, environ=None): from zope.site.hooks import setSite, getSite, setHooks setHooks() site = getSite() with z2.zopeApp(db, connection, environ) as app: portal = app[plone_site_id] setSite(portal) login(portal, TEST_USER_NAME) try: yield portal finally: logout() if site is not portal: setSite(site)
def setUp(self): zca.pushGlobalRegistry() self.configurationContext = zca.stackConfigurationContext() import ftw.inflator xmlconfig.file('meta.zcml', ftw.inflator, context=self.configurationContext) with zopeApp() as app: self.app = app self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader('Authorization', 'Basic %s:%s' % ( SITE_OWNER_NAME, SITE_OWNER_PASSWORD))
def test_customize_image(self): self.load_zcml_string('\n'.join(( '<configure xmlns:inflator="http://namespaces.zope.org/inflator"' ' i18n_domain="my.package"' ' package="ftw.inflator.tests">', ' <inflator:customize', ' image="../resources/plone-logo.png" />', '</configure>' ))) image = get_merged_customizations().image self.assertEquals(image, '++resource++inflator-plone-logo-10.png') with z2.zopeApp() as app: self.assertTrue(app.unrestrictedTraverse(image))
def tearDown(self): # Tear down products for app in z2.zopeApp(): # note: content tear-down happens by squashing the ZODB self.tearDownProducts(app) from zope.app.component.hooks import resetHooks resetHooks() self.tearDownZCML() # Zap the stacked ZODB self['zodbDB'].close() del self['zodbDB']
def test_setuphandler(self): default_profile_path = os.path.join( os.path.dirname(ftw.bridge.client.__file__), 'profiles', 'default') with z2.zopeApp() as app: acl_users = app.acl_users self.assertFalse(setuphandlers.PLUGIN_ID in acl_users.objectIds()) setup = DirectoryImportContext(app.acl_users, default_profile_path) setuphandlers.setup_bridge_pas_plugin(setup) self.assertTrue(setuphandlers.PLUGIN_ID in acl_users.objectIds()) # Does not fail on another call setuphandlers.setup_bridge_pas_plugin(setup)
def setUp(self): # Stack a new DemoStorage on top of the one from z2.STARTUP. self['zodbDB'] = zodb.stackDemoStorage( self.get('zodbDB'), name='SilvaFixture' ) self.setUpZCML() from zope.app.component.hooks import setHooks setHooks() # Set up products and the default content for app in z2.zopeApp(): self.setUpProducts(app) self.setUpDefaultContent(app)
def setUp(self): self['zodbDB'] = zodb.stackDemoStorage( self.get('zodbDB'), name='CMFAppLayer', ) with z2.zopeApp() as app: self.setUpTestUserContext(app) for pkg in self.PRODUCTS: z2.installProduct(app, pkg) self.setUpSite(app) transaction.commit() global_components = zca.pushGlobalRegistry() site = self.get('site') local_components = site.getSiteManager() if global_components not in local_components.__bases__: local_components.__bases__ = (global_components,)
def setUp(self): zca.pushGlobalRegistry() self.configurationContext = zca.stackConfigurationContext() import ftw.inflator xmlconfig.file('meta.zcml', ftw.inflator, context=self.configurationContext) with zopeApp() as app: self.app = app self.browser = Browser(app) self.browser.handleErrors = False self.browser.addHeader( 'Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD))
def test_setuphandler(self): default_profile_path = os.path.join( os.path.dirname(ftw.bridge.client.__file__), 'profiles', 'default') with z2.zopeApp() as app: acl_users = app.acl_users self.assertFalse( setuphandlers.PLUGIN_ID in acl_users.objectIds()) setup = DirectoryImportContext(app.acl_users, default_profile_path) setuphandlers.setup_bridge_pas_plugin(setup) self.assertTrue(setuphandlers.PLUGIN_ID in acl_users.objectIds()) # Does not fail on another call setuphandlers.setup_bridge_pas_plugin(setup)
def setUpZope(self, app, configurationContext): """load package zcml to initialize product""" import z3c.form self.loadZCML(name='meta.zcml', package=z3c.form) self.loadZCML(package=z3c.form) # needed for testing product views import plone.uuid self.loadZCML(package=plone.uuid) import collective.z3cform.datagridfield self.loadZCML(package=collective.z3cform.datagridfield) import Products.CMFPlacefulWorkflow self.loadZCML(package=Products.CMFPlacefulWorkflow) import plone.app.iterate self.loadZCML(package=plone.app.iterate) with z2.zopeApp() as app: z2.installProduct(app, 'Products.DateRecurringIndex') import uu.workflows self.loadZCML(package=uu.workflows) import collective.teamwork self.loadZCML(package=collective.teamwork) import upiqsite.teamwork self.loadZCML(package=upiqsite.teamwork)
def setUp(self): # Stack a new DemoStorage self['zodbDB'] = zodb.stackDemoStorage( self.get('zodbDB'), name='BundleLayer:%s' % self.language) with z2.zopeApp() as app: z2.login(app['acl_users'], SITE_OWNER_NAME) # instll a plone site with the bundle bundle = get_bundle_by_name('OneGov Box (Example content)') bundle.install(app, PLONE_SITE_ID, language=self.language) # create the plone test user pas = app[PLONE_SITE_ID]['acl_users'] pas.source_users.addUser( TEST_USER_ID, TEST_USER_NAME, TEST_USER_PASSWORD) for role in TEST_USER_ROLES: pas.portal_role_manager.doAssignRoleToPrincipal(TEST_USER_ID, role) z2.logout()
def tearDown(self): with z2.zopeApp() as app: portal = app[PLONE_SITE_ID] from zope.site.hooks import setSite, setHooks setHooks() setSite(portal) # Allow subclass to tear down persistent fixture self.tearDownPloneSite(portal) setSite(None) # Make sure zope.security checkers can be set up and torn down # reliably security.popCheckers() # Pop the component registry, thus removing component # architecture registrations popGlobalRegistry(portal) # Remove PAS plugins self.tearDownMultiPlugins() # Allow subclass to tear down products self.tearDownZope(app) # Zap the configuration context del self['configurationContext'] # Pop the demo storage, thus restoring the database to the # previous state self['zodbDB'].close() del self['zodbDB']
def setUp(self): with z2.zopeApp() as app: ZopeTestCase.utils.setupCoreSessions(app)
def setUp(self): with z2.zopeApp() as app: z2.installProduct(app, 'Products.PTProfiler')
def setUp(self): with z2.zopeApp() as app: z2.installProduct(app, 'Products.DateRecurringIndex')
def setUpDefaultContent(self, app): # do not create plone site with z2.zopeApp() as app: app['acl_users'].userFolderAddUser(SITE_OWNER_NAME, SITE_OWNER_PASSWORD, ['Manager'], [])
def tearDown(self): with z2.zopeApp() as app: z2.installProduct(app, 'Products.PTProfiler')
def tearDown(self): with z2.zopeApp() as app: z2.uninstallProduct(app, 'plone.app.linkintegrity')
def tearDown(self): with z2.zopeApp() as app: z2.uninstallProduct(app, 'Products.DateRecurringIndex')