Skip to content
Snippets Groups Projects
Commit cc1bbb8c authored by Simon Künzel's avatar Simon Künzel
Browse files

Update initialization. Add warning and some comments.

parent 97b9bd55
No related branches found
No related tags found
1 merge request!3Rollout to production
Pipeline #6025 passed
......@@ -9,7 +9,7 @@ socket = /uwsgi/uwsgi.sock
manage-script-name = true
chdir = ./src/
mount = /=app:api_app
mount = /=app:app
need-app = true # Fail if startup throws exception
master = true # Master manages our workers (in our case, just one worker)
......
# noinspection PyUnresolvedReferences
from app import api_app as app, api_config as config
# We have these here because 'api.config' and 'api.live_config' is nicer than 'app.config' and 'api.live_config.config'
from app import app, config
from api.live_config import config as live_config
import locale
if __name__ == "__main__":
print("You are running app.py as the main file. This is not supported and causes import errors. Execute with 'flask run' instead")
exit(-1)
import os
from flask import Flask, Config
locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
api_app = Flask("api")
api_config = api_app.config
app = Flask("api")
config = app.config
api_config.from_pyfile(os.path.join(os.getcwd(), os.environ["VIDEOAG_API_CONFIG"]))
config.from_pyfile(os.path.join(os.getcwd(), os.environ["VIDEOAG_API_CONFIG"]))
if "VIDEOAG_API_TEST_CONFIG_OVERRIDE" in os.environ:
override_config = Config(api_config.root_path)
override_config = Config(config.root_path)
override_config.from_pyfile(os.path.join(os.getcwd(), os.environ["VIDEOAG_API_TEST_CONFIG_OVERRIDE"]))
# Merge the config files manually to also merge dicts (instead of one overwriting the other)
for key, value in override_config.items():
if key not in api_config:
api_config[key] = value
if key not in config:
config[key] = value
continue
if isinstance(value, dict) and isinstance(api_config[key], dict):
api_config[key] |= value
if isinstance(value, dict) and isinstance(config[key], dict):
config[key] |= value
else:
api_config[key] = value
config[key] = value
if "SECRET_KEY" not in api_config:
api_config["SECRET_KEY"] = os.urandom(24) # pragma: no cover
# A key is required for flask (This key is used to sign the cookies)
if "SECRET_KEY" not in config:
config["SECRET_KEY"] = os.urandom(24) # pragma: no cover
# Import routes AFTER initialization
# noinspection PyUnresolvedReferences
import api.routes
......@@ -3,7 +3,7 @@
if __name__ == '__main__':
import app
import unittest
app.api_app.testing = True
app.app.testing = True
# This is always run from src/
suite = unittest.defaultTestLoader.discover("../tests/", pattern="*", top_level_dir="../tests")
if not unittest.TextTestRunner(verbosity=2, failfast=True).run(suite).wasSuccessful():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment