Beispiel #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #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
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

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

config.init("MONGO_CONNECTION_STRING", str, None)
config.init("MONGO_DATABASE", str, "cashier")

config.load()