示例#1
0
    def test_update_user_details_successfully_updates(self, user, mock):
        form = self.produce_form(
            birthday="25 04 2000",
            gender="awesome",
            location="here",
            website="http://web.site",
            avatar="http://web.site/avatar.png",
            signature="use a cursive font",
            notes="got 'em",
        )
        handler = mock.Mock(spec=ChangeSetHandler)
        view = ChangeUserDetails(form=form, details_update_handler=handler)

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

        assert flashed == [("success", "User details updated.")]
        assert result.status_code == 302
        assert result.headers["Location"] == url_for("user.change_user_details")
        handler.apply_changeset.assert_called_once_with(
            user,
            UserDetailsChange(
                birthday=date(2000, 4, 25),
                gender="awesome",
                location="here",
                website="http://web.site",
                avatar="http://web.site/avatar.png",
                signature="use a cursive font",
                notes="got 'em",
            ),
        )
示例#2
0
    def test_update_user_fails_with_invalid_input(self, mock):
        form = self.produce_form(birthday="99 99 999999")
        handler = mock.Mock(spec=ChangeSetHandler)
        view = ChangeUserDetails(form=form, details_update_handler=handler)

        view.post()

        assert form.errors == {"birthday": ["Not a valid date value"]}
示例#3
0
    def test_update_user_fails_with_persistence_error(self, mock):
        form = self.produce_form(birthday="25 04 2000")
        handler = mock.Mock(spec=ChangeSetHandler)
        handler.apply_changeset.side_effect = PersistenceError("no")
        view = ChangeUserDetails(form=form, details_update_handler=handler)

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

        assert flashed == [("danger", "Error while updating user details")]
        assert result.status_code == 302
        assert result.headers["Location"] == url_for("user.change_user_details")
示例#4
0
    def test_update_user_fails_with_stopvalidation(self, mock):
        form = self.produce_form(birthday="25 04 2000")
        handler = mock.Mock(spec=ChangeSetHandler)
        handler.apply_changeset.side_effect = StopValidation(
            [("birthday", "I just want you to know that's a great birthday")]
        )
        view = ChangeUserDetails(form=form, details_update_handler=handler)

        view.post()

        assert form.errors == {
            "birthday": ["I just want you to know that's a great birthday"]
        }
示例#5
0
    def test_renders_get_okay(self, mock):
        form = self.produce_form()
        handler = mock.Mock(spec=ChangeSetHandler)
        view = ChangeUserDetails(form=form, details_update_handler=handler)

        view.get()