예제 #1
0
    def test_updates_user_password_fails_with_invalid_inpit(self, mock, user):
        form = self.produce_form(
            old_password="******",
            new_password="******",
            confirm_new_password="******",
        )
        handler = mock.Mock(spec=ChangeSetHandler)
        view = ChangePassword(form=form, password_update_handler=handler)

        view.post()

        handler.apply_changeset.assert_not_called()
        assert "new_password" in form.errors
예제 #2
0
    def test_update_user_password_fails_with_stopvalidation_error(self, mock):
        form = self.produce_form(
            old_password="******",
            new_password="******",
            confirm_new_password="******",
        )
        handler = mock.Mock(spec=ChangeSetHandler)
        handler.apply_changeset.side_effect = StopValidation(
            [("new_password", "That's not a very strong password")]
        )
        view = ChangePassword(form=form, password_update_handler=handler)

        view.post()

        assert form.errors["new_password"] == ["That's not a very strong password"]
예제 #3
0
    def test_update_user_password_fails_with_persistence_error(self, mock):
        form = self.produce_form(
            old_password="******",
            new_password="******",
            confirm_new_password="******",
        )
        handler = mock.Mock(spec=ChangeSetHandler)
        handler.apply_changeset.side_effect = PersistenceError("no")
        view = ChangePassword(form=form, password_update_handler=handler)

        result = view.post()
        flashed = get_flashed_messages(with_categories=True)

        assert flashed == [("danger", "Error while changing password")]
        assert result.status_code == 302
        assert result.headers["Location"] == url_for("user.change_password")
예제 #4
0
    def test_updates_user_password_okay(self, user, mock):
        form = self.produce_form(
            old_password="******",
            new_password="******",
            confirm_new_password="******",
        )
        handler = mock.Mock(spec=ChangeSetHandler)
        view = ChangePassword(form=form, password_update_handler=handler)

        result = view.post()
        flashed = get_flashed_messages(with_categories=True)

        assert len(flashed) == 1
        assert flashed[0] == ("success", "Password updated.")
        assert result.status_code == 302
        assert result.headers["Location"] == url_for("user.change_password")
        handler.apply_changeset.assert_called_once_with(
            user, PasswordUpdate(old_password="******", new_password="******")
        )