def tearDown(self): """ Tear Down """ with self.app.app_context(): db.session.remove() db.drop_all()
def setup_db(): app = create_app() app.config.from_object('config.TestConfig') with app.app_context(): db.create_all() yield app db.drop_all()
def test_client(): app = create_app() app.config.from_object('config.TestConfig') with app.app_context(): db.create_all() yield app.test_client() db.drop_all()
def app(): app = create_app('testing') with app.app_context(): db.create_all() yield app # Note that we changed return for yield, see below for why db.session.remove() db.drop_all() return app
def test_db(test_app): # pylint: disable=redefined-outer-name """ test db fixture """ # with app context with test_app.app_context(): # create database tables db.create_all() # yield session yield db # drop all tables created db.drop_all()
def tearDown(self): db.session.remove() db.drop_all()
from src.app import db, create_app from src.orm_models import Player, PlayerScore, GameType, Tournament, Game, Leaderboard from sqlalchemy.sql import func import datetime '''This is used to create an example populated database. Can be run from the root folder of the project with 'python -m src.example' ''' #Setup the database app = create_app('development') app_context = app.app_context() app_context.push() db.drop_all() db.create_all() #This function creates example data in the database def first_example(): #GAME 1 - A chess game with 3 players #Players player_1 = Player(name="Alice") player_2 = Player(name="Bob") player_3 = Player(name="Charles") #Example game type game_type = GameType(name="chess", max_players=3) #Create a chess tournament (created_at defaults to func.now() but is here as an example)
def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()
def resource(app): db.create_all() Role.insert_roles() yield resource db.session.remove() db.drop_all()
def drop_all_tables(): db.drop_all()
def create_db(): db.init_app(app) db.drop_all() db.create_all() db.session.commit()
def drop_db(): db.init_app(app=app) db.drop_all()
def drop_db(): """Drop database tables.""" db.drop_all()
def drop_db(): db.drop_all()
def drop_schema_and_tables(): db.drop_all()