def test_post_reply_resolve(self, mock_reply): """The task should optionally resolve when replying""" test_text = "Lorem ipsum" form = FlaggedTaskForm({"text": test_text}) ok_(form.is_valid()) post_data = form.cleaned_data post_data.update({"reply": "truthy", "resolve": True, "task": self.task.pk}) self.post_request(post_data) self.task.refresh_from_db() ok_(self.task.resolved, "The task should resolve.") mock_reply.assert_called_with(test_text)
def test_post_reply(self, mock_reply): """Staff should be able to reply to the user who raised the flag""" test_text = 'Lorem ipsum' form = FlaggedTaskForm({'text': test_text}) ok_(form.is_valid()) post_data = form.cleaned_data post_data.update({'reply': 'truthy', 'task': self.task.pk}) self.post_request(post_data) self.task.refresh_from_db() ok_(not self.task.resolved, 'The task should not automatically resolve when replying.') mock_reply.assert_called_with(test_text)
def test_post_reply_resolve(self, mock_reply): """The task should optionally resolve when replying""" test_text = 'Lorem ipsum' form = FlaggedTaskForm({'text': test_text}) ok_(form.is_valid()) post_data = form.cleaned_data post_data.update({ 'reply': 'truthy', 'resolve': True, 'task': self.task.pk }) self.post_request(post_data) self.task.refresh_from_db() ok_(self.task.resolved, 'The task should resolve.') mock_reply.assert_called_with(test_text)
def task_post_helper(self, request, task): """Special post handler for FlaggedTasks""" if request.POST.get('reply'): reply_form = FlaggedTaskForm(request.POST) if reply_form.is_valid() and task.user: text = reply_form.cleaned_data['text'] task.reply(text) elif reply_form.is_valid(): messages.error(request, 'Cannot reply - task has no user') return else: messages.error(request, 'The form is invalid') return if request.POST.get('resolve'): task.resolve(request.user) return super(FlaggedTaskList, self).task_post_helper(request, task)
def task_post_helper(self, request, task, form_data=None): """Special post handler for FlaggedTasks""" form_data = {} if request.POST.get("reply"): form_data["reply"] = True reply_form = FlaggedTaskForm(request.POST) if reply_form.is_valid() and task.user: text = reply_form.cleaned_data["text"] task.reply(text) form_data["text"] = text elif reply_form.is_valid(): messages.error(request, "Cannot reply - task has no user") return None else: messages.error(request, "The form is invalid") return None return super(FlaggedTaskList, self).task_post_helper(request, task, form_data=form_data)