Пример #1
0
def test_toggle_user():
    my_backend = Backend(cfg, init=True)
    #create user
    my_backend.add_user(user_id)
    #check it's active
    user = my_backend.get_users(user_id=user_id)[0]
    assert user[USER_ACTIVE] == 1
    #disable user
    my_backend.toggle_user(user_id, active=False)
    #check it's inactive
    user = my_backend.get_users(user_id=user_id)[0]
    assert user[USER_ACTIVE] == 0
    #enable user
    my_backend.toggle_user(user_id, active=True)
    #check it's active
    user = my_backend.get_users(user_id=user_id)[0]
    assert user[USER_ACTIVE] == 1
Пример #2
0
def test_get_user():
    #create DB
    my_backend = Backend(cfg, init=True)
    my_backend.add_user(user_id)
    #check that user was correctly created
    db = sqlite3.connect(DB_path)
    cursor = db.cursor()
    sql = ''' SELECT * FROM users WHERE id=? '''
    cursor.execute(sql, (user_id, ))
    resp = cursor.fetchone()
    assert resp[USER_ID] == user_id and \
           resp[USER_ACTIVE] == 1
    #load user
    user = my_backend.get_users(user_id=user_id)[0]
    assert user[USER_ID] == user_id and \
           resp[USER_ACTIVE] == 1
Пример #3
0
def test_add_user():
    #create DB
    my_backend = Backend(cfg, init=True)
    #make sure user does not exist
    assert my_backend.get_users(user_id=user_id) == []
    #create user
    assert my_backend.add_user(user_id)
    db = sqlite3.connect(DB_path)
    cursor = db.cursor()
    sql = ''' SELECT * FROM users WHERE id=? '''
    cursor.execute(sql, (user_id, ))
    resp = cursor.fetchone()
    assert resp[USER_ID]     == user_id and \
        resp[USER_ACTIVE] == 1
    #adding the same user should fail
    assert not my_backend.add_user(user_id)