From 774a0af9db439f50421a47249c57e5a0a6932301 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 11 Apr 2025 14:52:12 -0500 Subject: Update application initialisation to allow config updates for tests. --- uploader/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'uploader/__init__.py') diff --git a/uploader/__init__.py b/uploader/__init__.py index 734bdcd..e25fc5b 100644 --- a/uploader/__init__.py +++ b/uploader/__init__.py @@ -8,7 +8,7 @@ from flask import Flask, request from flask_session import Session from cachelib import FileSystemCache -from gn_libs import jobs +from gn_libs import jobs as gnlibs_jobs from uploader.oauth2.client import user_logged_in, authserver_authorise_uri @@ -54,9 +54,15 @@ def setup_logging(app: Flask) -> Flask: return __log_gunicorn__(app) if bool(software) else __log_dev__(app) -def create_app(): - """The application factory""" +def create_app(config: dir): + """The application factory. + + config: dict + Useful to override settings in the settings files and environment + especially in environments such as testing.""" app = Flask(__name__) + + ### BEGIN: Application configuration app.config.from_pyfile( Path(__file__).parent.joinpath("default_settings.py")) if "UPLOADER_CONF" in os.environ: @@ -71,6 +77,8 @@ def create_app(): if secretsfile.exists(): # Silently ignore secrets if the file does not exist. app.config.from_pyfile(secretsfile) + app.config.update(config) # Override everything with passed in config + ### END: Application configuration app.config["SESSION_CACHELIB"] = FileSystemCache( cache_dir=Path(app.config["SESSION_FILESYSTEM_CACHE_PATH"]).absolute(), @@ -96,5 +104,5 @@ def create_app(): app.register_blueprint(speciesbp, url_prefix="/species") register_error_handlers(app) - jobs.init_app(app) + gnlibs_jobs.init_app(app) return app -- cgit v1.2.3