Пример #1
0
def test_get_user(client):
    user = build_user(role='host')
    status, res = create_user(client, user)

    status, res = get_user(client, res['id'])
    assert status == 200
    validate_same_user(user, res)
Пример #2
0
def test_block_user_not_authenticated(client):
    user = build_user(role='guest')
    status, res = create_user(client, user)
    user_id = str(uuid.uuid4())

    status, res = block_user(client, user_id)

    assert status == 401
    assert res['message'] == 'User not recognized'
Пример #3
0
def test_block_user_invalid_id(client):
    token = create_user_and_login(client, role='admin')

    user = build_user(role='guest')
    status, res = create_user(client, user)

    status, res = block_user(client, 'aninvalidid')

    assert status == 400
    assert res['message'] == 'Invalid id aninvalidid'
Пример #4
0
def test_block_user_non_admin(client):
    token = create_user_and_login(client, role='host')

    user = build_user(role='guest')
    status, res = create_user(client, user)
    user_id = str(uuid.uuid4())

    status, res = block_user(client, user_id, session_token=token)

    assert status == 403
    assert res['message'] == 'Only an admin can block users'
Пример #5
0
def test_block_user_login(client):
    token = create_user_and_login(client, role='admin')

    user = build_user(role='guest')
    status, res = create_user(client, user)
    user_id = res['id']

    status, res = block_user(client, user_id, session_token=token)

    status, res = login(client, user)

    assert status == 403
    assert res['message'] == 'User is blocked'
Пример #6
0
def test_block_user(client):
    token = create_user_and_login(client, role='admin')

    user = build_user(role='guest')
    status, res = create_user(client, user)
    user_id = res['id']

    status, res = block_user(client, user_id, session_token=token)

    status, res = get_user(client, user_id)

    assert status == 200
    assert res['blocked'] == True
Пример #7
0
def test_get_many_users(client):
    ids = []
    users = []
    for i in range(10):
        user = build_user(n=i, role='host')
        users.append(user)
        status, res = create_user(client, user)
        ids.append(res['id'])

    status, res = get_several_users(client, ids)

    assert status == 200
    for i in range(10):
        validate_same_user(users[i], res[i])
Пример #8
0
def create_user_and_login(client, role='host'):
    admin = build_user(role=role, n=9)
    create_user(client, admin)
    status, res = login(client, admin)
    return res['token']