Ejemplo n.º 1
0
def test_invalid_use_option():
    """Report missing colon in `use` value
    """
    filename = os.path.join(os.path.dirname(__file__), u'data',
                            u'test-invalid-use.ini')
    with pytest.raises(CkanConfigurationException):
        CKANConfigLoader(filename).get_config()
Ejemplo n.º 2
0
def test_ckan_config_loader_parse_two_files():
    """
    CKANConfigLoader should parse both 'test-extension.ini.tpl' and
    'test-core.ini.tpl' and override the values of 'test-core.ini.tpl' with
    the values of test-extension.ini.tpl.

    Values in [DEFAULT] section are always override.
    """
    tpl_dir = os.path.dirname(__file__) + u'/templates'
    extension_tpl_dir = tpl_dir + u'/ckanext-extension'
    filename = os.path.join(extension_tpl_dir, u'test-extension.ini.tpl')
    conf = CKANConfigLoader(filename).get_config()

    # Debug should be override by test-core.ini.tpl since is in DEFAULT section
    assert conf[u'debug'] == u'false'
    # __file__ should never be override if parsing two files
    assert conf[u'__file__'] == filename

    assert conf[u'key1'] == extension_tpl_dir + u'/extension'
    assert conf[u'key2'] == tpl_dir + u'/core'
    assert conf[u'key3'] == extension_tpl_dir + u'/extension'
    assert conf[u'key4'] == u'extension'

    with pytest.raises(KeyError):
        conf[u'host']

    assert conf[u'global_conf'][u'__file__'] == filename
    assert conf[u'global_conf'][u'here'] == tpl_dir
    assert conf[u'global_conf'][u'debug'] == u'false'
Ejemplo n.º 3
0
def test_other_env_vars_ignored(monkeypatch):
    """Non-CKAN_ environment variables are ignored
    """
    filename = os.path.join(os.path.dirname(__file__), u'data',
                            u'test-no-env-var.ini')
    monkeypatch.setenv("TEST_ENV_VAR", "value")
    with pytest.raises(InterpolationMissingOptionError):
        CKANConfigLoader(filename).get_config()
Ejemplo n.º 4
0
def test_ckan_env_vars_in_config(monkeypatch):
    """CKAN_ prefixed environment variables can be used in config.
    """
    filename = os.path.join(os.path.dirname(__file__), u'data',
                            u'test-env-var.ini')
    monkeypatch.setenv("CKAN_TEST_ENV_VAR", "value")
    conf = CKANConfigLoader(filename).get_config()
    assert conf["var"] == "value"
Ejemplo n.º 5
0
def test_recursive_loading():
    """ Make sure we still remember main config file.

    If there are circular dependencies, make sure the user knows about it.
    """
    filename = os.path.join(os.path.dirname(__file__), u'data',
                            u'test-one-recursive.ini')
    with pytest.raises(CkanConfigurationException):
        CKANConfigLoader(filename).get_config()
Ejemplo n.º 6
0
def test_chain_loading():
    """Load chains of config files via `use = config:...`.
    """
    filename = os.path.join(os.path.dirname(__file__), u'data',
                            u'test-one.ini')
    conf = CKANConfigLoader(filename).get_config()
    assert conf[u'__file__'] == filename
    assert conf[u'key1'] == u'one'
    assert conf[u'key2'] == u'two'
    assert conf[u'key3'] == u'three'
Ejemplo n.º 7
0
def test_ckan_config_loader_parse_files():
    """
    CKANConfigLoader should parse both 'test.ini.tpl' and 'test-core.ini.tpl'
    files since test.ini.ptl has a use = config:test-core.ini.tpl config.
    """
    filename = os.path.join(os.path.dirname(__file__), u'data/test.ini.tpl')
    conf = CKANConfigLoader(filename).get_config()

    assert conf.global_conf[u'debug'] == u'true'
    assert conf.global_conf[u'smtp_server'] == u'localhost'
    assert conf.local_conf[u'ckan.site_id'] == u'default'
    assert conf.local_conf[u'faster_db_test_hacks'] == u'True'
    assert conf.local_conf[u'cache_dir'] == u'/tmp/default/'
    assert (conf.local_conf[u'sqlalchemy.url'] ==
            u'postgresql://*****:*****@localhost/ckan_test')
Ejemplo n.º 8
0
def test_variables_in_chained_files():
    """Variables are available accross all files in chain.

    When variables got redefined latest version is used, just as in python's
    class-inheritance. The only exception is the `here` variable, which
    evaluated immediately.
    """
    here = os.path.dirname(__file__)
    filename = os.path.join(here, u'data', u'test-one.ini')
    conf = CKANConfigLoader(filename).get_config()
    assert conf["one.from2"] == "2"
    assert conf["one.from3"] == "3"

    assert conf["two.from3"] == "3"

    assert conf["parts"] == "one two three"

    assert conf["here.one"] == os.path.join(here, "data")
    assert conf["here.two"] == os.path.join(here, "data", "sub")
    assert conf["here.three"] == os.path.join(here, "data")
Ejemplo n.º 9
0
def test_ckan_config_loader_parse_file():
    """
    CKANConfigLoader should parse and interpolate variables in
    test-core.ini.tpl file both in DEFAULT and app:main section.
    """
    tpl_dir = os.path.dirname(__file__) + u'/templates'
    filename = os.path.join(tpl_dir, u'test-core.ini.tpl')
    conf = CKANConfigLoader(filename).get_config()

    assert conf[u'debug'] == u'false'

    assert conf[u'key1'] == tpl_dir + u'/core'
    assert conf[u'key2'] == tpl_dir + u'/core'
    assert conf[u'key4'] == u'core'

    assert conf[u'__file__'] == filename

    with pytest.raises(KeyError):
        conf[u'host']

    assert conf['here'] == tpl_dir
Ejemplo n.º 10
0
# -*- coding: utf-8 -*-

import os
from ckan.config.middleware import make_app
from ckan.cli import CKANConfigLoader
from logging.config import fileConfig as loggingFileConfig
config_filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                               u'production.ini')
abspath = os.path.join(os.path.dirname(os.path.abspath(__file__)))
loggingFileConfig(config_filepath)
config = CKANConfigLoader(config_filepath).get_config()
application = make_app(config)