def app(): print("Creating application") os.environ["ENV"] = "Testing" app = create_app("config.TestingConfig") app.config["TESTING"] = True app.config["CRON_API_KEY"] = CRON_API_KEY if app.config["SQLALCHEMY_DATABASE_URI"].lower().startswith("sqlite"): @event.listens_for(Engine, "connect") def set_sqlite_pragma(dbapi_connection, connection_record): """ Make SQLite recognize ON DELETE CASCADE. """ cursor = dbapi_connection.cursor() cursor.execute("PRAGMA foreign_keys=ON") cursor.close() # ctx = app.app_context() ctx = app.test_request_context() ctx.push() yield app ctx.pop()
def create_app(self): os.environ['ENV'] = 'Prod' os.environ['APP_CONFIG'] = '' app = create_app('config.TestingConfig') app.config['TESTING'] = True self.app = app.test_client() return app
from flask_script import Manager, Option, Command from flask_migrate import Migrate, MigrateCommand from flask_security import SQLAlchemyUserDatastore from flask_security.script import (CreateUserCommand, AddRoleCommand, RemoveRoleCommand, ActivateUserCommand, DeactivateUserCommand) from datetime import datetime from feedrsub.models.user import User from feedrsub.models.role import Role from feedrsub.models.populate_db import populate_db from feedrsub.tests.fakedatafactory import FakeDataFactory app = create_app() migrate = Migrate(app, db) manager = Manager(app) manager.add_command('db', MigrateCommand) user_datastore = SQLAlchemyUserDatastore(db, User, Role) @manager.command def add_admin(email, password): """Add an admin user to the database""" user = User.query.filter_by(email=email).first() if user is not None:
from feedrsub.core import create_app application = create_app() if __name__ == '__main__': application.run(host='0.0.0.0')
def create_app(self): os.environ['ENV'] = "Testing" app = create_app('config.TestingConfig') app.config['TESTING'] = True self.app = app.test_client() return app