From 86b09b9add2599852ed32e59515c0b0708f54a3b Mon Sep 17 00:00:00 2001 From: Giulia Naponiello Date: Mar 01 2018 09:37:58 +0000 Subject: Fixed load configuration The previous version used to ignore the custom configuration defined in conf/settings.py with DEV and TEST environment. --- diff --git a/README.md b/README.md index 2fee2c5..808832d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Install the project: Run the server: - $ python run-dev-server.py + $ DEV=true python run-dev-server.py The server is now running at and API calls can be sent to . @@ -41,7 +41,7 @@ values in `greenwave/config.py`. You can run the unit tests, which live in the `greenwave.tests` package, with the following command: - $ py.test greenwave/tests/ + $ TEST=true py.test greenwave/tests/ To test against all supported versions of Python, you can use tox:: @@ -55,7 +55,7 @@ The functional tests will start their own copy of the send HTTP requests to them. If you have a git checkout of all three projects, you can run the functional tests like this (adjust the paths as appropriate): - $ PYTHONPATH=../resultsdb:../waiverdb:. py.test functional-tests/ + $ TEST=true PYTHONPATH=../resultsdb:../waiverdb:. py.test functional-tests/ ## Building the docs diff --git a/greenwave/utils.py b/greenwave/utils.py index 08f1e04..f8c2375 100644 --- a/greenwave/utils.py +++ b/greenwave/utils.py @@ -59,25 +59,21 @@ def load_config(config_obj=None): :param str config_obj: An config object. For example, greenwave.config.DevelopmentConfig. :return: A dict of Greenwave configuration. """ + # Load default config, then override that with a config file config = Config(__name__) - if config_obj: - config.from_object(config_obj) + default_config_file = os.getcwd() + '/conf/settings.py' + if os.getenv('DEV') == 'true': + default_config_obj = 'greenwave.config.DevelopmentConfig' + elif os.getenv('TEST') == 'true': + default_config_obj = 'greenwave.config.TestingConfig' else: - # Load default config, then override that with a config file - default_config_file = None - if os.getenv('DEV') == 'true': - default_config_obj = 'greenwave.config.DevelopmentConfig' - elif os.getenv('TEST') == 'true': - default_config_obj = 'greenwave.config.TestingConfig' - else: - default_config_obj = 'greenwave.config.ProductionConfig' - default_config_file = '/etc/greenwave/settings.py' - config.from_object(default_config_obj) - config_file = os.environ.get('GREENWAVE_CONFIG', default_config_file) - if config_file: - config.from_pyfile(config_file) - if os.environ.get('SECRET_KEY'): - config['SECRET_KEY'] = os.environ['SECRET_KEY'] + default_config_obj = 'greenwave.config.ProductionConfig' + default_config_file = '/etc/greenwave/settings.py' + config.from_object(default_config_obj) + config_file = os.environ.get('GREENWAVE_CONFIG', default_config_file) + config.from_pyfile(config_file) + if os.environ.get('SECRET_KEY'): + config['SECRET_KEY'] = os.environ['SECRET_KEY'] config['policies'] = load_policies(config['POLICIES_DIR']) return config