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
from envelop import Environment except ImportError: raise ImportError('could not import milieu, please make sure it is installed (pip install milieu)') env = Environment() SECRET_KEY = '8y2v7mq%foapmsuftqu#)_muync$+x7$$n7$3!66kwblvh40%w' DEBUG = True PRODUCTION = False LOCAL_FILE = lambda *parts: join(abspath(dirname(__file__)), *parts) TEMPLATE_DEBUG = DEBUG SITE_DOMAIN = env.get('SITE_DOMAIN', '127.0.0.1:8000') db_auth = env.get_uri('DATABASE_DEFAULT', "mysql://root@localhost/tckt") db_options = { 'init_command': 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', 'compress': True } DATABASES = { 'default': { 'ENGINE': 'django.db.backends.{0}'.format(db_auth.scheme), 'NAME': db_auth.path.replace('/', ''), 'HOST': db_auth.host, 'PORT': db_auth.port, 'USER': db_auth.user, 'PASSWORD': db_auth.password,
local_file = lambda *path: join(abspath(dirname(__file__)), *path) module_file = lambda *path: abspath(local_file('..', *path)) project_file = lambda *path: abspath(module_file('..', *path)) env = Environment() SELF = sys.modules[__name__] CONNECTION_POOL_SIZE = multiprocessing.cpu_count() LOCAL_PORT = 19842 PORT = env.get_int('PORT', LOCAL_PORT) TEST_MODE = env.get('TEST_MODE', 'false') OLDSPEAK_WORKDIR = env.get('OLDSPEAK_WORKDIR', '/srv/oldspeak/sandbox') OLDSPEAK_DATADIR = env.get('OLDSPEAK_DATADIR', '/srv/oldspeak/private-data') OLDSPEAK_PUBLICDIR = env.get('OLDSPEAK_PUBLICDIR', '/srv/oldspeak/public-data') STATIC_FOLDER_PATH = env.get('OLDSPEAK_STATIC_FOLDER_PATH', project_file('static', 'dist')) HTML_TEMPLATE_PATH = env.get('OLDSPEAK_HTML_TEMPLATE_PATH', project_file('static', 'templates')) STATIC_URL_PREFIX = '/s' HTML_TEMPLATE_PATH = project_file('static', 'templates') BOOTSTRAP_USE_MINIFIED = True BOOTSTRAP_SERVE_LOCAL = True BOOTSTRAP_CDN_FORCE_SSL = True BOOTSTRAP_QUERYSTRING_REVVING = True # Identifying environment
raise ImportError( 'could not import milieu, please make sure it is installed (pip install milieu)' ) env = Environment() SECRET_KEY = '8y2v7mq%foapmsuftqu#)_muync$+x7$$n7$3!66kwblvh40%w' DEBUG = True PRODUCTION = False LOCAL_FILE = lambda *parts: join(abspath(dirname(__file__)), *parts) TEMPLATE_DEBUG = DEBUG SITE_DOMAIN = env.get('SITE_DOMAIN', '127.0.0.1:8000') db_auth = env.get_uri('DATABASE_DEFAULT', "mysql://root@localhost/tckt") db_options = { 'init_command': 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', 'compress': True } DATABASES = { 'default': { 'ENGINE': 'django.db.backends.{0}'.format(db_auth.scheme), 'NAME': db_auth.path.replace('/', ''), 'HOST': db_auth.host, 'PORT': db_auth.port, 'USER': db_auth.user, 'PASSWORD': db_auth.password,
def test_envelop_environment_get(): # Given that I have an environment env = Environment({'val1': 'yo'}) # When I set something assert env.get('val1') == 'yo'