def teardown(): app.logger.info("Dropping Database") try: db.drop_all() except: app.logger.info("No tables detected.") app.logger.info("Dropping Alembic table") migrations = os.path.join(os.path.dirname(os.path.realpath(__file__)), r'../migrations') app.logger.info(f"Migrations Folder: {migrations}") app.logger.info( f"Migrations folder exists: {os.path.exists(migrations)}") app.logger.info("Removing migrations folder.") try: shutil.rmtree(migrations) except FileNotFoundError: app.logger.info("Migrations folder does not exists.") app.logger.info( f"Migrations folder exists: {os.path.exists(migrations)}") try: db.engine.execute("DROP TABLE alembic_version") except: app.logger.info("Alemic Table does not exists.")
def forge(user, follow, photo, file, tag, collect, comment): """Generate fake data.""" from server.fakes import fake_admin, fake_comment, fake_follow, fake_photo, fake_file, fake_tag, fake_user, fake_collect db.drop_all() db.create_all() click.echo('Initializing the roles and permissions...') Role.init_role() click.echo('Generating the administrator...') fake_admin() click.echo('Generating %d users...' % user) fake_user(user) click.echo('Generating %d follows...' % follow) fake_follow(follow) click.echo('Generating %d tags...' % tag) fake_tag(tag) click.echo('Generating %d photos...' % photo) fake_photo(photo) click.echo("Generating files ") fake_file(file) click.echo('Generating %d collects...' % photo) fake_collect(collect) click.echo('Generating %d comments...' % comment) fake_comment(comment) click.echo('Done.')
def init(): """ Initialize the database. :return: db session create_all result """ db.drop_all() return db.create_all()
def create_db(): """Drop and create the database.""" # Create uuid-ossp extension, if it doesn't exist. db.session.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";') db.session.commit() db.reflect() db.drop_all() db.create_all()
def drop(force=False): """ Drop all database tables """ if force or prompt_bool("Are you sure you want to drop all the database tables?"): db.drop_all() return True return False
def initdb(drop): """Initialize the database.""" if drop: click.confirm( 'This operation will delete the database, do you want to continue?', abort=True) db.drop_all() click.echo('Drop tables.') db.create_all() click.echo('Initialized database.')
def dbmodels(app): """Database and models. If the database defined in `SQLALCHEMY_DATABASE_URI` already exists, it is dropped and re-created. """ with app.app_context(): # If there is an existing database, make sure to drop it and re-create # it in order to make sure that we're getting a clean testrun. db.drop_all() db.create_all()
def db(app): """ Setup our database, this only gets executed once per session. :param app: Pytest fixture :return: SQLAlchemy database session """ _db.drop_all() _db.create_all() return _db
def init_database(): # Create the database and the database table db.create_all() # Insert user data # ... # Commit the changes for the users db.session.commit() yield db # this is where the testing happens! db.drop_all()
def init(with_testdb): """ Initialize the database. :param with_testdb: Create a test database :return: None """ db.reflect() db.drop_all() db.create_all() if with_testdb: db_uri = '{0}_test'.format(app.config['SQLALCHEMY_DATABASE_URI']) if not database_exists(db_uri): create_database(db_uri) return None
def db(app): """ Setup database, executed once per session. :param app: Pytest fixture :return: SQLAlchemy database session """ _db.drop_all() _db.create_all() # Create a single user because a lot of tests do not mutate this user. params = { 'role': 'admin', 'email': '*****@*****.**', 'password': '******', 'coins': 100 } admin = User(**params) _db.session.add(admin) _db.session.commit() return _db
def setUp(self): super(CLITestCase, self).setUp() db.drop_all()
def tearDownClass(cls): db.session.remove() db.drop_all()
from server.app import create_app from server.elastic_models import SamVendorsIndex from server.database_models import SamVendors load_dotenv(find_dotenv()) if __name__ == "__main__": app = create_app() # create tables on the database with app.app_context(): print("Dropping tables...") db.drop_all() print("Dropping functions...") db.engine.execute("DROP FUNCTION IF EXISTS modify_updated_at CASCADE;") print("Creating tables.") db.create_all() with open("sam_gov_data.csv") as f: data = [tuple(line) for line in csv.reader(f)] insert_statment = """ INSERT INTO sam_vendors( duns,
def tearDown(self): with self.app.app_context(): db.session.remove() db.drop_all()
def drop_db(): """Drops the db tables.""" db.drop_all()