def app(): """ Setup our flask test app, this only gets executed once. :return: Flask app """ db_uri = '{0}_test'.format(settings.SQLALCHEMY_DATABASE_URI) params = { 'DEBUG': False, 'TESTING': True, 'WTF_CSRF_ENABLED': False, 'SQLALCHEMY_DATABASE_URI': db_uri } _app = create_app(settings_override=params) # Establish an application context before running the tests. ctx = _app.app_context() ctx.push() yield _app ctx.pop()
import click from sqlalchemy_utils import database_exists, create_database from flexio.app import create_app from flexio.extensions import db from flexio.blueprints.user.models import User # Create an app context for the database connection. app = create_app() db.app = app @click.group() def cli(): """ Run PostgreSQL related tasks. """ pass @click.command() @click.option('--with-testdb/--no-with-testdb', default=False, help='Create a test db too?') def init(with_testdb): """ Initialize the database. :param with_testdb: Create a test database :return: None """ db.drop_all()