def teardown_class(cls):
        plugins.unload('example_idatasetform_v4')
        helpers.reset_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
Example #2
0
    def teardown_class(cls):
        plugins.unload('example_idatasetform')
        helpers.reset_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
    def teardown_class(cls):
        helpers.reset_db()
        model.repo.rebuild_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
Example #4
0
def pytest_runtest_setup(item):
    """Automatically apply `ckan_config` fixture if test has `ckan_config`
    mark.

    `ckan_config` mark itself does nothing(as any mark). All actual
    config changes performed inside `ckan_config` fixture. So let's
    implicitly use `ckan_config` fixture inside any test that patches
    config object. This will save us from adding
    `@mark.usefixtures("ckan_config")` every time.

    """
    # Restore configuration from the snapshot, removing all customization that
    # were done during previous tests.  Note, it is not related to
    # `ckan_config` fixture, which restores config object itself. This is
    # needed because such modules as `ckan.lib.app_globals` can mutate global
    # config object. Potentially can be removed, when the logic behind
    # `app_globals` stops modifying global config object.
    config.clear()
    config.update(_config)

    custom_config = [
        mark.args for mark in item.iter_markers(name=u"ckan_config")
    ]

    if custom_config:
        item.fixturenames.append(u"ckan_config")
Example #5
0
 def teardown(self):
     for env_var, _ in self.ENV_VAR_LIST:
         if os.environ.get(env_var, None):
             del os.environ[env_var]
     config.update(self._old_config)
     # plugin.load() will force the config to update
     p.load()
Example #6
0
 def teardown(self):
     for env_var, _ in self.ENV_VAR_LIST:
         if os.environ.get(env_var, None):
             del os.environ[env_var]
     config.update(self._old_config)
     # plugin.load() will force the config to update
     p.load()
Example #7
0
def test_update_works_on_pylons_config():
    ckan_config.update({
        u"ckan.site_title": u"Example title 2",
        u"ckan.new_key": u"test"
    })
    assert pylons.config[u"ckan.site_title"] == u"Example title 2"
    assert pylons.config[u"ckan.new_key"] == u"test"
Example #8
0
def ckan_config(request, monkeypatch):
    """Allows to override the configuration object used by tests

    Takes into account config patches introduced by the ``ckan_config``
    mark.

    If you just want to set one or more configuration options for the
    scope of a test (or a test class), use the ``ckan_config`` mark::

        @pytest.mark.ckan_config('ckan.auth.create_unowned_dataset', True)
        def test_auth_create_unowned_dataset():

            # ...

    To use the custom config inside a test, apply the
    ``ckan_config`` mark to it and inject the ``ckan_config`` fixture:

    .. literalinclude:: /../ckan/tests/pytest_ckan/test_fixtures.py
       :start-after: # START-CONFIG-OVERRIDE
       :end-before: # END-CONFIG-OVERRIDE

    If the change only needs to be applied locally, use the
    ``monkeypatch`` fixture

    .. literalinclude:: /../ckan/tests/test_common.py
       :start-after: # START-CONFIG-OVERRIDE
       :end-before: # END-CONFIG-OVERRIDE

    """
    _original = copy.deepcopy(config)
    for mark in request.node.iter_markers(u"ckan_config"):
        monkeypatch.setitem(config, *mark.args)
    yield config
    config.clear()
    config.update(_original)
Example #9
0
    def teardown_class(cls):
        helpers.reset_db()
        model.repo.rebuild_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
Example #10
0
 def teardown_class(cls):
     import ckan.plugins as p
     for plugin in reversed(getattr(cls, '_load_plugins', [])):
         p.unload(plugin)
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Example #11
0
 def teardown_class(cls):
     import ckan.plugins as p
     for plugin in reversed(getattr(cls, '_load_plugins', [])):
         p.unload(plugin)
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Example #12
0
 def changed_config(key, value):
     _original_config = config.copy()
     config[key] = value
     try:
         yield
     finally:
         config.clear()
         config.update(_original_config)
Example #13
0
def test_update_works_on_flask_config():
    ckan_config[u"ckan.site_title"] = u"Example title"

    ckan_config.update({
        u"ckan.site_title": u"Example title 2",
        u"ckan.new_key": u"test"
    })
    assert flask.current_app.config[u"ckan.site_title"] == u"Example title 2"
    assert flask.current_app.config[u"ckan.new_key"] == u"test"
Example #14
0
    def test_update_works_on_pylons_config(self):

        ckan_config[u'ckan.site_title'] = u'Example title'

        ckan_config.update({
            u'ckan.site_title': u'Example title 2',
            u'ckan.new_key': u'test'})

        eq_(pylons.config[u'ckan.site_title'], u'Example title 2')
        eq_(pylons.config[u'ckan.new_key'], u'test')
Example #15
0
def load_environment(conf):
    """
    Configure the Pylons environment via the ``pylons.config`` object. This
    code should only need to be run once.
    """
    os.environ['CKAN_CONFIG'] = conf['__file__']

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    valid_base_public_folder_names = ['public']
    static_files = conf.get('ckan.base_public_folder', 'public')
    conf['ckan.base_public_folder'] = static_files

    if static_files not in valid_base_public_folder_names:
        raise CkanConfigurationException(
            'You provided an invalid value for ckan.base_public_folder. '
            'Possible values are: "public".'
        )

    log.info('Loading static files from %s' % static_files)
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, static_files),
                 templates=[])

    # Initialize main CKAN config object
    config.update(conf)

    # Setup the SQLAlchemy database engine
    # Suppress a couple of sqlalchemy warnings
    msgs = ['^Unicode type received non-unicode bind param value',
            "^Did not recognize type 'BIGINT' of column 'size'",
            "^Did not recognize type 'tsvector' of column 'search_vector'"
            ]
    for msg in msgs:
        warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning)

    # load all CKAN plugins
    p.load_all()

    # Check Redis availability
    if not is_redis_available():
        log.critical('Could not connect to Redis.')

    app_globals.reset()

    # issue #3260: remove idle transaction
    # Session that was used for getting all config params nor committed,
    # neither removed and we have idle connection as result
    model.Session.commit()

    # Build JavaScript translations. Must be done after plugins have
    # been loaded.
    build_js_translations()
Example #16
0
        def wrapper(*args, **kwargs):
            _original_config = config.copy()
            config[key] = value

            try:
                return_value = func(*args, **kwargs)
            finally:
                config.clear()
                config.update(_original_config)

            return return_value
Example #17
0
    def test_update_works_on_pylons_config(self):

        ckan_config[u'ckan.site_title'] = u'Example title'

        ckan_config.update({
            u'ckan.site_title': u'Example title 2',
            u'ckan.new_key': u'test'
        })

        eq_(pylons.config[u'ckan.site_title'], u'Example title 2')
        eq_(pylons.config[u'ckan.new_key'], u'test')
Example #18
0
        def wrapper(*args, **kwargs):
            _original_config = config.copy()
            config[key] = value

            try:
                return_value = func(*args, **kwargs)
            finally:
                config.clear()
                config.update(_original_config)

            return return_value
Example #19
0
    def test_update_works_on_flask_config(self):

        app = helpers._get_test_app()
        with app.flask_app.app_context():

            ckan_config[u'ckan.site_title'] = u'Example title'

            ckan_config.update({
                u'ckan.site_title': u'Example title 2',
                u'ckan.new_key': u'test'})

            eq_(flask.current_app.config[u'ckan.site_title'], u'Example title 2')
            eq_(flask.current_app.config[u'ckan.new_key'], u'test')
Example #20
0
    def test_update_works_on_flask_config(self):

        app = helpers._get_test_app()
        with app.flask_app.app_context():

            ckan_config[u'ckan.site_title'] = u'Example title'

            ckan_config.update({
                u'ckan.site_title': u'Example title 2',
                u'ckan.new_key': u'test'
            })

            eq_(flask.current_app.config[u'ckan.site_title'],
                u'Example title 2')
            eq_(flask.current_app.config[u'ckan.new_key'], u'test')
Example #21
0
    def test_js_included(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.view',
                            id=self.package.name, resource_id=self.resource_id,
                            view_id=self.resource_view['id'])
        result = app.get(url)
        assert (('text_view.js' in result.body) or
                ('text_view.min.js' in result.body))
        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Example #22
0
    def test_js_included(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.view',
                            id=self.package.name, resource_id=self.resource_id,
                            view_id=self.resource_view['id'])
        result = app.get(url)
        assert (('text_view.js' in result.body) or  # Source file
                ('textview.js' in result.body))     # Compiled file
        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Example #23
0
    def test_title_description_iframe_shown(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.read',
                            id=self.package.name, resource_id=self.resource_id)
        result = app.get(url)
        assert self.resource_view['title'] in result
        assert self.resource_view['description'] in result
        assert 'data-module="data-viewer"' in result.body

        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Example #24
0
    def test_title_description_iframe_shown(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.read',
                            id=self.package.name, resource_id=self.resource_id)
        result = app.get(url)
        assert self.resource_view['title'] in result
        assert self.resource_view['description'] in result
        assert 'data-module="data-viewer"' in result.body

        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Example #25
0
def load_environment(conf: Union[Config, CKANConfig]):
    """
    Configure the Pylons environment via the ``pylons.config`` object. This
    code should only need to be run once.
    """
    os.environ['CKAN_CONFIG'] = cast(str, conf['__file__'])

    valid_base_public_folder_names = ['public', 'public-bs3']
    static_files = conf.get('ckan.base_public_folder', 'public')
    conf['ckan.base_public_folder'] = static_files

    if static_files not in valid_base_public_folder_names:
        raise CkanConfigurationException(
            'You provided an invalid value for ckan.base_public_folder. '
            'Possible values are: "public" and "public-bs3".')

    log.info('Loading static files from %s' % static_files)

    # Initialize main CKAN config object
    config.update(conf)

    # Setup the SQLAlchemy database engine
    # Suppress a couple of sqlalchemy warnings
    msgs = [
        '^Unicode type received non-unicode bind param value',
        "^Did not recognize type 'BIGINT' of column 'size'",
        "^Did not recognize type 'tsvector' of column 'search_vector'"
    ]
    for msg in msgs:
        warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning)

    # load all CKAN plugins
    p.load_all()

    # Check Redis availability
    if not is_redis_available():
        log.critical('Could not connect to Redis.')

    app_globals.reset()

    # Build JavaScript translations. Must be done after plugins have
    # been loaded.
    build_js_translations()
Example #26
0
def changed_config(key, value):
    '''
    Context manager for temporarily changing a config value.

    Allows you to temporarily change the value of a CKAN configuration
    option. The original value is restored once the context manager is
    left.

    Usage::

        with changed_config(u'ckan.site_title', u'My Test CKAN'):
            assert config[u'ckan.site_title'] == u'My Test CKAN'

    .. seealso:: The decorator :py:func:`change_config`
    '''
    _original_config = config.copy()
    config[key] = value
    try:
        yield
    finally:
        config.clear()
        config.update(_original_config)
Example #27
0
def changed_config(key, value):
    """
    Context manager for temporarily changing a config value.

    Allows you to temporarily change the value of a CKAN configuration
    option. The original value is restored once the context manager is
    left.

    Usage::

        with changed_config(u'ckan.site_title', u'My Test CKAN'):
            assert config[u'ckan.site_title'] == u'My Test CKAN'

    .. seealso:: The decorator :py:func:`change_config`
    """
    _original_config = config.copy()
    config[key] = value
    try:
        yield
    finally:
        config.clear()
        config.update(_original_config)
Example #28
0
 def teardown_class(cls):
     model.repo.rebuild_db()
     config.update(cls.original_config)
     ckan.plugins.unload('string_to_location')
Example #29
0
def load_environment(global_conf, app_conf):
    """
    Configure the Pylons environment via the ``pylons.config`` object. This
    code should only need to be run once.
    """
    # this must be run at a time when the env is semi-setup, thus inlined here.
    # Required by the deliverance plugin and iATI
    from pylons.wsgiapp import PylonsApp
    import pkg_resources
    find_controller_generic = PylonsApp.find_controller

    # This is from pylons 1.0 source, will monkey-patch into 0.9.7
    def find_controller(self, controller):
        if controller in self.controller_classes:
            return self.controller_classes[controller]
        # Check to see if its a dotted name
        if '.' in controller or ':' in controller:
            ep = pkg_resources.EntryPoint.parse('x={0}'.format(controller))

            if hasattr(ep, 'resolve'):
                # setuptools >= 10.2
                mycontroller = ep.resolve()
            else:
                # setuptools >= 11.3
                mycontroller = ep.load(False)

            self.controller_classes[controller] = mycontroller
            return mycontroller
        return find_controller_generic(self, controller)

    PylonsApp.find_controller = find_controller

    os.environ['CKAN_CONFIG'] = global_conf['__file__']

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[])

    # Initialize main CKAN config object
    config.update(global_conf)
    config.update(app_conf)

    # Initialize Pylons own config object
    pylons_config.init_app(global_conf, app_conf, package='ckan', paths=paths)

    # Update the main CKAN config object with the Pylons specific stuff, as it
    # quite hard to keep them separated. This should be removed once Pylons
    # support is dropped
    config.update(pylons_config)

    # Setup the SQLAlchemy database engine
    # Suppress a couple of sqlalchemy warnings
    msgs = [
        '^Unicode type received non-unicode bind param value',
        "^Did not recognize type 'BIGINT' of column 'size'",
        "^Did not recognize type 'tsvector' of column 'search_vector'"
    ]
    for msg in msgs:
        warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning)

    # Check Redis availability
    if not is_redis_available():
        log.critical('Could not connect to Redis.')

    # load all CKAN plugins
    p.load_all()

    app_globals.reset()
Example #30
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)
        PylonsTestCase.teardown_class()

        model.repo.rebuild_db()
 def teardown_class(self):
     config.clear()
     config.update(self._original_config)
     mock_mail_server.SmtpServerHarness.teardown_class()
     pylons_controller.PylonsTestCase.teardown_class()
     model.repo.rebuild_db()
Example #32
0
 def teardown_class(cls):
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Example #33
0
 def teardown_class(self):
     config.clear()
     config.update(self._original_config)
     mock_mail_server.SmtpServerHarness.teardown_class()
     pylons_controller.PylonsTestCase.teardown_class()
     model.repo.rebuild_db()
Example #34
0
def load_environment(global_conf, app_conf):
    """
    Configure the Pylons environment via the ``pylons.config`` object. This
    code should only need to be run once.
    """
    # this must be run at a time when the env is semi-setup, thus inlined here.
    # Required by the deliverance plugin and iATI
    from pylons.wsgiapp import PylonsApp
    import pkg_resources
    find_controller_generic = PylonsApp.find_controller

    # This is from pylons 1.0 source, will monkey-patch into 0.9.7
    def find_controller(self, controller):
        if controller in self.controller_classes:
            return self.controller_classes[controller]
        # Check to see if its a dotted name
        if '.' in controller or ':' in controller:
            ep = pkg_resources.EntryPoint.parse('x={0}'.format(controller))

            if hasattr(ep, 'resolve'):
                # setuptools >= 10.2
                mycontroller = ep.resolve()
            else:
                # setuptools >= 11.3
                mycontroller = ep.load(False)

            self.controller_classes[controller] = mycontroller
            return mycontroller
        return find_controller_generic(self, controller)
    PylonsApp.find_controller = find_controller

    os.environ['CKAN_CONFIG'] = global_conf['__file__']

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    valid_base_public_folder_names = ['public', 'public-bs2']
    static_files = app_conf.get('ckan.base_public_folder', 'public')
    app_conf['ckan.base_public_folder'] = static_files

    if static_files not in valid_base_public_folder_names:
        raise CkanConfigurationException(
            'You provided an invalid value for ckan.base_public_folder. '
            'Possible values are: "public" and "public-bs2".'
        )

    log.info('Loading static files from %s' % static_files)
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, static_files),
                 templates=[])

    # Initialize main CKAN config object
    config.update(global_conf)
    config.update(app_conf)

    # Initialize Pylons own config object
    pylons_config.init_app(global_conf, app_conf, package='ckan', paths=paths)

    # Update the main CKAN config object with the Pylons specific stuff, as it
    # quite hard to keep them separated. This should be removed once Pylons
    # support is dropped
    config.update(pylons_config)

    # Setup the SQLAlchemy database engine
    # Suppress a couple of sqlalchemy warnings
    msgs = ['^Unicode type received non-unicode bind param value',
            "^Did not recognize type 'BIGINT' of column 'size'",
            "^Did not recognize type 'tsvector' of column 'search_vector'"
            ]
    for msg in msgs:
        warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning)

    # load all CKAN plugins
    p.load_all()

    # Check Redis availability
    if not is_redis_available():
        log.critical('Could not connect to Redis.')

    app_globals.reset()

    # issue #3260: remove idle transaction
    # Session that was used for getting all config params nor committed,
    # neither removed and we have idle connection as result
    model.Session.commit()

    # Build JavaScript translations. Must be done after plugins have
    # been loaded.
    build_js_translations()
Example #35
0
 def teardown_class(cls):
     rebuild_all_dbs(cls.Session)
     p.unload('datastore')
     p.unload('datapusher')
     config.clear()
     config.update(cls._original_config)
Example #36
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)
        PylonsTestCase.teardown_class()

        model.repo.rebuild_db()
Example #37
0
 def teardown(self):
     ckan_config.clear()
     ckan_config.update(self._original_config)
Example #38
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)

        model.repo.rebuild_db()
Example #39
0
 def teardown_class(cls):
     config.clear()
     config.update(cls._original_config)
Example #40
0
def load_environment(global_conf, app_conf):
    """
    Configure the Pylons environment via the ``pylons.config`` object. This
    code should only need to be run once.
    """
    # this must be run at a time when the env is semi-setup, thus inlined here.
    # Required by the deliverance plugin and iATI
    from pylons.wsgiapp import PylonsApp
    import pkg_resources
    find_controller_generic = PylonsApp.find_controller

    # This is from pylons 1.0 source, will monkey-patch into 0.9.7
    def find_controller(self, controller):
        if controller in self.controller_classes:
            return self.controller_classes[controller]
        # Check to see if its a dotted name
        if '.' in controller or ':' in controller:
            ep = pkg_resources.EntryPoint.parse('x={0}'.format(controller))

            if hasattr(ep, 'resolve'):
                # setuptools >= 10.2
                mycontroller = ep.resolve()
            else:
                # setuptools >= 11.3
                mycontroller = ep.load(False)

            self.controller_classes[controller] = mycontroller
            return mycontroller
        return find_controller_generic(self, controller)
    PylonsApp.find_controller = find_controller

    os.environ['CKAN_CONFIG'] = global_conf['__file__']

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[])

    # Initialize main CKAN config object
    config.update(global_conf)
    config.update(app_conf)

    # Initialize Pylons own config object
    pylons_config.init_app(global_conf, app_conf, package='ckan', paths=paths)

    # Update the main CKAN config object with the Pylons specific stuff, as it
    # quite hard to keep them separated. This should be removed once Pylons
    # support is dropped
    config.update(pylons_config)

    # Setup the SQLAlchemy database engine
    # Suppress a couple of sqlalchemy warnings
    msgs = ['^Unicode type received non-unicode bind param value',
            "^Did not recognize type 'BIGINT' of column 'size'",
            "^Did not recognize type 'tsvector' of column 'search_vector'"
            ]
    for msg in msgs:
        warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning)

    # load all CKAN plugins
    p.load_all()

    app_globals.reset()
Example #41
0
 def teardown_class(cls):
     # Restore the config to its original values
     config.clear()
     config.update(cls._original_config)
Example #42
0
 def teardown_class(cls):
     config.clear()
     config.update(cls._original_config)
Example #43
0
 def teardown_class(cls):
     # Restore the config to its original values
     config.clear()
     config.update(cls._original_config)
Example #44
0
def load_environment(conf):
    """
    Configure the Pylons environment via the ``pylons.config`` object. This
    code should only need to be run once.
    """
    if six.PY2:
        # this must be run at a time when the env is semi-setup, thus inlined
        # here. Required by the deliverance plugin and iATI
        from pylons.wsgiapp import PylonsApp
        import pkg_resources
        find_controller_generic = getattr(PylonsApp.find_controller,
                                          '_old_find_controller',
                                          PylonsApp.find_controller)

        # This is from pylons 1.0 source, will monkey-patch into 0.9.7
        def find_controller(self, controller):
            if controller in self.controller_classes:
                return self.controller_classes[controller]
            # Check to see if its a dotted name
            if '.' in controller or ':' in controller:
                ep = pkg_resources.EntryPoint.parse('x={0}'.format(controller))

                if hasattr(ep, 'resolve'):
                    # setuptools >= 10.2
                    mycontroller = ep.resolve()
                else:
                    # setuptools >= 11.3
                    mycontroller = ep.load(False)

                self.controller_classes[controller] = mycontroller
                return mycontroller
            return find_controller_generic(self, controller)

        find_controller._old_find_controller = find_controller_generic
        PylonsApp.find_controller = find_controller

    os.environ['CKAN_CONFIG'] = conf['__file__']

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    valid_base_public_folder_names = ['public']
    static_files = conf.get('ckan.base_public_folder', 'public')
    conf['ckan.base_public_folder'] = static_files

    if static_files not in valid_base_public_folder_names:
        raise CkanConfigurationException(
            'You provided an invalid value for ckan.base_public_folder. '
            'Possible values are: "public".')

    log.info('Loading static files from %s' % static_files)
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, static_files),
                 templates=[])

    # Initialize main CKAN config object
    config.update(conf)

    if six.PY2:
        # Initialize Pylons own config object
        pylons_config.init_app(conf['global_conf'],
                               conf,
                               package='ckan',
                               paths=paths)

        # Update the main CKAN config object with the Pylons specific stuff,
        # as it is quite hard to keep them separated. This should be removed
        # once Pylons support is dropped
        config.update(pylons_config)

    # Setup the SQLAlchemy database engine
    # Suppress a couple of sqlalchemy warnings
    msgs = [
        '^Unicode type received non-unicode bind param value',
        "^Did not recognize type 'BIGINT' of column 'size'",
        "^Did not recognize type 'tsvector' of column 'search_vector'"
    ]
    for msg in msgs:
        warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning)

    # load all CKAN plugins
    p.load_all()

    if not p.plugin_loaded('managed_search_schema'):
        search.check_solr_schema_version()

    # Check Redis availability
    if not is_redis_available():
        log.critical('Could not connect to Redis.')

    app_globals.reset()

    # issue #3260: remove idle transaction
    # Session that was used for getting all config params nor committed,
    # neither removed and we have idle connection as result
    model.Session.commit()

    # Build JavaScript translations. Must be done after plugins have
    # been loaded.
    build_js_translations()
Example #45
0
 def teardown_class(cls):
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Example #46
0
 def teardown(self):
     ckan_config.clear()
     ckan_config.update(self._original_config)
Example #47
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)

        model.repo.rebuild_db()