예제 #1
0
class BumblebeeLayer(PloneSandboxLayer):
    def setUpZope(self, app, configurationContext):
        super(BumblebeeLayer, self).setUpZope(app, configurationContext)

        self.queue = BumblebeeTestTaskQueue()
        sm = getSiteManager()
        sm.registerUtility(self.queue, provided=ITaskQueue, name='test-queue')

    def setUpPloneSite(self, portal):
        activate_bumblebee_feature()

    def testSetUp(self):
        super(BumblebeeLayer, self).testSetUp()
        self.reset_environment_variables()

    def tearDownZope(self, app):
        super(BumblebeeLayer, self).tearDownZope(app)
        self.reset_environment_variables()

    def reset_environment_variables(self):
        os.environ['BUMBLEBEE_APP_ID'] = 'local'
        os.environ['BUMBLEBEE_SECRET'] = 'secret'
        os.environ['BUMBLEBEE_INTERNAL_PLONE_URL'] = 'http://nohost/plone'
        os.environ['BUMBLEBEE_PUBLIC_URL'] = 'http://bumblebee'
        os.environ.pop('BUMBLEBEE_INTERNAL_URL', None)
        os.environ.pop('BUMBLEBEE_DEACTIVATE', None)

    def testTearDown(self):
        self.queue.reset()
        super(BumblebeeLayer, self).testTearDown()

    defaultBases = (OPENGEVER_FUNCTIONAL_TESTING, )
예제 #2
0
class BumblebeeLayer(PloneSandboxLayer):

    def setUpZope(self, app, configurationContext):
        super(BumblebeeLayer, self).setUpZope(app, configurationContext)

        self.queue = BumblebeeTestTaskQueue()
        sm = getSiteManager()
        sm.registerUtility(self.queue, provided=ITaskQueue, name='test-queue')

    def setUpPloneSite(self, portal):
        activate_bumblebee_feature()

    def tearDownPloneSite(self, portal):
        deactivate_bumblebee_feature()

    def testSetUp(self):
        super(BumblebeeLayer, self).testSetUp()
        self.reset_environment_variables()

    def tearDownZope(self, app):
        super(BumblebeeLayer, self).tearDownZope(app)
        self.reset_environment_variables()

    def reset_environment_variables(self):
        os.environ['BUMBLEBEE_APP_ID'] = 'local'
        os.environ['BUMBLEBEE_SECRET'] = 'secret'
        os.environ['BUMBLEBEE_INTERNAL_PLONE_URL'] = 'http://nohost/plone'
        os.environ['BUMBLEBEE_PUBLIC_URL'] = 'http://bumblebee'
        os.environ.pop('BUMBLEBEE_INTERNAL_URL', None)
        os.environ.pop('BUMBLEBEE_DEACTIVATE', None)

    def testTearDown(self):
        self.queue.reset()
        super(BumblebeeLayer, self).testTearDown()

    defaultBases = (OPENGEVER_FUNCTIONAL_TESTING,)
예제 #3
0
class ContentFixtureLayer(OpengeverFixture):
    """The content fixture layer extends the regular OpengeverFixture with a
    content fixture.
    The content fixture is a set of objects which are constructed on layer setup
    time and can be used by all tests, saving us the per-test creation time.

    SQL:
    This fixture does only work with sqlite at the moment. It cannot base on the
    SQLITE_MEMORY_FIXTURE because this will break savepoint support because the
    engine would be created before the ZCML is loaded, registering engine
    creation event handlers.

    Builder session:
    ftw.builder provides testing layers and functions for using builders within
    tests.
    It does not provide infrastructure for setting up builders in layer setup.
    Therefore we cannot reuse ftw.builder's testing layers but configure the
    builder manually in a non-committing integration testing mode.

    Warning:
    Do not create another fixture layer based on this fixture layer.
    It won't work without fixing transactionality issues.
    The current setup works because the fixture state is committed to the database.
    Committed state cannot be rolled back.
    Uncommitted state will get lost when IntegrationTesting.testSetUp begins
    a new transaction.
    """

    defaultBases = (CACHED_COMPONENT_REGISTRY_ISOLATION, )

    def __init__(self):
        # By super-super-calling the __init__ we remove the SQL bases,
        # since we are implementing SQL setup in this layer directly.
        PloneSandboxLayer.__init__(self)

    def setUpZope(self, app, configurationContext):
        super(ContentFixtureLayer, self).setUpZope(app, configurationContext)
        # Setting up the database, which creates a new engine, must happen after
        # opengever's ZCML is loaded in order to have engine creation event
        # handlers already registered, which enable support for rolling back
        # to savepoints.
        sqlite_testing.setup_memory_database()
        if 'sqlite' in datamanager.NO_SAVEPOINT_SUPPORT:
            datamanager.NO_SAVEPOINT_SUPPORT.remove('sqlite')

        # register bumblebee task queue
        self.bumblebee_queue = BumblebeeTestTaskQueue()
        sm = getSiteManager()
        sm.registerUtility(self.bumblebee_queue,
                           provided=ITaskQueue,
                           name='test-queue')

        # provide bumblebee config by default and only deactivate bumblebee
        # with the feature flag.
        os.environ.pop('BUMBLEBEE_DEACTIVATE', None)
        os.environ['BUMBLEBEE_APP_ID'] = 'local'
        os.environ['BUMBLEBEE_SECRET'] = 'secret'
        os.environ['BUMBLEBEE_INTERNAL_PLONE_URL'] = 'http://nohost/plone'
        os.environ['BUMBLEBEE_PUBLIC_URL'] = 'http://bumblebee'

    def setUpPloneSite(self, portal):
        session.current_session = session.BuilderSession()
        session.current_session.session = create_session()
        super(ContentFixtureLayer, self).setUpPloneSite(portal)

        portal.portal_languages.use_combined_language_codes = True
        portal.portal_languages.addSupportedLanguage('de-ch')

        if not DB_CACHE_MANAGER.is_loaded_from_cache(CACHE_GEVER_FIXTURE):
            sqlite_testing.create_tables()
            # Avoid circular imports:
            from opengever.testing.fixtures import OpengeverContentFixture
            setRequest(portal.REQUEST)
            self['fixture_lookup_table'] = OpengeverContentFixture()()
            setRequest(None)
            DB_CACHE_MANAGER.data['fixture_lookup_table'] = (
                self['fixture_lookup_table'])
            DB_CACHE_MANAGER.dump_to_cache(self['zodbDB'], CACHE_GEVER_FIXTURE)
        else:
            DB_CACHE_MANAGER.apply_cache_fixes(CACHE_GEVER_FIXTURE)
            self['fixture_lookup_table'] = (
                DB_CACHE_MANAGER.data['fixture_lookup_table'])

        # bumblebee should only be turned on on-demand with the feature flag.
        # if this assertion fails a profile in the fixture enables bumblebee,
        # or if was left on by mistake after fixture setup.
        assert not is_bumblebee_feature_enabled()

    def installOpengeverProfiles(self, portal):
        if not DB_CACHE_MANAGER.is_loaded_from_cache(CACHE_GEVER_INSTALLATION):
            super(ContentFixtureLayer, self).installOpengeverProfiles(portal)
            DB_CACHE_MANAGER.dump_to_cache(self['zodbDB'],
                                           CACHE_GEVER_INSTALLATION)
        else:
            DB_CACHE_MANAGER.apply_cache_fixes(CACHE_GEVER_INSTALLATION)

    def testTearDown(self):
        super(ContentFixtureLayer, self).testTearDown()

        # clear bumblebee queue after each test
        self.bumblebee_queue.reset()

    def tearDown(self):
        sqlite_testing.model.Session.close_all()
        sqlite_testing.truncate_tables()
        super(ContentFixtureLayer, self).tearDown()
        session.current_session = None

    def allowAllTypes(self, portal):
        """In the fixture layer, the fixture objects should be used and
        we want them to be at the correct place hierarchically.
        When additional objects need to be created anyway, they can be placed
        in the correct spot easily by using the fixture objects as parents.
        Therefore we do not allow to create objects at the portal.
        """
        pass