def test_app(): app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True app.config["TESTING"] = True _db.init_app(app) with app.app_context(): _db.create_all() yield app _db.drop_all()
def test_app(): """Set up test Flask application.""" # Set up Flask app app = Flask(__name__) # We will create database in memory # That way, we don't worry about after cleaning/removing it after running tests app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" app.config["TESTING"] = True app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True _db.init_app(app) with app.app_context(): # Create database tables _db.create_all() yield app # Our database is stored in memory so the following line is not needed # I'm using it to show you how to clean up after your tests _db.drop_all()
"""Main file of our application. When ran with: $ python run.py it will reset the database and start the webserver. """ from todo import app, db if __name__ == "__main__": db.drop_all() db.create_all() app.run(host="0.0.0.0")
def setUp(self): todo.app.config['TESTING'] = True todo.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/todo_test.db' self.app = todo.app.test_client() db.create_all()
def setUp(self): todo.app.config['TESTING'] = True todo.app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/todo_test.db' self.app = todo.app.test_client() db.create_all()
from migrate.versioning import api from config import SQLALCHEMY_DATABASE_URI from config import SQLALCHEMY_MIGRATE_REPO from todo import db import os.path db.create_all() if not os.path.exists(SQLALCHEMY_MIGRATE_REPO): api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository') api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) else: api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
def app_inst(): app.config.from_object("config.TestConfig") db.create_all() yield app db.drop_all()
def init_db(): db.create_all()
def setUp(self): self.app = create_app('TES') self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def init(): db.create_all()