Beispiel #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
Beispiel #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
Beispiel #3
0
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
Beispiel #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'
Beispiel #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'
Beispiel #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
Beispiel #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
Beispiel #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'
Beispiel #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
Beispiel #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 ...
Beispiel #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
Beispiel #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
Beispiel #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']
Beispiel #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 ...
Beispiel #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
Beispiel #16
0
def test_basic_values_work_without_load():
    c = Config()
    c.init('TEST', str, 'TEST')
    # no load!

    assert c['TEST'] == 'TEST'
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")
Beispiel #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()
Beispiel #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