def test_update_consecutively(user_1): """ Testing wheter the same token allows users to continously change their name """ user.user_profile_setname(user_1['token'], 'Bobby', 'Smith') user.user_profile_setname(user_1['token'], 'Snake', 'City') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: assert account['name_first'] == 'Snake' assert account['name_last'] == 'City' break user.user_profile_setname(user_1['token'], 'Goku', 'Vegeta') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: assert account['name_first'] == 'Goku' assert account['name_last'] == 'Vegeta' break user.user_profile_setname(user_1['token'], 'Will', 'Smith') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: assert account['name_first'] == 'Will' assert account['name_last'] == 'Smith' break clear()
def test_users_all_valid_token(user_1): """Test if token does not refer to a valid user """ auth.auth_logout(user_1['token']) with pytest.raises(AccessError): users_all(user_1['token']) clear()
def test_users_all(user_1, user_2, user_3, user_4): """Test if a list all users details is returned """ all_users = users_all(user_1['token']) user_count = 0 test_1 = False test_2 = False test_3 = False test_4 = False for user in all_users['users']: if user['u_id'] is user_1['u_id']: test_1 = True if user['u_id'] is user_2['u_id']: test_2 = True if user['u_id'] is user_3['u_id']: test_3 = True if user['u_id'] is user_4['u_id']: test_4 = True user_count += 1 assert user_count == 4 assert test_1 assert test_2 assert test_3 assert test_4 clear()
def test_valid_user_email(user_1, user_2, user_3): """Test whether the user's email matches the email in user_profile. """ user_1_list = users_all(user_3['token']) user_1_profile = user.user_profile(user_3['token'], user_3['u_id']) for account in user_1_list['users']: if account['u_id'] == user_1_profile['user']['u_id']: assert user_1_profile['user']['email'] == account['email']
def test_update_name(user_1): """ Testing the basic functionality of updating a name """ user.user_profile_setname(user_1['token'], 'Bobby', 'Smith') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: assert account['name_first'] == 'Bobby' assert account['name_last'] == 'Smith' clear()
def test_handle_consecutive(user_1): """ Testing the process of changing handle string consecutively """ user.user_profile_sethandle(user_1['token'], 'newHandle') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: assert account['handle_str'] == 'newHandle' user.user_profile_sethandle(user_1['token'], 'newHandle1') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: assert account['handle_str'] == 'newHandle1' user.user_profile_sethandle(user_1['token'], 'newHandle2') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: assert account['handle_str'] == 'newHandle2' clear()
def test_update_handle(user_1): """ Testing the basic functionality of updating a handle """ # getting the current handle string prev_handle = '' user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: prev_handle = account['handle_str'] user.user_profile_sethandle(user_1['token'], 'newHandle') # getting the updated handle string new_handle = '' user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_1['u_id']: new_handle = account['handle_str'] assert new_handle is not prev_handle clear()
def test_valid_user_handle_str(user_1, user_2, user_3): """Test whether the user's handle string matches the handle string in user_profile. """ user_1_list = users_all(user_2['token']) user_1_profile = user.user_profile(user_2['token'], user_2['u_id']) for account in user_1_list['users']: if account['u_id'] == user_1_profile['user']['u_id']: assert user_1_profile['user']['handle_str'] == account[ 'handle_str']
def test_valid_user_name(user_1, user_2, user_3): """Test whether the first and last name of a user is the same as the names in user_profile. """ user_1_list = users_all(user_2['token']) user_1_profile = user.user_profile(user_2['token'], user_2['u_id']) for account in user_1_list['users']: if account['u_id'] == user_1_profile['user']['u_id']: assert user_1_profile['user']['name_first'] == account[ 'name_first'] assert user_1_profile['user']['name_last'] == account['name_last']
def route_users_all(): """Returns a list of all users and their associated details Args: token (string) Returns: (dict): { users } """ try: return dumps(users_all(request.args.get('token'))) except (InputError, AccessError) as e: return e
def test_update_multiple_users(user_1, user_2, user_3, user_4): """ Testing if users name fields are appropiately changed in largely stored data """ user.user_profile_setname(user_3['token'], 'Popcorn', 'Smoothie') user.user_profile_setname(user_2['token'], 'Krillin', 'Bulma') user_list = users_all(user_1['token']) for account in user_list['users']: if account['u_id'] == user_2['u_id']: assert account['name_first'] == 'Krillin' assert account['name_last'] == 'Bulma' if account['u_id'] == user_3['u_id']: assert account['name_first'] == 'Popcorn' assert account['name_last'] == 'Smoothie' if account['u_id'] == user_1['u_id']: assert account['name_first'] == 'John' assert account['name_last'] == 'Smith' if account['u_id'] == user_4['u_id']: assert account['name_first'] == 'Janice' assert account['name_last'] == 'Smith' clear()
def test_users_all_logout(user_1, user_2, user_3, user_4): """Test if some users log out, their details are still returned """ auth.auth_logout(user_3['token']) auth.auth_logout(user_4['token']) all_users = users_all(user_1['token']) user_count = 0 test_1 = False test_2 = False test_3 = False for user in all_users['users']: if user['u_id'] is user_1['u_id']: test_1 = True if user['u_id'] is user_2['u_id']: test_2 = True if user['u_id'] is user_3['u_id']: test_3 = True user_count += 1 assert user_count == 4 assert test_1 assert test_2 assert test_3 clear()