def test_user_profile_setemail(): # creating users user1 = auth_register('*****@*****.**', 'password1', 'user1', 'userlast1', None) user2 = auth_register('*****@*****.**', 'password2', 'user2', 'userlast2', None) token1 = user1['token'] token2 = user2['token'] u_id1 = user1['u_id'] u_id2 = user2['u_id'] # raising errors for invalid users and taken email addresses with pytest.raises(InputError): ''' email entered is not a valid email ''' user_profile_setemail(token1, 'notavalidemailaddress') ''' email address is already being used by another user ''' user_profile_setemail(token1, '*****@*****.**') user_profile_setemail(token2, '*****@*****.**') # updating the users' email address user_profile_setemail(token1, '*****@*****.**') user_profile_setemail(token2, '*****@*****.**') for user in users: if user['u_id'] == u_id1: assert user['email'] == '*****@*****.**' if user['u_id'] == u_id2: assert user['email'] == '*****@*****.**' clear()
def test_email_not_taken(): """ test setemail email not taken """ auth_register("*****@*****.**", "password", "Donald", "Trump") user2 = auth_register("*****@*****.**", "password2", "Donald2", "Trump2") user_profile_setemail(user2['token'], "*****@*****.**")
def test_setemail_ivt(): """ test with set email invalid token """ auth_register("*****@*****.**", "password", "Donald", "Trump") with pytest.raises(AccessError): user_profile_setemail('THISISNOTATOKEN', "*****@*****.**")
def test_setemail_successful(): clear() user_a = register_n_users(1) user_profile_setemail(user_a["token"], "*****@*****.**") user_a_profile = user_profile(user_a["token"], user_a["u_id"])["user"] assert user_a_profile["email"] == "*****@*****.**"
def test_invalid_email_5(): """ test setemail with invalid email """ user = auth_register("*****@*****.**", "password", "Donald", "Trump") with pytest.raises(InputError): user_profile_setemail(user['token'], "!@#$%^&*()_")
def test_valid_profile_setemail(): # A few valid emails: # user1 : user1 = auth_register('*****@*****.**', 'haydEn123', 'Hayden', 'Smith') token = user1['token'] assert user_profile_setemail(token, '*****@*****.**') == {} # user2 : user2 = auth_register('*****@*****.**', 'haydEn123', 'Hayden', 'Smith') token = user2['token'] assert user_profile_setemail(token, '*****@*****.**') == {} # user3 : user3 = auth_register('*****@*****.**', 'passw0rD', 'Abdul', 'Ahmed') token = user3['token'] assert user_profile_setemail(token, '*****@*****.**') == {} # user4 : user4 = auth_register('*****@*****.**', 'Timeforth4i', 'Mathews', 'Foodcourt') token = user4['token'] assert user_profile_setemail(token, '*****@*****.**') == {}
def test_user_setemail_valid_email(user1): """ Testing successful uses of user_profile_setemail focusing on valid emails """ user.user_profile_setemail(user1["token"], "*****@*****.**") check_email_change(user1, "*****@*****.**") other.clear()
def test_email_exists_setemail(): """Testing an invalid setemail entry where email already exists""" clear() auth_register("*****@*****.**", "password", "Darth", "Vader") new_user2 = auth_register("*****@*****.**", "password", "Luke", "Skywalker") with pytest.raises(InputError): user_profile_setemail(new_user2["token"], "*****@*****.**")
def test_setemail_invalid_email(initial_users): ''' invalid test for profile setemail register and login user give an invalid email ''' with pytest.raises(InputError): user_profile_setemail(users[0]['token'], 'testvalidtest.com')
def test_email_already_taken(): """ test setemail email already taken """ auth_register("*****@*****.**", "password", "Donald", "Trump") user2 = auth_register("*****@*****.**", "password2", "Donald2", "Trump2") with pytest.raises(InputError): user_profile_setemail(user2['token'], "*****@*****.**")
def test_setemail_occupied_email(initial_users): ''' invalid test for the profile email being used register and login user give an used email ''' with pytest.raises(InputError): user_profile_setemail(users[0]['token'], '*****@*****.**')
def test_no_email_input(): login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] with pytest.raises(InputError): user.user_profile_setemail(token, "")
def test_user_profile_setemail_unique_changes(get_users): jwang_token, jwang_u_id, kli_token, kli_u_id = get_users user_profile_setemail(kli_token, "*****@*****.**") user_profile_setemail(jwang_token, "*****@*****.**") assert user_profile(jwang_token, kli_u_id)["user"]["email"] == "*****@*****.**" assert user_profile( kli_token, jwang_u_id)["user"]["email"] == "*****@*****.**"
def test_invalid_email(): reset_data() login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] #email does not contain the @ with pytest.raises(InputError): user.user_profile_setemail(token, 'cs1531.unsw.edu.au')
def test_invalid_email(): ''' Testing when email is invalid. ''' clear() user_1 = auth.auth_register("*****@*****.**", "password", "User_1", "User_last_1") with pytest.raises(error.InputError): user.user_profile_setemail(user_1.get('token'), 'invalid_email')
def test_invalid_token(): ''' Testing when token is invalid. ''' clear() user_1 = auth.auth_register("*****@*****.**", "password", "User_1", "User_last_1") with pytest.raises(error.AccessError): user.user_profile_setemail('invalid_token', user_1.get('email'))
def user_profile_setemail(): ''' Takes a token and an email and updates the users email ''' data = request.get_json() token = data['token'] email = data['email'] user.user_profile_setemail(token, email) return dumps({})
def test_invalid_token(): login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] with pytest.raises(InputError): user.user_profile_setemail("".join((token, 'wrong')), '*****@*****.**')
def user_profile_setemail(): """ Function user profile setemail route """ input_data = request.get_json() user.user_profile_setemail(input_data['token'], input_data['email']) return dumps({})
def test_user_profile_setemail_invalid_email(): '''Test that checks an exception is raised when an invalid email is given''' other.clear() test_user = auth.auth_register("*****@*****.**", "testpass", "Milhouse", "Houten") with pytest.raises(InputError): user.user_profile_setemail(test_user['token'], "milhouten.com")
def test_already_used_email(): ''' Testing when updated email is already being used. ''' clear() user_1 = auth.auth_register("*****@*****.**", "passwordone", "User_1", "User_last_1") with pytest.raises(error.InputError): user.user_profile_setemail(user_1.get('token'), '*****@*****.**')
def test_profile_setemail_valid(initial_users): ''' valid test for profile setemail register and login user update the email ''' user_profile_setemail(users[0]['token'], '*****@*****.**') assert user_profile( users[0]['token'], users[0]['u_id'])['user']['email'] == '*****@*****.**'
def test_user_setemail_invalid_email(user1): """ Testing unsuccessful uses of user_profile_setemail focusing on invalid emails """ with pytest.raises(InputError): assert user.user_profile_setemail(user1["token"], "thisisaninvalidemail.com") assert user.user_profile_setemail(user1["token"], "invalidemail") other.clear()
def test_email_already_taken(): reset_data() auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") login2 = auth.auth_register("*****@*****.**", "123456", "Robbie", "Caldwell") token = login2['token'] #attempting to change to an already taken email with pytest.raises(InputError): user.user_profile_setemail(token, '*****@*****.**')
def test_user_profile_setemail_contains_nums_symbols(get_users): jwang_token, jwang_u_id = get_users[:2] user_profile_setemail(jwang_token, "*****@*****.**") assert user_profile(jwang_token, jwang_u_id)["user"]["email"] == "*****@*****.**" user_profile_setemail(jwang_token, "*****@*****.**") assert user_profile( jwang_token, jwang_u_id)["user"]["email"] == "*****@*****.**"
def profile_setemail(): ''' A route to call user_profile_setemail ''' payload = request.get_json() if not payload["token"] or not payload["email"]: raise RequestError(description="Missing data in request body") user.user_profile_setemail(payload["token"], payload["email"]) return json.dumps({})
def test_valid_user_profile_setemail(): """Testing a valid setemail entry""" clear() new_user = auth_register("*****@*****.**", "password", "Clint", "Eastwood") user_profile_setemail(new_user["token"], "*****@*****.**") assert user_profile(new_user["token"], new_user["u_id"] == \ {'user': {'email': '*****@*****.**', \ 'name_first': 'Clint', 'name_last': \ 'Eastwood', 'handle_str': 'clinteast', "profile_img_url": "", \ "u_id": new_user["u_id"]}})
def test_valid_email(): reset_data() login = auth.auth_register("*****@*****.**", "123456", "Hayden", "Jacobs") token = login['token'] u_id = login['u_id'] #checking that email has properly changed user.user_profile_setemail(token, '*****@*****.**') profile = user.user_profile(token, u_id) assert profile['user']['email'] == '*****@*****.**'
def test_user_profile_setemail_update(): clear() user = auth_register('*****@*****.**', 'Y1ppY1ppY!!', 'Anag', 'Airno') user_profile_setemail(user['token'], '*****@*****.**') u_prof = user_profile(user['token'], user['u_id']) assert u_prof['user']['email'] == '*****@*****.**' user_profile_setemail(user['token'], '*****@*****.**') u_prof = user_profile(user['token'], user['u_id']) assert u_prof['user']['email'] == '*****@*****.**'
def test_user_profile_setemail_used_email(): '''Test that checks an exception is raised when the updated email is already in use by another user''' other.clear() auth.auth_register("*****@*****.**", "testpass", "Milhouse", "Houten") second_test_user = auth.auth_register("*****@*****.**", "testpass", "Bart", "Simpson") with pytest.raises(InputError): user.user_profile_setemail(second_test_user['token'], "*****@*****.**")