update to create_app - if using environment ariables for SECRET_KEY testing is broken when it is outside like originally suggested

This commit is contained in:
Kassandra Keeton 2023-02-16 10:11:11 -06:00 committed by GitHub
parent 604de4b1dc
commit 133b93d337
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,12 @@ from flask import Flask
def create_app(test_config=None): def create_app(test_config=None):
"""Create and configure an instance of the Flask application.""" """Create and configure an instance of the Flask application."""
app = Flask(__name__, instance_relative_config=True) app = Flask(__name__, instance_relative_config=True)
if test_config is None:
# load the instance config, if it exists, when not testing
if os.path.isfile("config.py"):
app.config.from_pyfile("config.py", silent=True)
else:
app.config.from_mapping( app.config.from_mapping(
# a default secret that should be overridden by instance config # a default secret that should be overridden by instance config
SECRET_KEY="dev", SECRET_KEY="dev",
@ -13,9 +19,6 @@ def create_app(test_config=None):
DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"), DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"),
) )
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile("config.py", silent=True)
else: else:
# load the test config if passed in # load the test config if passed in
app.config.update(test_config) app.config.update(test_config)