def test_search_valid_token(user_1): """Test if token does not refer to a valid user """ auth.auth_logout(user_1['token']) with pytest.raises(AccessError): search(user_1['token'], "Test") clear()
def test_update_handle_invalid_token(user_1): """ Testing that an invalid token will not allow you to change the handle """ auth.auth_logout(user_1['token']) with pytest.raises(AccessError): user.user_profile_sethandle(user_1['token'], 'blahblah') 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_update_invalid_token(user_1, logout_user_1): """ Testing user cant change name with an invalid token """ auth.auth_logout(user_1['token']) with pytest.raises(AccessError): user.user_profile_setname(user_1['token'], 'Bobby', 'Smith') clear()
def test_output_admin_owner_change_owner_to_member_logout(user_1, user_2, private_channel_1): """Test whether permission change carry through after logout """ admin_userpermission_change(user_1["token"], user_2["u_id"], OWNER) admin_userpermission_change(user_1["token"], user_2["u_id"], MEMBER) auth.auth_logout(user_2['token']) user_2 = auth.auth_login('*****@*****.**', 'password') with pytest.raises(AccessError): channel.channel_join(user_2['token'], private_channel_1['channel_id']) clear()
def test_access_admin_valid_token(user_1): """Test if token is invalid does not refer to a valid user """ auth.auth_logout(user_1['token']) with pytest.raises(AccessError): admin_userpermission_change(user_1["token"], user_1["u_id"], OWNER) with pytest.raises(AccessError): admin_userpermission_change(user_1["token"], user_1["u_id"], MEMBER) with pytest.raises(AccessError): admin_userpermission_change("INVALID", user_1["u_id"], MEMBER) clear()
def test_login_incorrect_password(): """ testing using the incorrect password """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) with pytest.raises(InputError): auth.auth_login('*****@*****.**', 'abcdef') clear()
def test_output_admin_owner_change_member_to_owner_logout(user_1, user_2, public_channel_1): """Testing whether the permission change carry through after user logout and logs back in. """ admin_userpermission_change(user_1["token"], user_2["u_id"], OWNER) auth.auth_logout(user_2["token"]) user_2 = auth.auth_login('*****@*****.**', 'password') # Owner can join any channels including private # Testing user, with now as flockr owner to join private channel channel.channel_join(user_2['token'], public_channel_1['channel_id']) clear()
def test_login_invalid_password(): """ checks if the password inputted is correct, and that the user exists in the active users data """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) with pytest.raises(InputError): auth.auth_login('*****@*****.**', 'abcde') clear()
def test_logout_failure(): """ Testing failures when logging out """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Chris', 'Hie') logout = auth.auth_logout(result['token']) logout2 = auth.auth_logout(result['token']) assert logout['is_success'] assert not logout2['is_success'] clear()
def test_login_invalid_password_chars(): """ Checks if the password inputted contains valid characters """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) with pytest.raises(InputError): auth.auth_login('*****@*****.**', 'h $ e L ( 0') clear()
def test_valid_passwords(): """ passwords can contain all visible characters on the keyboard, except space """ clear() result = auth.auth_register('*****@*****.**', '!@#$%^&*()_+-=][<>w;:"', 'who', 'where') auth.auth_logout(result['token']) auth.auth_login('*****@*****.**', '!@#$%^&*()_+-=][<>w;:"') with pytest.raises(InputError): auth.auth_register('*****@*****.**', 'h el$l o', 'who', 'where') clear()
def test_request_logged_out(): """ Testing that a user can request a password reset when logged out """ clear() email_1 = '*****@*****.**' result_1 = auth.auth_register(email_1, 'abcdefg', 'John', 'Smith') auth.auth_logout(result_1['token']) auth.auth_passwordreset_request(email_1) data = pickle.load(open("data.p", "rb")) for user in data.get_reset_users(): if user['u_id'] == result_1['u_id']: assert user['email'] == email_1 clear()
def test_login_reset_password(): """ Testing that a user should not be able to login when they have requested a password reset. """ clear() auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') user = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(user['token']) auth.auth_passwordreset_request('*****@*****.**') with pytest.raises(AccessError): auth.auth_login('*****@*****.**', 'abcdefg') clear()
def test_logout_without_valid_token(): """ make sure token is required to log out. """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) auth.auth_register('*****@*****.**', 'abcdefg', 'Bob', 'Build') logout = auth.auth_logout(result['token']) assert not logout['is_success'] with pytest.raises(AccessError): channels.channels_create(result['token'], 'name', True) clear()
def test_logout_before_registering(): """ testing tokens are needed to logout. """ clear() result = auth.auth_logout('*****@*****.**') assert not result['is_success'] clear()
def test_register_logout(): """ user should be able to logout when registered """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') logout = auth.auth_logout(result['token']) assert logout['is_success'] clear()
def test_logout_not_registered(): """ make sure the token is required to log out. """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') false_token = 'invalid_tok' assert false_token != result['token'] logout = auth.auth_logout(false_token) assert not logout['is_success'] 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()
def test_standup_send_expired_token(user_1, user_2, user_3, user_4, public_channel_1): """Testing expired token for users which have logged out """ auth.auth_logout(user_1['token']) auth.auth_logout(user_2['token']) auth.auth_logout(user_3['token']) auth.auth_logout(user_4['token']) with pytest.raises(AccessError): standup.standup_send(user_1['token'], public_channel_1['channel_id'], 'Hey') with pytest.raises(AccessError): standup.standup_send(user_2['token'], public_channel_1['channel_id'], 'Hey') with pytest.raises(AccessError): standup.standup_send(user_3['token'], public_channel_1['channel_id'], 'Hey') with pytest.raises(AccessError): standup.standup_send(user_4['token'], public_channel_1['channel_id'], 'Hey') clear()
def route_auth_logout(): """Given an active token, invalidates the token to log the user out. If a valid token is given, and the user is successfully logged out, it returns true, otherwise false. Args: token (string): unique identifier for user Returns: (dict): { is_success } """ payload = request.get_json() try: return dumps(auth.auth_logout(payload['token'])) except (InputError, AccessError) as e: return e
def test_logout_basic(): """ testing the basics of loging out and logging back in. """ clear() result = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result['token']) result2 = auth.auth_login('*****@*****.**', 'abcdefg') auth.auth_logout(result2['token']) clear() result3 = auth.auth_register('*****@*****.**', 'abcdefg', 'Christian', 'Ilagan') auth.auth_logout(result3['token']) clear()
def logout_user_1(user_1): return auth.auth_logout(user_1['token'])