Update index document types view to AddRemoveView

Add index create and edit events.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-27 23:01:46 -04:00
parent 8374a66011
commit dda0f0d2af
12 changed files with 196 additions and 87 deletions

View File

@@ -2,10 +2,12 @@ from __future__ import unicode_literals
from ..models import Index
from .literals import TEST_INDEX_LABEL
from .literals import (
TEST_INDEX_LABEL, TEST_INDEX_LABEL_EDITED, TEST_INDEX_SLUG
)
class DocumentIndexingTestMixin(object):
class IndexTestMixin(object):
def _create_test_index(self, rebuild=False):
# Create empty index
self.test_index = Index.objects.create(label=TEST_INDEX_LABEL)
@@ -16,3 +18,35 @@ class DocumentIndexingTestMixin(object):
# Rebuild indexes
if rebuild:
Index.objects.rebuild()
class IndexViewTestMixin(object):
def _request_test_index_create_view(self):
# Typecast to list to force queryset evaluation
values = list(Index.objects.values_list('pk', flat=True))
response = self.post(
viewname='indexing:index_setup_create', data={
'label': TEST_INDEX_LABEL, 'slug': TEST_INDEX_SLUG
}
)
self.test_index = Index.objects.exclude(pk__in=values).first()
return response
def _request_test_index_delete_view(self):
return self.post(
viewname='indexing:index_setup_delete', kwargs={
'pk': self.test_index.pk
}
)
def _request_test_index_edit_view(self):
return self.post(
viewname='indexing:index_setup_edit', kwargs={
'pk': self.test_index.pk
}, data={
'label': TEST_INDEX_LABEL_EDITED, 'slug': TEST_INDEX_SLUG
}
)

View File

@@ -12,10 +12,10 @@ from ..permissions import (
)
from .literals import TEST_INDEX_LABEL, TEST_INDEX_SLUG
from .mixins import DocumentIndexingTestMixin
from .mixins import IndexTestMixin
class DocumentIndexingAPITestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseAPITestCase):
class DocumentIndexingAPITestCase(IndexTestMixin, DocumentTestMixin, BaseAPITestCase):
auto_upload_document = False
def _request_index_create_api_view(self):

View File

@@ -0,0 +1,47 @@
from __future__ import unicode_literals
from actstream.models import Action
from mayan.apps.common.tests import GenericViewTestCase
from mayan.apps.documents.tests import DocumentTestMixin
from ..permissions import (
permission_document_indexing_create, permission_document_indexing_edit,
)
from ..events import event_index_template_created, event_index_template_edited
from .mixins import IndexTestMixin, IndexViewTestMixin
class IndexTemplateEventsTestCase(DocumentTestMixin, IndexTestMixin, IndexViewTestMixin, GenericViewTestCase):
auto_upload_document = False
def test_index_template_create_event(self):
Action.objects.all().delete()
self.grant_permission(
permission=permission_document_indexing_create
)
self._request_test_index_create_view()
self.assertEqual(Action.objects.last().actor, self._test_case_user)
self.assertEqual(Action.objects.last().target, self.test_index)
self.assertEqual(
Action.objects.last().verb, event_index_template_created.id
)
def test_index_template_edit_event(self):
self._create_test_index()
self.grant_access(
obj=self.test_index, permission=permission_document_indexing_edit
)
Action.objects.all().delete()
self._request_test_index_edit_view()
self.assertEqual(Action.objects.last().target, self.test_index)
self.assertEqual(
Action.objects.last().verb, event_index_template_edited.id
)

View File

@@ -20,10 +20,10 @@ from .literals import (
TEST_INDEX_TEMPLATE_METADATA_EXPRESSION, TEST_METADATA_TYPE_LABEL,
TEST_METADATA_TYPE_NAME
)
from .mixins import DocumentIndexingTestMixin
from .mixins import IndexTestMixin
class IndexTestCase(DocumentIndexingTestMixin, DocumentTestMixin, BaseTestCase):
class IndexTestCase(IndexTestMixin, DocumentTestMixin, BaseTestCase):
def test_document_description_index(self):
self._create_test_index()

View File

@@ -10,22 +10,13 @@ from ..permissions import (
permission_document_indexing_rebuild
)
from .literals import (
TEST_INDEX_LABEL, TEST_INDEX_LABEL_EDITED, TEST_INDEX_SLUG
)
from .mixins import DocumentIndexingTestMixin
from .literals import TEST_INDEX_LABEL, TEST_INDEX_LABEL_EDITED
from .mixins import IndexTestMixin, IndexViewTestMixin
class IndexViewTestCase(DocumentIndexingTestMixin, GenericDocumentViewTestCase):
def _request_index_create_view(self):
return self.post(
viewname='indexing:index_setup_create', data={
'label': TEST_INDEX_LABEL, 'slug': TEST_INDEX_SLUG
}
)
class IndexViewTestCase(IndexTestMixin, IndexViewTestMixin, GenericDocumentViewTestCase):
def test_index_create_view_no_permission(self):
response = self._request_index_create_view()
response = self._request_test_index_create_view()
self.assertEquals(response.status_code, 403)
self.assertEqual(Index.objects.count(), 0)
@@ -35,23 +26,16 @@ class IndexViewTestCase(DocumentIndexingTestMixin, GenericDocumentViewTestCase):
permission=permission_document_indexing_create
)
response = self._request_index_create_view()
response = self._request_test_index_create_view()
self.assertEqual(response.status_code, 302)
self.assertEqual(Index.objects.count(), 1)
self.assertEqual(Index.objects.first().label, TEST_INDEX_LABEL)
def _request_index_delete_view(self):
return self.post(
viewname='indexing:index_setup_delete', kwargs={
'pk': self.test_index.pk
}
)
def test_index_delete_view_no_permission(self):
self._create_test_index()
response = self._request_index_delete_view()
response = self._request_test_index_delete_view()
self.assertEqual(response.status_code, 403)
self.assertEqual(Index.objects.count(), 1)
@@ -61,24 +45,15 @@ class IndexViewTestCase(DocumentIndexingTestMixin, GenericDocumentViewTestCase):
self.grant_permission(permission=permission_document_indexing_delete)
response = self._request_index_delete_view()
response = self._request_test_index_delete_view()
self.assertEqual(response.status_code, 302)
self.assertEqual(Index.objects.count(), 0)
def _request_index_edit_view(self):
return self.post(
viewname='indexing:index_setup_edit', kwargs={
'pk': self.test_index.pk
}, data={
'label': TEST_INDEX_LABEL_EDITED, 'slug': TEST_INDEX_SLUG
}
)
def test_index_edit_view_no_permission(self):
self._create_test_index()
response = self._request_index_edit_view()
response = self._request_test_index_edit_view()
self.assertEqual(response.status_code, 403)
self.test_index.refresh_from_db()
@@ -91,7 +66,7 @@ class IndexViewTestCase(DocumentIndexingTestMixin, GenericDocumentViewTestCase):
obj=self.test_index, permission=permission_document_indexing_edit
)
response = self._request_index_edit_view()
response = self._request_test_index_edit_view()
self.assertEqual(response.status_code, 302)
self.test_index.refresh_from_db()