def test_config_testing(): app = create_app("testing") assert app.config["SECRET_KEY"] != "open sesame" assert app.config["TESTING"] assert app.config["SQLALCHEMY_DATABASE_URI"] == SQLITE_TEST assert app.config["TOKEN_EXPIRE_HOURS"] == 0 assert app.config["TOKEN_EXPIRE_MINUTES"] == 0
def test_config_development(): app = create_app("development") assert app.config["SECRET_KEY"] != "open sesame" assert not app.config["TESTING"] assert app.config["SQLALCHEMY_DATABASE_URI"] == os.getenv( "DATABASE_URL", SQLITE_DEV) assert app.config["TOKEN_EXPIRE_HOURS"] == 0 assert app.config["TOKEN_EXPIRE_MINUTES"] == 15
def test_config_production(): app = create_app("production") assert app.config["SECRET_KEY"] != "open sesame" assert not app.config["TESTING"] assert app.config["SQLALCHEMY_DATABASE_URI"] == os.getenv( "DATABASE_URL", SQLITE_PROD) assert app.config["TOKEN_EXPIRE_HOURS"] == 1 assert app.config["TOKEN_EXPIRE_MINUTES"] == 0
#! /usr/bin/env python import os from flask.ext.script import Manager from flask_api import create_app, db app = create_app(os.getenv('FLASK_API_CONFIG', 'default')) manager = Manager(app) @manager.shell def make_shell_context(): return dict(app=app, db=db) if __name__ == '__main__': manager.run()
from flask_script import Manager from flask_api import create_app from flask_api.extensions import db from flask_api.user import manager as user_manager manager = Manager(create_app(register_blueprints=False)) @manager.command def init_db(): """ Initializes the tables in the database """ db.drop_all() db.create_all() db.session.commit() manager.add_command("user", user_manager) if __name__ == "__main__": manager.run()
"""Flask CLI/Application entry point.""" import os import click from flask_api import create_app, db from flask_api.models.token_blacklist import BlacklistedToken from flask_api.models.user import User from flask_api.models.widget import Widget app = create_app(os.getenv("FLASK_ENV", "development")) # This decorator makes the decorated method execute # when the flask shell command is run. # https://aaronluna.dev/series/flask-api-tutorial/part-1/#flask-cliapplication-entry-point @app.shell_context_processor def shell(): return { "db": db, "User": User, "BlacklistedToken": BlacklistedToken, "Widget": Widget, } @app.cli.command("add-user", short_help="add a new user") @click.argument("email") @click.option("--admin", is_flag=True, default=False,
from flask_api import create_app app = create_app() if __name__ == '__main__': app.run()
def app(): """ Create main app """ app = create_app("testing") return app