diff options
author | Frederick Muriuki Muriithi | 2025-04-11 14:52:12 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-04-11 14:52:12 -0500 |
commit | 774a0af9db439f50421a47249c57e5a0a6932301 (patch) | |
tree | 698ab3ead5c2e9eb5182b6d006f637752bf7de3b | |
parent | dd2b36c5a3427c58df0cee332bd4661a3ceb0b4d (diff) | |
download | gn-uploader-774a0af9db439f50421a47249c57e5a0a6932301.tar.gz |
Update application initialisation to allow config updates for tests.
-rw-r--r-- | uploader/__init__.py | 16 |
1 files changed, 12 insertions, 4 deletions
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 |