Ejemplo n.º 1
0
def remove_users():
    """Remove inserted users after tests."""
    yield 1
    connection = connect_db()
    for username in TEST_USERS:
        connection.cursor().execute('DELETE FROM Users WHERE username=%s',
                                    (username, ))
    connection.commit()
    close_db(connection)
Ejemplo n.º 2
0
def prepare_create_user_db():
    """Clear a user from the database to be created."""
    username = TEST_USERS[0][0]
    connection = connect_db()
    connection.cursor().execute('DELETE FROM Users WHERE username=%s',
                                (username,))
    connection.commit()
    close_db(connection)
    return username
Ejemplo n.º 3
0
def arrange_users():
    """Insert and remove users before and after tests."""
    connection = connect_db()
    for user in TEST_USERS:
        user_id = uuid.uuid4().bytes
        username = user[0]
        password_hash = bcrypt.hashpw(user[1].encode(), bcrypt.gensalt())
        connection.cursor().execute(
            'INSERT INTO Users (userID, username, password) VALUES (%s, %s, %s)',
            (user_id, username, password_hash))
    connection.commit()
    yield 1
    for user in TEST_USERS:
        user_id = uuid.uuid4().bytes
        username = user[0]
        connection.cursor().execute('DELETE FROM Users WHERE username=%s',
                                    (username,))
    connection.commit()
    close_db(connection)
Ejemplo n.º 4
0
def app():
    flask_app = create_app('foursquare_test', testing = True, debug = True)

    with flask_app.app_context():
        conn = get_db()
        cursor = conn.cursor()
        drop_records(cursor, conn, 'venues')
        drop_records(cursor, conn, 'categories')
        build_records(conn, cursor)

        conn.commit()
        close_db()
    yield flask_app

    with flask_app.app_context():
        close_db()
        conn = get_db()
        cursor = conn.cursor()
        drop_records(cursor, conn, 'venues')
        drop_records(cursor, conn, 'categories')
        close_db()
Ejemplo n.º 5
0
def test_close_db():
    """Ensure connection to the database can be closed."""
    connection = connect_db()
    close_db(connection)
    assert not connection.is_connected()
Ejemplo n.º 6
0
def test_connect_db():
    """Ensure app can connect to the database."""
    connection = connect_db()
    assert connection.is_connected()
    close_db(connection)