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"]}
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"] }
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", ), )
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")