Beispiel #1
0
    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")
Beispiel #2
0
    def setUpDatabase(self):
        """Create a database and stash it in the resource ``zodbDB``. If
        that resource exists, create a layered DemoStorage on top of the
        base database. Otherwise, create a new resource.

        The database is registered in the global configuration so that
        Zope 2 app startup will find it. We use a facade object to ensure
        that the database that is opened by Zope 2 is in fact the top of
        the resource stack.
        """
        if ZOPETESTCASEALERT:
            raise Exception('You try to run plone.testing tests together with '
                            'ZopeTestCase tests. This will result in random '
                            'failures. Convert the ZopeTestCase Tests or '
                            'do not run them together')

        import Zope2.Startup.datatypes
        import App.config

        # Layer a new storage for Zope 2 on top of the one from the base
        # layer, if there is one.

        self['zodbDB'] = zodb.stackDemoStorage(
            self.get('zodbDB'),
            name='Startup')

        # Create a facade for the database object that will delegate to the
        # correct underlying database. This allows resource shadowing to work
        # with regular traversal, which relies on a module-level ``DB``
        # variable.

        class DBFacade(object):

            def __init__(self, layer):
                self.__layer = layer

            @property
            def __db(self):
                return self.__layer['zodbDB']

            def __getattr__(self, name):
                return getattr(self.__db, name)

        # Create a fake dbtab value in the config so that app startup will
        # use this one.

        class DBTab(Zope2.Startup.datatypes.DBTab):
            """A fake DBTab that causes App.startup() to use our own database.
            """

            def __init__(self, db):
                # value is never used when we have an open db
                self.db_factories = {'testing': None}
                self.mount_paths = {'/': 'testing'}
                self.databases = {'testing': db}

        config = App.config.getConfiguration()
        self._dbtab = getattr(config, 'dbtab', None)
        config.dbtab = DBTab(DBFacade(self))
        App.config.setConfiguration(config)
Beispiel #3
0
 def setUp(self):
     self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                                            name=self.__name__)
     name = self.__name__ if self.__name__ is not None else 'not-named'
     contextName = "PloneSandboxLayer-%s" % name
     self['configurationContext'] = configurationContext = (
         zca.stackConfigurationContext(self.get('configurationContext'),
                                       name=contextName))
     # call ploneSite() for all pages in dict.
     plone_site_ids = [PLONE_SITE_ID]
     plone_site_ids.extend(additional_page['page_id']
                           for additional_page in ADDITIONAL_PAGES_TO_SETUP)
     for plone_site_id in plone_site_ids:
         with self.ploneSite(plone_site_id) as portal:
             from zope.site.hooks import setSite, setHooks
             setHooks()
             setSite(None)
             pushGlobalRegistry(portal)
             security.pushCheckers()
             from Products.PluggableAuthService.PluggableAuthService import (
                 MultiPlugins)
             preSetupMultiPlugins = MultiPlugins[:]
             self.setUpZope(portal.getPhysicalRoot(), configurationContext)
             setSite(portal)
             self.setUpPloneSite(portal)
             setSite(None)
         self.snapshotMultiPlugins(preSetupMultiPlugins)
Beispiel #4
0
    def testSetUp(self):
        import Zope2
        import transaction

        # Override zodbDB from the layer setup. Since it was set up by
        # this layer, we can't just assign a new shadow. We therefore keep
        # track of the original so that we can restore it on tear-down.

        self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'), name='FunctionalTest')

        # Save the app

        environ = {
            'SERVER_NAME': self['host'],
            'SERVER_PORT': str(self['port']),
        }

        app = addRequestContainer(Zope2.app(), environ=environ)
        request = app.REQUEST
        request['PARENTS'] = [app]
        
        # Make sure we have a zope.globalrequest request
        try:
            from zope.globalrequest import setRequest
            setRequest(request)
        except ImportError:
            pass
        
        # Start a transaction
        transaction.begin()

        # Save resources for the test
        self['app'] = app
        self['request'] = request
Beispiel #5
0
    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')
Beispiel #6
0
    def testSetUp(self):
        import Zope2
        import transaction

        # Override zodbDB from the layer setup. Since it was set up by
        # this layer, we can't just assign a new shadow. We therefore keep
        # track of the original so that we can restore it on tear-down.

        self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                                               name='FunctionalTest')

        # Save the app

        environ = {
            'SERVER_NAME': self['host'],
            'SERVER_PORT': str(self['port']),
        }

        app = addRequestContainer(Zope2.app(), environ=environ)
        request = app.REQUEST
        request['PARENTS'] = [app]

        # Make sure we have a zope.globalrequest request
        try:
            from zope.globalrequest import setRequest
            setRequest(request)
        except ImportError:
            pass

        # Start a transaction
        transaction.begin()

        # Save resources for the test
        self['app'] = app
        self['request'] = request
Beispiel #7
0
 def setUp(self):
     self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'), 
                                            name='PASLDAPLayer')
     self['app'] = z2.addRequestContainer(Zope2.app(self['zodbDB'].open()), 
                                          environ=None)
     self.setUpZCML()
     self.setUpProducts(self['app'])
     self.setUpDefaultContent(self['app'])
Beispiel #8
0
    def setUp(self):
        zca.pushGlobalRegistry()

        import plone.namedfile
        xmlconfig.file('testing.zcml', plone.namedfile)

        self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                                               name='NamedFileFixture')
Beispiel #9
0
    def testSetUp(self):
        # Setup a transient db
        self['zodbDB'] = zodb.stackDemoStorage(
            self.get('zodbDB'),
            name='FunctionalTest'
        )

        # Start a transaction
        transaction.begin()
Beispiel #10
0
    def setUpDatabase(self):
        """Create a database and stash it in the resource ``zodbDB``. If
        that resource exists, create a layered DemoStorage on top of the
        base database. Otherwise, create a new resource.

        The database is registered in the global configuration so that
        Zope 2 app startup will find it. We use a facade object to ensure
        that the database that is opened by Zope 2 is in fact the top of
        the resource stack.
        """
        if ZOPETESTCASEALERT:
            raise Exception('You try to run plone.testing tests together with '
                            'ZopeTestCase tests. This will result in random '
                            'failures. Convert the ZopeTestCase Tests or '
                            'do not run them together')

        import Zope2.Startup.datatypes
        import App.config

        # Layer a new storage for Zope 2 on top of the one from the base
        # layer, if there is one.

        self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                                               name='Startup')

        # Create a facade for the database object that will delegate to the
        # correct underlying database. This allows resource shadowing to work
        # with regular traversal, which relies on a module-level ``DB``
        # variable.

        class DBFacade(object):
            def __init__(self, layer):
                self.__layer = layer

            @property
            def __db(self):
                return self.__layer['zodbDB']

            def __getattr__(self, name):
                return getattr(self.__db, name)

        # Create a fake dbtab value in the config so that app startup will
        # use this one.

        class DBTab(Zope2.Startup.datatypes.DBTab):
            """A fake DBTab that causes App.startup() to use our own database.
            """
            def __init__(self, db):
                # value is never used when we have an open db
                self.db_factories = {'testing': None}
                self.mount_paths = {'/': 'testing'}
                self.databases = {'testing': db}

        config = App.config.getConfiguration()
        self._dbtab = getattr(config, 'dbtab', None)
        config.dbtab = DBTab(DBFacade(self))
        App.config.setConfiguration(config)
Beispiel #11
0
    def setUp(self):
        zca.pushGlobalRegistry()

        import plone.namedfile
        xmlconfig.file('testing.zcml', plone.namedfile)

        self['zodbDB'] = zodb.stackDemoStorage(
            self.get('zodbDB'),
            name='NamedFileFixture'
        )
Beispiel #12
0
    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)
Beispiel #13
0
    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)
Beispiel #14
0
    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')
Beispiel #15
0
    def setUp(self):
        # Stack the component registry
        self['configurationContext'] = zca.stackConfigurationContext(
            self.get('configurationContext'))

        # Stack the database
        self['zodbDB'] = zodb.stackDemoStorage(
            self.get('zodbDB'), name='SimplelayoutTopicsLayer')

        with ploneSite() as portal:
            applyProfile(portal, 'ftw.topics.tests:example')
Beispiel #16
0
 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'])
Beispiel #17
0
    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)
Beispiel #18
0
    def setUp(self):
        try:
            # Push a new database storage so that database changes
            # commited during layer setup can be easily torn down
            self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                                                   name=self.__name__)

            # Push a new configuration context so that it's possible to
            # re-import ZCML files after tear-down
            name = self.__name__ if self.__name__ is not None else 'not-named'
            contextName = 'PloneSandboxLayer-{0}'.format(name)
            self['configurationContext'] = configurationContext = (
                zca.stackConfigurationContext(self.get('configurationContext'),
                                              name=contextName))

            with ploneSite() as portal:
                setHooks()

                # Make sure there's no local site manager while we load ZCML
                setSite(None)

                # Push a new component registry so that ZCML registations
                # and other global component registry changes are sandboxed
                pushGlobalRegistry(portal)

                # Persist GenericSetup profile upgrade versions for easy
                # rollback.
                persist_profile_upgrade_versions(portal)

                # Make sure zope.security checkers can be set up and torn down
                # reliably

                security.pushCheckers()

                from Products.PluggableAuthService.PluggableAuthService import MultiPlugins  # noqa

                preSetupMultiPlugins = MultiPlugins[:]

                # Allow subclass to load ZCML and products
                self.setUpZope(portal.getPhysicalRoot(), configurationContext)

                # Allow subclass to configure a persistent fixture
                setSite(portal)
                self.setUpPloneSite(portal)
                setSite(None)

            # Keep track of PAS plugins that were added during setup
            self.snapshotMultiPlugins(preSetupMultiPlugins)
        except Exception:
            del self['configurationContext']
            self['zodbDB'].close()
            del self['zodbDB']
            raise
Beispiel #19
0
    def setUp(self):
        try:
            # Push a new database storage so that database changes
            # commited during layer setup can be easily torn down
            self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                    name=self.__name__)

            # Push a new configuration context so that it's possible to re-import
            # ZCML files after tear-down
            name = self.__name__ if self.__name__ is not None else 'not-named'
            contextName = "PloneSandboxLayer-%s" % name
            self['configurationContext'] = configurationContext = (
                zca.stackConfigurationContext(self.get('configurationContext'),
                name=contextName))

            with ploneSite() as portal:

                from zope.site.hooks import setSite, setHooks
                setHooks()

                # Make sure there's no local site manager while we load ZCML
                setSite(None)

                # Push a new component registry so that ZCML registations
                # and other global component registry changes are sandboxed
                pushGlobalRegistry(portal)

                # Make sure zope.security checkers can be set up and torn down
                # reliably

                security.pushCheckers()

                from Products.PluggableAuthService.PluggableAuthService import (
                        MultiPlugins)

                preSetupMultiPlugins = MultiPlugins[:]

                # Allow subclass to load ZCML and products
                self.setUpZope(portal.getPhysicalRoot(), configurationContext)

                # Allow subclass to configure a persistent fixture
                setSite(portal)
                self.setUpPloneSite(portal)
                setSite(None)

            # Keep track of PAS plugins that were added during setup
            self.snapshotMultiPlugins(preSetupMultiPlugins)
        except:
            del self['configurationContext']
            self['zodbDB'].close()
            del self['zodbDB']
            raise
Beispiel #20
0
    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)
Beispiel #21
0
 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,)
Beispiel #22
0
    def setUp(self):
        # Stack the component registry
        self["configurationContext"] = zca.stackConfigurationContext(self.get("configurationContext"))

        # Stack the database
        self["zodbDB"] = zodb.stackDemoStorage(self.get("zodbDB"), name="ftw.book:examplecontent")

        # Register and apply the example content GS profile
        import ftw.book.tests

        xmlconfig.file("examplecontent.zcml", ftw.book.tests, context=self["configurationContext"])

        with ploneSite() as portal:
            request = portal.REQUEST
            mark_layer(None, Dummy(request=request))
            provide_request_layer(request, IWithinBookLayer)
            provide_request_layer(request, IDefaultBookLayoutSelectionLayer)

            applyProfile(portal, "ftw.book.tests:examplecontent")
Beispiel #23
0
    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()
Beispiel #24
0
    def setUp(self):

        # Push a new database storage so that database changes
        # commited during layer setup can be easily torn down
        self['zodbDB'] = zodb.stackDemoStorage(
            self.get('zodbDB'), name=self.__name__
        )

        # Push a new configuration context so that it's possible to re-import
        # ZCML files after tear-down
        if self.__name__ is not None:
            name = self.__name__
        else:
            name = 'not-named'
        contextName = "SilvaSandboxLayer-%s" % name
        self['configurationContext'] = configurationContext = (
            zca.stackConfigurationContext(
                self.get('configurationContext'),
                name=contextName
            )
        )

        for silvaroot in silvaRoot():
            from zope.app.component.hooks import setHooks
            setHooks()

            # Push a new component registry so that ZCML registations
            # and other global component registry changes are sandboxed
            pushGlobalRegistry(silvaroot)

            # Make sure zope.security checkers can be set up and torn down
            # reliably

            security.pushCheckers()

            # Allow subclass to load ZCML and products
            self.setUpZope(silvaroot.getPhysicalRoot(), configurationContext)

            self.setUpSilvaSite(silvaroot)
Beispiel #25
0
    def setUp(self):
        # Stack the component registry
        self['configurationContext'] = zca.stackConfigurationContext(
            self.get('configurationContext'))

        # Stack the database
        self['zodbDB'] = zodb.stackDemoStorage(self.get('zodbDB'),
                                               name='ftw.book:examplecontent')

        # Register and apply the example content GS profile
        import ftw.book.tests
        xmlconfig.file('examplecontent.zcml',
                       ftw.book.tests,
                       context=self['configurationContext'])

        with ploneSite() as portal:
            request = portal.REQUEST
            mark_layer(None, Dummy(request=request))
            provide_request_layer(request, IWithinBookLayer)
            provide_request_layer(request, IDefaultBookLayoutSelectionLayer)

            applyProfile(portal, 'ftw.book.tests:examplecontent')