def post_change_password(): json = request.get_json() validate_change_password_request(json) user = find_user_by_email(current_user.email) new_password = json["newPassword"] new_confirmation_password = json["newConfirmationPassword"] old_password = json["oldPassword"] check_password_validity(new_password, new_confirmation_password, old_password, user) user.setPassword(new_password) repository.save(user) return "", 204
def post_change_password(): user = current_user._get_current_object( ) # get underlying User object from proxy json = request.get_json() validate_change_password_request(json) new_password = json["newPassword"] new_confirmation_password = json["newConfirmationPassword"] old_password = json["oldPassword"] check_password_validity(new_password, new_confirmation_password, old_password, user) user.setPassword(new_password) repository.save(user) return "", 204
def test_change_password_raises_an_error_if_new_confirmation_password_is_not_given_as_key_in_json( self): # given user = User() user.setPassword("0ld__p455w0rd") json = {"oldPassword": "******", "newPassword": "******"} # when with pytest.raises(ApiErrors) as api_errors: validate_change_password_request(json) # then assert api_errors.value.errors["newConfirmationPassword"] == [ "Confirmation du nouveau mot de passe manquante" ]
def test_change_password_raises_an_error_if_old_password_has_no_value_in_json( self): # given user = User() user.setPassword("0ld__p455w0rd") json = { "oldPassword": "", "newPassword": "******", "newConfirmationPassword": "******" } # when with pytest.raises(ApiErrors) as api_errors: validate_change_password_request(json) # then assert api_errors.value.errors["oldPassword"] == [ "Ancien mot de passe manquant" ]
def test_change_password_raises_an_error_if_no_password_is_provided(self): # given user = User() user.setPassword("0ld__p455w0rd") json = {} # when with pytest.raises(ApiErrors) as api_errors: validate_change_password_request(json) # then assert api_errors.value.errors["newPassword"] == [ "Nouveau mot de passe manquant" ] assert api_errors.value.errors["oldPassword"] == [ "Ancien mot de passe manquant" ] assert api_errors.value.errors["newConfirmationPassword"] == [ "Confirmation du nouveau mot de passe manquante" ]