def initialize_database(): with current_app.app_context(): db.create_all() yield db with current_app.app_context(): try: db.session.commit() except Exception as exception: app_logger.warning(f"Exception occurred: {exception}") pass db.session.remove() db.drop_all()
def drop_and_rebuild_sql(): app = create_app() context = app.app_context() context.push() # define working database working_database = config.DATABASE_NAME # drop working database print(f"Dropping database: {working_database}") db.drop_all() # recreate working database print(f"Creating database: {working_database}") db.create_all() context.pop()
from app.server import db from app.server.api.models.Tournament import Tournament from app.server.api.models.TournametsToObjects import TournamentsToObject from app.server.api.models.user import User from app.server.api.models.contestant import Contestant from app.server.api.models.team import Team from app.server.api.models import * db.drop_all() db.create_all() db.session.commit()
def tearDown(self): CommonTestWithDatabaseSupport.tearDownClass() db.session.remove() db.drop_all() app.config[ 'SQLALCHEMY_DATABASE_URI'] = config.Flask.SQLALCHEMY_DATABASE_URI
def setUp(self): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' db.drop_all() db.create_all()
def tearDown(self): db.session.remove() db.drop_all()
def drop_db(): """Drops the db tables.""" db.drop_all()
def tearDownClass(cls): db.session.remove() db.drop_all()
def setUp(self): db.drop_all() db.create_all()
def tearDown(self): db.session.remove() db.drop_all() super(BaseTestCase, self).tearDown()