Coverage for src/app/__init__.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-03-24 22:02 -0400

1"""Build the Flask app so it can be used by the flask CLI, a production 

2middleware like Gunicorn, etc.""" 

3 

4import os 

5 

6from flask import Flask, jsonify, redirect 

7 

8from common import app_config 

9from common.app_config import FlaskConfig 

10from common.models.base import db 

11from common.models.cuecode_config import CuecodeConfig 

12 

13from .api import create_blueprint as create_api_blueprint 

14from .portal import create_blueprint as create_portal_blueprint 

15 

16 

17def create_app(): 

18 """create and configure the app""" 

19 

20 app = Flask(__name__) 

21 app.config.from_object(FlaskConfig()) 

22 

23 app.config["SQLALCHEMY_DATABASE_URI"] = app_config.SQLALCHEMY_DATABASE_URI 

24 db.init_app(app) 

25 

26 # Apply blueprints 

27 # https://flask.palletsprojects.com/en/stable/blueprints/ 

28 portal_bp = create_portal_blueprint() 

29 app.register_blueprint(portal_bp, url_prefix="/portal") 

30 

31 api_bp = create_api_blueprint() 

32 app.register_blueprint(api_bp, url_prefix="/api") 

33 

34 # health check endpoint 

35 @app.route("/health-check", methods=["GET"]) 

36 def health(): 

37 return jsonify( 

38 { 

39 "status": "UP", 

40 "database": "UP - [To be worked upon]", # TODO: add database health pylint: disable=fixme 

41 } 

42 ) 

43 

44 @app.route("/") 

45 def index(): 

46 """If the user visits the root path, redirect them to the Portal""" 

47 return redirect("/portal") 

48 

49 return app