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)
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'
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'
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'
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'
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
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])
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']