Add support for editing document comments
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -8,17 +8,17 @@ from mayan.apps.rest_api.tests import BaseAPITestCase
|
||||
from ..models import Comment
|
||||
from ..permissions import (
|
||||
permission_document_comment_create, permission_document_comment_delete,
|
||||
permission_document_comment_view
|
||||
permission_document_comment_edit, permission_document_comment_view
|
||||
)
|
||||
|
||||
from .literals import TEST_COMMENT_TEXT
|
||||
from .literals import TEST_COMMENT_TEXT, TEST_COMMENT_TEXT_EDITED
|
||||
from .mixins import DocumentCommentTestMixin
|
||||
|
||||
|
||||
class CommentAPITestCase(
|
||||
DocumentCommentTestMixin, DocumentTestMixin, BaseAPITestCase
|
||||
):
|
||||
def _request_comment_create_view(self):
|
||||
def _request_test_comment_create_api_view(self):
|
||||
return self.post(
|
||||
viewname='rest_api:comment-list', kwargs={
|
||||
'document_pk': self.test_document.pk
|
||||
@@ -28,7 +28,7 @@ class CommentAPITestCase(
|
||||
)
|
||||
|
||||
def test_comment_create_view_no_access(self):
|
||||
response = self._request_comment_create_view()
|
||||
response = self._request_test_comment_create_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
self.assertEqual(Comment.objects.count(), 0)
|
||||
@@ -38,14 +38,14 @@ class CommentAPITestCase(
|
||||
obj=self.test_document, permission=permission_document_comment_create
|
||||
)
|
||||
|
||||
response = self._request_comment_create_view()
|
||||
response = self._request_test_comment_create_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
comment = Comment.objects.first()
|
||||
self.assertEqual(Comment.objects.count(), 1)
|
||||
self.assertEqual(response.data['id'], comment.pk)
|
||||
|
||||
def _request_comment_delete_view(self):
|
||||
def _request_test_comment_delete_api_view(self):
|
||||
return self.delete(
|
||||
viewname='rest_api:comment-detail', kwargs={
|
||||
'document_pk': self.test_document.pk,
|
||||
@@ -56,7 +56,7 @@ class CommentAPITestCase(
|
||||
def test_comment_delete_view_no_access(self):
|
||||
self._create_test_comment()
|
||||
|
||||
response = self._request_comment_delete_view()
|
||||
response = self._request_test_comment_delete_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
self.assertTrue(self.test_document_comment in Comment.objects.all())
|
||||
@@ -67,12 +67,43 @@ class CommentAPITestCase(
|
||||
obj=self.test_document, permission=permission_document_comment_delete
|
||||
)
|
||||
|
||||
response = self._request_comment_delete_view()
|
||||
response = self._request_test_comment_delete_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
|
||||
|
||||
self.assertFalse(self.test_document_comment in Comment.objects.all())
|
||||
|
||||
def _request_comment_view(self):
|
||||
def _request_comment_edit_patch_api_view(self):
|
||||
return self.patch(
|
||||
viewname='rest_api:comment-detail', kwargs={
|
||||
'document_pk': self.test_document.pk,
|
||||
'comment_pk': self.test_document_comment.pk,
|
||||
}, data={'comment': TEST_COMMENT_TEXT_EDITED}
|
||||
)
|
||||
|
||||
def test_comment_edit_view_no_access(self):
|
||||
self._create_test_comment()
|
||||
comment_text = self.test_document_comment.comment
|
||||
|
||||
response = self._request_comment_edit_patch_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
self.test_document_comment.refresh_from_db()
|
||||
self.assertEqual(self.test_document_comment.comment, comment_text)
|
||||
|
||||
def test_comment_edit_view_with_access(self):
|
||||
self._create_test_comment()
|
||||
self.grant_access(
|
||||
obj=self.test_document, permission=permission_document_comment_edit
|
||||
)
|
||||
comment_text = self.test_document_comment.comment
|
||||
|
||||
response = self._request_comment_edit_patch_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
self.test_document_comment.refresh_from_db()
|
||||
self.assertNotEqual(self.test_document_comment.comment, comment_text)
|
||||
|
||||
def _request_test_comment_api_view(self):
|
||||
return self.get(
|
||||
viewname='rest_api:comment-detail', kwargs={
|
||||
'document_pk': self.test_document.pk,
|
||||
@@ -83,7 +114,7 @@ class CommentAPITestCase(
|
||||
def test_comment_detail_view_no_access(self):
|
||||
self._create_test_comment()
|
||||
|
||||
response = self._request_comment_view()
|
||||
response = self._request_test_comment_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def test_comment_detail_view_with_access(self):
|
||||
@@ -92,12 +123,12 @@ class CommentAPITestCase(
|
||||
obj=self.test_document, permission=permission_document_comment_view
|
||||
)
|
||||
|
||||
response = self._request_comment_view()
|
||||
response = self._request_test_comment_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
self.assertEqual(response.data['comment'], self.test_document_comment.comment)
|
||||
|
||||
def _request_comment_list_view(self):
|
||||
def _request_test_comment_list_api_view(self):
|
||||
return self.get(
|
||||
viewname='rest_api:comment-list', kwargs={
|
||||
'document_pk': self.test_document.pk
|
||||
@@ -107,7 +138,7 @@ class CommentAPITestCase(
|
||||
def test_comment_list_view_no_access(self):
|
||||
self._create_test_comment()
|
||||
|
||||
response = self._request_comment_list_view()
|
||||
response = self._request_test_comment_list_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def test_comment_list_view_with_access(self):
|
||||
@@ -116,7 +147,7 @@ class CommentAPITestCase(
|
||||
obj=self.test_document, permission=permission_document_comment_view
|
||||
)
|
||||
|
||||
response = self._request_comment_list_view()
|
||||
response = self._request_test_comment_list_api_view()
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(
|
||||
response.data['results'][0]['comment'], self.test_document_comment.comment
|
||||
|
||||
Reference in New Issue
Block a user