diff --git a/server/README.md b/server/README.md index 8061fd7..8a003b7 100644 --- a/server/README.md +++ b/server/README.md @@ -18,6 +18,12 @@ pipenv shell ## Configuration +Specify a settings file + +```bash +export SERVER_SETTINGS='' +``` + ## Running ### Docker @@ -29,12 +35,20 @@ docker run -d corvus:local-test ### Local Development Version +Run a local version + ```bash FLASK_APP=corvus:corvus flask db upgrade python manage.py user register-admin FLASK_APP=corvus:corvus flask run ``` +Set log level + +```bash +export SERVER_LOGLEVEL=DEBUG +``` + ## FAQ ## Development @@ -52,6 +66,14 @@ pipenv install --dev * If everything passes follow contributing guide. +## Testing + +To run the pytests directly, use the following command + +```bash +PYTHONPATH=$(pwd) pipenv run py.test +``` + ## Contributing See ../CONTRIBUTING.md \ No newline at end of file diff --git a/server/server/__init__.py b/server/server/__init__.py index ce90f9a..cd42896 100644 --- a/server/server/__init__.py +++ b/server/server/__init__.py @@ -10,6 +10,7 @@ from server.errors import BaseError, handle_base_error, \ handle_404_error from server.utility import json_utility, session_utility +LOGLEVEL = os.environ.get('SERVER_LOGLEVEL', 'INFO').upper() dictConfig({ 'version': 1, 'formatters': {'default': { @@ -21,7 +22,7 @@ dictConfig({ 'formatter': 'default' }}, 'root': { - 'level': 'INFO', + 'level': LOGLEVEL, 'handlers': ['wsgi'] } }) @@ -48,11 +49,18 @@ def create_app(test_config: dict = None) -> Flask: TRAP_HTTP_EXCEPTIONS=True, ) + config_directory = os.getenv('SERVER_CONFIG_DIRECTORY', 'config') if test_config is None: app.logger.debug('Loading configurations') - app.config.from_object('server.default_settings') - app.config.from_pyfile('config.py', silent=True) + default_settings = 'server.default_settings' + app.logger.debug('Loading configuration from ' + default_settings) + app.config.from_object(default_settings) + config_file = config_directory + '/config.py' + if os.path.exists(config_file): + app.logger.debug('Loading config from ' + config_file) + app.config.from_pyfile(config_file, silent=True) if os.getenv('SERVER_SETTINGS', None): + app.logger.debug('Loading config from SERVER_SETTINGS=' + os.getenv('SERVER_SETTINGS', '')) app.config.from_envvar('SERVER_SETTINGS') else: app.logger.debug('Loading test configuration') diff --git a/server/tests/conftest.py b/server/tests/conftest.py index f33dabd..aaf2e48 100644 --- a/server/tests/conftest.py +++ b/server/tests/conftest.py @@ -36,6 +36,9 @@ def app() -> Generator[Flask, Any, Any]: 'TESTING': True, 'SQLALCHEMY_DATABASE_URI': test_database_uri, }) + test_settings = 'tests.test_settings' + server_app.logger.debug('Loading configuration from ' + test_settings) + server_app.config.from_object(test_settings) register_blueprints(server_app) register_error_handlers(server_app) diff --git a/server/test_settings.py b/server/tests/test_settings.py similarity index 100% rename from server/test_settings.py rename to server/tests/test_settings.py