aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-08-31 03:27:28 +0300
committerFrederick Muriuki Muriithi2022-08-31 03:27:28 +0300
commit215f4e07ccb7cef5db2c50d322a28576e2b9fd68 (patch)
treed32b3c61d70c9f5311270309af361cd0f46f4ed1
parent19c376c4b60592f4bba0e26952faa3a71b6f5641 (diff)
downloadgn-uploader-215f4e07ccb7cef5db2c50d322a28576e2b9fd68.tar.gz
Check connections outside app factory
Check the connections in the wsgi.py file, outside of the `create_app` application factory to avoid issues with tests failing due to test app not initialising because of missing connections in the test environment.
-rw-r--r--qc_app/__init__.py5
-rw-r--r--wsgi.py13
2 files changed, 12 insertions, 6 deletions
diff --git a/qc_app/__init__.py b/qc_app/__init__.py
index eefe236..6b760b9 100644
--- a/qc_app/__init__.py
+++ b/qc_app/__init__.py
@@ -7,7 +7,6 @@ from flask import Flask
from .entry import entrybp
from .parse import parsebp
from .dbinsert import dbinsertbp
-from .check_connections import check_db, check_redis
def instance_path():
"""Retrieve the `instance_path`. Raise an exception if not defined."""
@@ -26,10 +25,6 @@ def create_app(instance_dir):
app.config.from_pyfile(os.path.join(os.getcwd(), "etc/default_config.py"))
app.config.from_pyfile("config.py") # Override defaults with instance path
- # Check the connection
- check_db(app.config["SQL_URI"])
- check_redis(app.config["REDIS_URL"])
-
# setup blueprints
app.register_blueprint(entrybp, url_prefix="/")
app.register_blueprint(parsebp, url_prefix="/parse")
diff --git a/wsgi.py b/wsgi.py
index baf6ce5..40c4473 100644
--- a/wsgi.py
+++ b/wsgi.py
@@ -1,8 +1,19 @@
"""Run the application"""
from qc_app import create_app, instance_path
+from qc_app.check_connections import check_db, check_redis
-app = create_app(instance_path())
+def check_and_build_app():
+ # Setup the app
+ appl = create_app(instance_path())
+
+ # Check connections
+ check_db(appl.config["SQL_URI"])
+ check_redis(appl.config["REDIS_URL"])
+ return appl
+
+app = check_and_build_app()
if __name__ == "__main__":
+ # Run the app
app.run()