示例#1
0
def test_basic():
    c = Config(env_prefix='VIRTUAL_')
    c.init('HOST', str, '0.0.0.0')
    c.init('PORT', int, 8080)
    c.load()

    assert c['HOST'] == '0.0.0.0'
    assert c['PORT'] == 8080
示例#2
0
def test_basic():
    c = Config()
    c.init('HOST', str, '0.0.0.0')
    c.init('PORT', int, 8080)
    c.load()

    assert c['HOST'] == '0.0.0.0'
    assert c['PORT'] == 8080
示例#3
0
文件: config.py 项目: Sparkycz/Better
def init_config():

    c = Config(env_prefix='')

    c.init('SPORTS', list, [
        'fotbal', 'hokej', 'basketbal', 'hazena', 'baseball', 'florbal',
        'futsal', 'ragby'
    ])

    c.init('PROXY', str)

    c.init('ELASTICSEARCH_HOST', str)

    c.load()

    return c
示例#4
0
def test_case_sensitivity():
    c = Config()
    c.init('TEST', str, 'TEST')
    with pytest.warns(UserWarning):
        c.init('test', str, 'test')
    c.load()

    assert c['TEST'] == 'TEST'
    assert c['test'] == 'test'
示例#5
0
def test_nonprefixed_variables_dont_override_nonempty_prefix():
    c = Config(env_prefix='PREFIX_')
    c.init('HOST', str, '0.0.0.0')
    with env(HOST='1.2.3.4'):
        c.load()

    assert c['HOST'] == '0.0.0.0'
示例#6
0
def test_int_from_environ():
    c = Config(env_prefix='PREFIX_')
    c.init('NUM', int, 666)
    with env(PREFIX_NUM='42'):
        c.load()

    assert c['NUM'] == 42
示例#7
0
def test_bool_like_true(value):
    c = Config(env_prefix='')
    c.init('VALUE', bool_like)
    with env(VALUE=value):
        c.load()

    assert c['VALUE'] is True
示例#8
0
def test_prefixed_variables_override():
    c = Config(env_prefix='PREFIX_')
    c.init('HOST', str, '0.0.0.0')
    with env(PREFIX_HOST='1.2.3.4'):
        c.load()

    assert c['HOST'] == '1.2.3.4'
示例#9
0
def test_python_bool_type(value):
    c = Config(env_prefix='')
    with pytest.warns(UserWarning):
        c.init('VALUE', bool)
    with env(VALUE=value):
        c.load()

    assert c['VALUE'] is True
示例#10
0
def test_custom_converter():
    def custom(value):
        return ...

    c = Config(env_prefix='')
    c.init('VALUE', custom)
    with env(VALUE='42'):
        c.load()
    assert c['VALUE'] is ...
示例#11
0
def test_json():
    c = Config(env_prefix='')
    c.init('VALUE1', json)
    c.init('VALUE2', json)
    with env(VALUE1='{"aha": [1, 1.2, false]}', VALUE2='1'):
        c.load()

    assert c['VALUE1'] == {'aha': [1, 1.2, False]}
    assert c['VALUE2'] == 1
示例#12
0
def test_python_numeric_types_converters(_type):
    c = Config(env_prefix='')
    c.init('VALUE', _type)
    with env(VALUE='1'):
        c.load()

    assert c['VALUE'] == _type('1')
    assert c['VALUE'] == 1
    assert type(c['VALUE']) == _type
示例#13
0
def test_nonexisting_config_is_missing():
    c = Config()
    c.init('TEST', str, 'TEST')
    c.load()

    assert 'TEST' in c
    assert 'NOMNOMNOM' not in c

    with pytest.raises(KeyError):
        c['NOMNOMNOM']
示例#14
0
def test_custom_anonymous_converter():
    c = Config(env_prefix='')
    c.init('VALUE', lambda x:...)
    with env(VALUE='42'):
        c.load()
    assert c['VALUE'] is ...
示例#15
0
from llconfig import Config
from llconfig.converters import bool_like
from pathlib import Path

config = Config()

# Keep README in sync!

config.init("TELEGRAM_BOT_TOKEN", str, None)
config.init("TELEGRAM_CHAT_ID", int, None)

config.init("SENTRY_DSN", str, None)
config.init("SENTRY_ENVIRONMENT", str, "production")

# https://crontab.guru/
config.init("TRANSACTION_WATCH_CRON", str, "0 * * * *")  # each hour
config.init("FLIGHT_WATCH_CRON", str, "0 20 * * *")  # every day at 20:00
config.init("FLIGHT_WATCH_DAYS_BACK", int, 30)

config.init("RUN_TASKS_AFTER_STARTUP", bool_like,
            False)  # if True, first run tasks and then wait for next CRON

# https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome
config.init(
    "USER_AGENT", str,
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.114 Safari/537.36"
)
config.init("SESSION_ID", str)

config.init("LIVENESS", Path, Path("/tmp/liveness"))
config.init("LIVENESS_SLEEP", int, 20)  # seconds
示例#16
0
def test_basic_values_work_without_load():
    c = Config()
    c.init('TEST', str, 'TEST')
    # no load!

    assert c['TEST'] == 'TEST'
示例#17
0
from pathlib import Path

from aiohttp import ClientTimeout
from llconfig import Config
from llconfig.converters import bool_like

config = Config()

config.init("LOGGING_LEVEL", str, "INFO")

config.init("HTTP_TIMEOUT", lambda val: ClientTimeout(total=int(val)),
            ClientTimeout(total=10))  # seconds
config.init("HTTP_RAISE_FOR_STATUS", bool_like, True)

config.init("STATE", Path, Path("/state/state.json"))
config.init("LIVENESS", Path, Path("/tmp/liveness"))

config.init("TELEGRAM_BOT_TOKEN", str, None)

config.init("SLEEP", int, 600)  # seconds
config.init("BACKOFF_SLEEP", int, 1200)  # seconds

config.init("SENTRY_DSN", str, None)
config.init("SENTRY_ENVIRONMENT", str, "production")
示例#18
0
from llconfig import Config
from llconfig.converters import bool_like

c = config = Config()
c.init('SENDGRID_API_KEY', str, None)
c.init('MONGO_CONNECTION_STRING', str)
c.init('CONTACT_FORM_RECEPIENT', str, '*****@*****.**')
c.init('CONTACT_FORM_SUBJECT', str, 'Chmelovar.cz - dotaz')
c.init('FORCE_HTTPS', bool_like, False)
c.load()
示例#19
0
from aiohttp import ClientTimeout
from llconfig import Config
from llconfig.converters import bool_like

config = Config()

config.init("ROHLIK_URL", str, "https://www.rohlik.cz/services/frontend-service/timeslots-api")

config.init("HTTP_TIMEOUT", lambda val: ClientTimeout(total=int(val)), ClientTimeout(total=10))  # seconds
config.init("HTTP_RAISE_FOR_STATUS", bool_like, True)

config.init("TELEGRAM_BOT_TOKEN", str, None)

config.init("SLEEP", int, 10)  # seconds
config.init("SUCCESS_SLEEP", int, 60)  # seconds
config.init("BACKOFF_SLEEP", int, 10)  # seconds