コード例 #1
0
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()

    # Create a single user because a lot of tests do not mutate this user.
    # It will result in faster tests.
    params = {
        'role': 'admin',
        'email': '*****@*****.**',
        'password': '******',
        'coins': 100
    }

    admin = User(**params)

    _db.session.add(admin)
    _db.session.commit()

    return _db
コード例 #2
0
ファイル: cmd_db.py プロジェクト: vnscriptkid/snakeeyes
def init(with_testdb):
    """
    Initialize the database.
    :param with_testdb: Create a test database
    :return: None
    """
    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
コード例 #3
0
def db(app):
    """Creating a database instance"""
    _db.drop_all()
    _db.create_all()

    params = {
        'role': 'admin',
        'email': '*****@*****.**',
        'password': '******',
    }

    admin = User(**params)

    _db.session.add(admin)
    _db.session.commit()

    return _db