コード例 #1
0
 def test_basic_config(self):
     os.environ["ENVVAR"] = "Environment Variable Value"
     config = Configuration()
     self.assertEqual(config("ENVVAR"), "Environment Variable Value")
     self.assertEqual(config("ENVFILE"), "Environment File Value")
     self.assertEqual(config("INIFILE"), "INI File Value")
     self.assertEqual(len(config.configurations),
                      3)  # envvar + .env + settings.ini
コード例 #2
0
 def test_basic_config_with_starting_path(self):
     os.environ["ENVVAR"] = "Environment Variable Value"
     starting_path = os.path.dirname(__file__)
     config = Configuration(starting_path=starting_path)
     self.assertEqual(config("ENVVAR"), "Environment Variable Value")
     self.assertEqual(config("ENVFILE"), "Environment File Value")
     self.assertEqual(config("INIFILE"), "INI File Value")
     self.assertEqual(len(config.configurations),
                      3)  # envvar + .env + settings.ini
コード例 #3
0
ファイル: test_config.py プロジェクト: motiteux/prettyconf
def test_basic_config(env_config, ini_config):
    os.environ["ENVVAR"] = "Environment Variable Value"
    config = Configuration()
    assert repr(config).startswith("Configuration(loaders=[")
    assert config("ENVVAR") == "Environment Variable Value"
    assert config("ENVFILE") == "Environment File Value"
    assert config("INIFILE") == "INI File Value"
    assert len(config.loaders) == 2  # Environment + RecursiveSearch
    del os.environ["ENVVAR"]
コード例 #4
0
 def test_basic_config(self):
     os.environ["ENVVAR"] = "Environment Variable Value"
     config = Configuration()
     self.assertTrue(repr(config).startswith("Configuration(loaders=["))
     self.assertEqual(config("ENVVAR"), "Environment Variable Value")
     self.assertEqual(config("ENVFILE"), "Environment File Value")
     self.assertEqual(config("INIFILE"), "INI File Value")
     self.assertEqual(len(config.loaders),
                      2)  # Environment + RecursiveSearch
     del os.environ["ENVVAR"]
コード例 #5
0
 def test_customized_loaders(self):
     os.environ["ENVVAR"] = "Environment Variable Value"
     os.environ["ENVVAR2"] = "Foo"
     loaders = [EnvFile(self.envfile), Environment(), IniFile(self.inifile)]
     config = Configuration(loaders=loaders)
     self.assertEqual(config("ENVVAR"), "Must be overrided")
     self.assertEqual(config("ENVVAR2"), "Foo")
     self.assertEqual(config("ENVFILE"), "Environment File Value")
     self.assertEqual(config("INIFILE"), "INI File Value")
     self.assertEqual(len(config.loaders), 3)
     del os.environ["ENVVAR"]
     del os.environ["ENVVAR2"]
コード例 #6
0
ファイル: test_config.py プロジェクト: motiteux/prettyconf
def test_customized_loaders(env_config, ini_config):
    os.environ["ENVVAR"] = "Environment Variable Value"
    os.environ["ENVVAR2"] = "Foo"
    loaders = [EnvFile(env_config), Environment(), IniFile(ini_config)]
    config = Configuration(loaders=loaders)
    assert config("ENVVAR") == "Must be overrided"
    assert config("ENVVAR2") == "Foo"
    assert config("ENVFILE") == "Environment File Value"
    assert config("INIFILE") == "INI File Value"
    assert len(config.loaders) == 3
    del os.environ["ENVVAR"]
    del os.environ["ENVVAR2"]
コード例 #7
0
from decimal import Decimal

from django.conf import settings
from prettyconf.configuration import Configuration

# Tells to prettyconf the .env path
config = Configuration(starting_path=settings.BASE_DIR)

# Defines the exchange_orderbook package name
PACKAGE_NAME = 'exchange_orderbook'

# Tells to django where is the configuration class of this package
default_app_config = PACKAGE_NAME + '.apps.Config'

# Orderbook session config
settings.ORDERBOOK_BASE_CURRENCY_SESSION_NAME = config(
    'ORDERBOOK_BASE_CURRENCY_SESSION_NAME', default='orderbook_base_currency')
settings.ORDERBOOK_MARKET_SESSION_NAME = config(
    'ORDERBOOK_MARKET_SESSION_NAME', default='orderbook_market')
settings.INTERMEDIATION_PASSIVE_FEE = config('INTERMEDIATION_PASSIVE_FEE',
                                             default=Decimal('0.003'),
                                             cast=Decimal)
settings.INTERMEDIATION_ACTIVE_FEE = config('INTERMEDIATION_ACTIVE_FEE',
                                            default=Decimal('0.005'),
                                            cast=Decimal)

# Orders listing config
settings.ORDERBOOK_TABLE_LIMIT = config('ORDERBOOK_TABLE_LIMIT', default=50)
settings.TRADINGVIEW_THEME = config('TRADINGVIEW_THEME', default='light')
settings.TRADINGVIEW_HEIGHT = config('TRADINGVIEW_HEIGHT',
                                     default=500,
コード例 #8
0
 def test_none_as_default_value(self):
     config = Configuration()
     self.assertIsNone(config("UNKNOWN", default=None))
コード例 #9
0
 def test_fail_unknown_config_without_default_value(self):
     os.environ["ENVVAR"] = "Environment Variable Value"
     config = Configuration()
     with self.assertRaises(UnknownConfiguration):
         config("UNKNOWN")
コード例 #10
0
 def test_fail_invalid_cast_type(self):
     os.environ["INTEGER"] = "42"
     config = Configuration()
     with self.assertRaises(TypeError):
         config("INTEGER", cast="not callable")
コード例 #11
0
 def test_config_cast_value(self):
     os.environ["INTEGER"] = "42"
     config = Configuration()
     self.assertEqual(config("INTEGER", cast=int), 42)
コード例 #12
0
 def test_config_default_values(self):
     config = Configuration()
     self.assertEqual(config("DEFAULT", default="Default Value"),
                      "Default Value")
コード例 #13
0
ファイル: settings.py プロジェクト: neosacode/bootstrap
import os

import dj_database_url
from prettyconf.configuration import Configuration

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

config = Configuration(starting_path=BASE_DIR)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', default=False, cast=config.boolean)

ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=config.list)

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'exchange_core',
コード例 #14
0
ファイル: test_config.py プロジェクト: motiteux/prettyconf
def test_none_as_default_value():
    config = Configuration()
    assert config("UNKNOWN", default=None) is None
コード例 #15
0
ファイル: test_config.py プロジェクト: motiteux/prettyconf
def test_config_cast_value():
    os.environ["INTEGER"] = "42"
    config = Configuration()
    assert config("INTEGER", cast=int) == 42
コード例 #16
0
ファイル: test_config.py プロジェクト: motiteux/prettyconf
def test_config_default_values():
    config = Configuration()
    assert config("DEFAULT", default="Default Value") == "Default Value"