def post(self, request, *args, **kwargs): self.comment_obj = get_object_or_404(Comment, id=request.POST.get("commentid")) if request.user == self.comment_obj.commented_by: form = TaskCommentForm(request.POST, instance=self.comment_obj) if form.is_valid(): return self.form_valid(form) return self.form_invalid(form) data = {"error": "You don't have permission to edit this comment."} return JsonResponse(data)
def test_invalid_comment(self): comment = TaskCommentForm(data={"comment_on_task": None}) self.assertFalse(comment.is_valid())
def test_valid_comment(self): comment = TaskCommentForm(data={"comment_on_task": "New comment"}) self.assertTrue(comment.is_valid())