Пример #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_login_google_cant_login_with_password(client):
    # Create user
    create_user(client, VALID_TOKEN)

    # Login password
    user = build_user()
    user['email'] = '*****@*****.**'
    status, res = login_with_password(client, user)

    assert status == 401
    assert res['message'] == 'User doesn\'t have password'
Пример #5
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'
Пример #6
0
def test_block_user_google_login(client):
    token = create_user_and_login(client, role='admin')

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

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

    status, res = google_login(client, VALID_GOOGLE_TOKEN)

    assert status == 403
    assert res['message'] == 'User is blocked'
Пример #7
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
Пример #8
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])
Пример #9
0
def test_login_with_password_and_google(client):
    # Create user
    user = build_user()
    user['email'] = '*****@*****.**'
    create_user_with_password(client, user)

    # Login password
    status, res = login_with_password(client, user)
    base64_data = res['token'].split('.')[1]

    missing_padding = len(base64_data) % 4
    if missing_padding:
        base64_data += (b'=' * (4 - missing_padding)).decode()

    decoded_data = b64decode(base64_data.encode()).decode()
    data = json.loads(decoded_data)

    assert status == 200
    assert data['id']
    assert data['email'] == '*****@*****.**'
    assert data['exp']

    # Login google
    status, res = login(client, VALID_TOKEN)

    base64_data = res['token'].split('.')[1]

    missing_padding = len(base64_data) % 4
    if missing_padding:
        base64_data += (b'=' * (4 - missing_padding)).decode()

    decoded_data = b64decode(base64_data.encode()).decode()
    data = json.loads(decoded_data)

    assert status == 200
    assert data['id']
    assert data['email'] == '*****@*****.**'
    assert data['exp']
Пример #10
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']