From 9572ecc5ea2f6346c9a7879b1093719fd8b6b495 Mon Sep 17 00:00:00 2001 From: Tim Mundt Date: Tue, 5 Sep 2017 10:58:48 +0200 Subject: [PATCH] test for env var prefix --- sanic/config.py | 2 +- tests/test_config.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sanic/config.py b/sanic/config.py index 18514425..853e4a99 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -132,7 +132,7 @@ class Config(dict): if 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): try: diff --git a/tests/test_config.py b/tests/test_config.py index aa7a0e4d..e393d02b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -19,15 +19,21 @@ def test_load_from_object(): def test_auto_load_env(): environ["SANIC_TEST_ANSWER"] = "42" app = Sanic() - assert app.config.TEST_ANSWER == "42" + assert app.config.TEST_ANSWER == 42 del environ["SANIC_TEST_ANSWER"] -def test_auto_load_env(): +def test_dont_load_env(): environ["SANIC_TEST_ANSWER"] = "42" app = Sanic(load_env=False) assert getattr(app.config, 'TEST_ANSWER', None) == None 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(): app = Sanic('test_load_from_file') config = b"""