def test_setemail_valid(user1): user1_profile = user_profile(user1['token'], user1['u_id'])['user'] new_email = '*****@*****.**' user_profile_setemail(user1['token'], new_email) new_user1_profile = user_profile(user1['token'], user1['u_id'])['user'] assert new_user1_profile['email'] == new_email # Check that no other field has been changed assert user1_profile['u_id'] == new_user1_profile['u_id'] assert user1_profile['name_first'] == new_user1_profile['name_first'] assert user1_profile['name_last'] == new_user1_profile['name_last'] assert user1_profile['handle_str'] == new_user1_profile['handle_str']
def test_set_same(user1): user1_profile = user_profile(user1['token'], user1['u_id'])['user'] user_profile_setname(user1['token'], user1['name_first'], user1['name_last']) user_profile_setemail(user1['token'], user1['email']) user_profile_sethandle(user1['token'], user1_profile['handle_str']) new_user1_profile = user_profile(user1['token'], user1['u_id'])['user'] assert new_user1_profile['email'] == user1_profile['email'] assert new_user1_profile['name_first'] == user1_profile['name_first'] assert new_user1_profile['name_last'] == user1_profile['name_last'] assert new_user1_profile['handle_str'] == user1_profile['handle_str']
def test_setemail_taken(user1, user2): ''' when a user tries to set their user profile email to an email that is already in use by another user, an input error is thrown ''' with pytest.raises(InputError): user_profile_setemail(user1['token'], user2['email']) with pytest.raises(InputError): user_profile_setemail(user2['token'], user1['email']) # Checking that user's emails have not been altered user1_profile = user_profile(user1['token'], user1['u_id'])['user'] user2_prof = user_profile(user2['token'], user2['u_id'])['user'] assert user1_profile['email'] == user1['email'] assert user2_prof['email'] == user2['email']
def test_setemail_invalid(user1): with pytest.raises(InputError): user_profile_setemail(user1['token'], '1234') with pytest.raises(InputError): user_profile_setemail(user1['token'], '@unsw.edu.au') with pytest.raises(InputError): user_profile_setemail(user1['token'], 'username') with pytest.raises(InputError): user_profile_setemail(user1['token'], '') # Checking that user1's email has not been altered user1_profile = user_profile(user1['token'], user1['u_id'])['user'] assert user1_profile['email'] == user1['email']
def test_set_return_type(user1): setname_return = user_profile_setname(user1['token'], 'new', 'name') setemail_return = user_profile_setemail(user1['token'], '*****@*****.**') sethandle_return = user_profile_sethandle(user1['token'], 'newhandle') assert isinstance(setname_return, dict) assert isinstance(setemail_return, dict) assert isinstance(sethandle_return, dict) assert len(setname_return) == 0 assert len(setemail_return) == 0 assert len(sethandle_return) == 0
def user_profile_setemail_wsgi(): json = request.get_json() return jsonify(user_profile_setemail(json['token'], json['email']))
def test_setemail_invalid_token(inv_token): with pytest.raises(AccessError): user_profile_setemail(inv_token, "*****@*****.**")