Example #1
0
def test_envelop_helper_methods():
    # Given that I have an environment with some variables set
    data = {
        'str': 'I heard you like variables',
        'int': '42',
        'float': '3.14',
        'bool0': 'True',
        'bool1': 'true',
        'bool2': '1',
        'bool3': '2',
        'bool4': 'False',
        'bool5': 'false',
        'bool6': '0',
        'list': 'foo,bar,baz'
    }
    env = Environment(storage=data)

    # Let's retrieve things with their correct types
    assert env.get_int('int') == 42
    assert env.get_float('float') == 3.14
    assert env.get_bool('bool0') is True
    assert env.get_bool('bool1') is True
    assert env.get_bool('bool2') is True
    assert env.get_bool('bool3') is True
    assert env.get_bool('bool4') is False
    assert env.get_bool('bool5') is False
    assert env.get_bool('bool6') is False
    assert env.get_list('list') == ['foo', 'bar', 'baz']

    # Sanity checks
    with pytest.raises(ValueError):
        env.get_int('str')
    with pytest.raises(ValueError):
        env.get_float('str')
    assert env.get_bool('str') is False

    # Testing default values
    assert env.get('i-dont-exist', 'blah') == 'blah'
    assert env.get_int('i-dont-exist', 2) == 2
    assert env.get_float('i-dont-exist', 2.5) == 2.5
    assert env.get_bool('i-dont-exist', True) is True
Example #2
0
BOOTSTRAP_USE_MINIFIED = True
BOOTSTRAP_SERVE_LOCAL = True
BOOTSTRAP_CDN_FORCE_SSL = True
BOOTSTRAP_QUERYSTRING_REVVING = True

# Identifying environment
LOCAL = str(PORT) == str(LOCAL_PORT)

# used for indicating where static files live in
ENVIRONMENT = {
    'production': 'pro',
    'development': 'dev',
}[env.get('OLDSPEAK_ENVIRONMENT', 'development')]

# Detecting environment
DEBUG = env.get_bool('DEBUG')

# HTTP
HOST = env.get("HOST") or 'oldspeak'
DOMAIN = env.get("DOMAIN") or '{HOST}:{PORT}'.format(**locals())
SCHEME = env.get('SCHEME') or (
    'oldspeak' not in DOMAIN and 'https://' or 'http://')
LOG_LEVEL_NAME = (env.get('LOG_LEVEL') or 'INFO').upper()

# Database-related

SQLALCHEMY_DATABASE_URI = env.get('SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://01d5pk:kp5d10@localhost/01d5pk')
DATA_DIR = env.get('OLDSPEAK_DATADIR', "~/.oldspeak/data")
REDIS_URI = env.get_uri("REDIS_URI") or 'redis://localhost:6379'

# Filesystem