test for env var prefix
This commit is contained in:
parent
97d8b9e908
commit
9572ecc5ea
|
@ -132,7 +132,7 @@ class Config(dict):
|
||||||
|
|
||||||
if load_env:
|
if load_env:
|
||||||
prefix = SANIC_PREFIX if load_env == True else load_env
|
prefix = SANIC_PREFIX if load_env == True else load_env
|
||||||
self.load_environment_vars(prefix=load_env)
|
self.load_environment_vars(prefix=prefix)
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -19,15 +19,21 @@ def test_load_from_object():
|
||||||
def test_auto_load_env():
|
def test_auto_load_env():
|
||||||
environ["SANIC_TEST_ANSWER"] = "42"
|
environ["SANIC_TEST_ANSWER"] = "42"
|
||||||
app = Sanic()
|
app = Sanic()
|
||||||
assert app.config.TEST_ANSWER == "42"
|
assert app.config.TEST_ANSWER == 42
|
||||||
del environ["SANIC_TEST_ANSWER"]
|
del environ["SANIC_TEST_ANSWER"]
|
||||||
|
|
||||||
def test_auto_load_env():
|
def test_dont_load_env():
|
||||||
environ["SANIC_TEST_ANSWER"] = "42"
|
environ["SANIC_TEST_ANSWER"] = "42"
|
||||||
app = Sanic(load_env=False)
|
app = Sanic(load_env=False)
|
||||||
assert getattr(app.config, 'TEST_ANSWER', None) == None
|
assert getattr(app.config, 'TEST_ANSWER', None) == None
|
||||||
del environ["SANIC_TEST_ANSWER"]
|
del environ["SANIC_TEST_ANSWER"]
|
||||||
|
|
||||||
|
def test_load_env_prefix():
|
||||||
|
environ["MYAPP_TEST_ANSWER"] = "42"
|
||||||
|
app = Sanic(load_env='MYAPP_')
|
||||||
|
assert app.config.TEST_ANSWER == 42
|
||||||
|
del environ["MYAPP_TEST_ANSWER"]
|
||||||
|
|
||||||
def test_load_from_file():
|
def test_load_from_file():
|
||||||
app = Sanic('test_load_from_file')
|
app = Sanic('test_load_from_file')
|
||||||
config = b"""
|
config = b"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user