def test_user_profile_setemail(): reset_all() data1 = auth_register('*****@*****.**', 'password', 'jiahao', 'zhang') u_id1 = data1['u_id'] token1 = data1['token'] data2 = auth_register('*****@*****.**', 'password', 'jiahao', 'zhang') token2 = data2['token'] assert user_profile_setemail(token1, '*****@*****.**') == {} #token changed after successful change email #check for new eamil login data3 = auth_login('*****@*****.**', 'password') token3 = data3['token'] assert user_profile(token3, u_id1) == { 'u_id': u_id1, 'email': '*****@*****.**', 'name_first': 'jiahao', 'name_last': 'zhang', 'handle_str': 'jiahaozhang', } ##token1 = auth_login('*****@*****.**','password')['token'] with pytest.raises(InputError): user_profile_setemail(token3, '5') with pytest.raises(InputError): user_profile_setemail(token3, '*****@*****.**') with pytest.raises(InputError): user_profile_setemail(token2, '*****@*****.**')
def test_login(get_new_user, reset): reset u_id1, token1 = get_new_user results2 = auth_login('*****@*****.**', 'a1b2c3d4e5') u_id2 = results2['u_id'] token2 = results2['token'] assert u_id1 == u_id2 assert token1 == token2
def get_token_via_email(): data = auth_login('*****@*****.**', 'password123') return data['token']
def login(): email = request.form.get("email") password = request.form.get("password") dumps = auth_login(email,password) return dumps()
def test_login_no_input(reset): reset with pytest.raises(InputError): auth_login('', '')
def test_login_incorrect_password(get_new_user, reset): reset get_new_user with pytest.raises(InputError): auth_login('*****@*****.**', 'wrongpassword')
def test_login_email_not_registered(reset): reset with pytest.raises(InputError): auth_login('*****@*****.**', 'random123')
def test_login_invalid_email(reset): reset with pytest.raises(InputError): auth_login('z1234567.unsw', 'a1b2c3d4e5')
def login(): '''Logs in a user with their email and password.''' details = request.get_json() return dumps(auth_login(details["email"], details["password"]))