def test_password_not_inDB(): reset_data() A = AF.auth_register("*****@*****.**", 'HoyaLee2019', "Hoya", "Lee") AF.auth_passwordreset_request("*****@*****.**") code = AHF.generate_reset_code() password = '******' with pytest.raises(AF.ValueError): AF.auth_passwordreset_reset(code, password)
def test_auth_passwordreset_request(): ''' Test functions for auth_passwordreset_request ''' data.initialise_all() # Create account to be password reset request auth.auth_register("*****@*****.**", "valid_password", "a", "b") # Password reset request is sent to valid email auth.auth_passwordreset_request("*****@*****.**") # Password reset request is sent to invalid email with pytest.raises(ValueError, match="Email is not valid"): auth.auth_passwordreset_request("comp1531receive.com")
def test_get_reset_code_from_email(): ''' Returns a reset_code according to a user email ''' # Register a user user = auth.auth_register("*****@*****.**", "passsword", "a", "b") user = helpers.get_user_by_token(user["token"]) user2 = auth.auth_register("*****@*****.**", "passsword", "a", "b") user2 = helpers.get_user_by_token(user2["token"]) auth.auth_passwordreset_request(user2.email) # No such email request assert helpers.get_reset_code_from_email("*****@*****.**") is None # Reset email request auth.auth_passwordreset_request(user.email) assert helpers.get_reset_code_from_email(user.email) ==\ global_var.data["reset_code"][1]["reset_code"]
def test_get_user_by_reset_code(): ''' Ensures that get_user_by_reset_code obtains the correct user u_id ''' # Initialisation global_var.initialise_all() # Creating a user user = auth.auth_register("*****@*****.**", "pass123", "Raydon", "Smith") u_id = user["u_id"] auth.auth_passwordreset_request("*****@*****.**") reset_code = auth.generate_reset_code(u_id) assert helpers.get_user_by_reset_code(reset_code) == u_id assert helpers.get_user_by_reset_code(-1) is None
def test_auth_passwordreset_reset(): ''' Test functions for auth_passwordreset_reset ''' data.initialise_all() # Create account to be password reset request auth.auth_register("*****@*****.**", "valid_password", "a", "b") # Password reset request is sent to valid email auth.auth_passwordreset_request("*****@*****.**") # Password is reset when valid reset code and password is given reset_code = get_reset_code_from_email("*****@*****.**") auth.auth_passwordreset_reset(reset_code, "new_password") # Reset code is invalid with pytest.raises(ValueError, match="Invalid Reset Code"): auth.auth_passwordreset_reset("invalid_reset_code", "valid_password") # Invalid password is given with pytest.raises(ValueError, match="Invalid Password"): auth.auth_passwordreset_reset(reset_code, "bpas")
def auth_passwordreset_request(): """ Given an email address, if the user is a registered user, sends an email with a code that when entered into auth_passwordreset_reset authorises the user to change their password """ email = request.form.get("email") msg = auth.auth_passwordreset_request(email) mail = Mail(APP) mail.send(msg) return dumps({})
def test_auth_password_fail_requeset(): email = None AF.auth_passwordreset_request(email) == None
def test_auth_password_succ_requeset(): email = '*****@*****.**' AF.auth_passwordreset_request(email)