diff --git a/README.md b/README.md index f5f8da1..90af60d 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ These channels need to be manually created by you in your Slack. ### Environment variables -All configs in `configuration.yaml` are overrideable through environment variables with the same name prefixed by `DESTALINATOR_` (e.g. `activated` -> `DESTALINATOR_ACTIVATED`). Set array environment variables (e.g. `DESTALINATOR_IGNORE_CHANNELS`) by comma delimiting items +All configs in `configuration.yaml` are overrideable through environment variables with the same name prefixed by `DESTALINATOR_` (e.g. `activated` -> `DESTALINATOR_ACTIVATED`). Set array environment variables (e.g. `DESTALINATOR_IGNORE_CHANNELS`) by comma delimiting items. If you only have one value for an array type environment variable add a training comma to denote the variable as a list. #### `DESTALINATOR_SB_TOKEN` (Required) diff --git a/config.py b/config.py index 364b3f6..d65d811 100644 --- a/config.py +++ b/config.py @@ -25,7 +25,7 @@ def __getattr__(self, attrname): else: envvar = os.getenv('DESTALINATOR_' + upper_attrname) if envvar is not None: - return envvar.split(',') if ',' in envvar else envvar + return [x for x in envvar.split(',') if x] if ',' in envvar else envvar return self.config.get(attrname, '') diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..e9c88c0 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,14 @@ +import os +import unittest + +from config import get_config + + +class ConfigTest(unittest.TestCase): + def setUp(self): + os.environ['DESTALINATOR_STRING_VARIABLE'] = 'test' + os.environ['DESTALINATOR_LIST_VARIABLE'] = 'test,' + + def test_environment_variable_configs(self): + self.assertEqual(get_config().string_variable, 'test') + self.assertListEqual(get_config().list_variable, ['test'])