Don't cache the entire converter class to lower memory usage. Instead a get_converter_class() function is now provided to load the converter backend class. Add model permission inheritance to transformations to removel custom permission checking code in the views. User keyword arguments. Update URL parameters to the '_id' form. Add missing edit and delete icons. Improve the create icon using composition. Update add to comply with MERCs 5 and 6. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
132 lines
4.5 KiB
Python
132 lines
4.5 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
from mayan.apps.documents.tests import GenericDocumentViewTestCase
|
|
|
|
from ..models import Transformation
|
|
from ..permissions import (
|
|
permission_transformation_create, permission_transformation_delete,
|
|
permission_transformation_edit, permission_transformation_view
|
|
)
|
|
|
|
from .literals import (
|
|
TEST_TRANSFORMATION_NAME, TEST_TRANSFORMATION_ARGUMENT,
|
|
TEST_TRANSFORMATION_ARGUMENT_EDITED
|
|
)
|
|
|
|
|
|
class TransformationViewsTestCase(GenericDocumentViewTestCase):
|
|
def _transformation_create_view(self):
|
|
return self.post(
|
|
viewname='converter:transformation_create', kwargs={
|
|
'app_label': 'documents', 'model': 'document',
|
|
'object_id': self.document.pk
|
|
}, data={
|
|
'name': TEST_TRANSFORMATION_NAME,
|
|
'arguments': TEST_TRANSFORMATION_ARGUMENT
|
|
}
|
|
)
|
|
|
|
def test_transformation_create_view_no_permissions(self):
|
|
response = self._transformation_create_view()
|
|
|
|
self.assertEqual(response.status_code, 404)
|
|
self.assertEqual(Transformation.objects.count(), 0)
|
|
|
|
def test_transformation_create_view_with_access(self):
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_transformation_create
|
|
)
|
|
response = self._transformation_create_view()
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
self.assertEqual(Transformation.objects.count(), 1)
|
|
|
|
def _create_transformation(self):
|
|
content_type = ContentType.objects.get_for_model(model=self.document)
|
|
|
|
self.transformation = Transformation.objects.create(
|
|
content_type=content_type, object_id=self.document.pk,
|
|
name=TEST_TRANSFORMATION_NAME,
|
|
arguments=TEST_TRANSFORMATION_ARGUMENT
|
|
)
|
|
|
|
def _transformation_delete_view(self):
|
|
return self.post(
|
|
viewname='converter:transformation_delete', kwargs={
|
|
'transformation_id': self.transformation.pk
|
|
}
|
|
)
|
|
|
|
def test_transformation_delete_view_no_permissions(self):
|
|
self._create_transformation()
|
|
response = self._transformation_delete_view()
|
|
|
|
self.assertEqual(response.status_code, 404)
|
|
self.assertEqual(Transformation.objects.count(), 1)
|
|
|
|
def test_transformation_delete_view_with_access(self):
|
|
self._create_transformation()
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_transformation_delete
|
|
)
|
|
response = self._transformation_delete_view()
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
self.assertEqual(Transformation.objects.count(), 0)
|
|
|
|
def _transformation_edit_view(self):
|
|
return self.post(
|
|
viewname='converter:transformation_edit', kwargs={
|
|
'transformation_id': self.transformation.pk
|
|
}, data={
|
|
'arguments': TEST_TRANSFORMATION_ARGUMENT_EDITED,
|
|
'name': self.transformation.name
|
|
}
|
|
)
|
|
|
|
def test_transformation_edit_view_no_permission(self):
|
|
self._create_transformation()
|
|
response = self._transformation_edit_view()
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
self.transformation.refresh_from_db()
|
|
self.assertNotEqual(
|
|
self.transformation.arguments, TEST_TRANSFORMATION_ARGUMENT_EDITED
|
|
)
|
|
|
|
def test_transformation_edit_view_with_access(self):
|
|
self._create_transformation()
|
|
self.grant_access(
|
|
obj=self.document, permission=permission_transformation_edit
|
|
)
|
|
response = self._transformation_edit_view()
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.transformation.refresh_from_db()
|
|
self.assertEqual(
|
|
self.transformation.arguments, TEST_TRANSFORMATION_ARGUMENT_EDITED
|
|
)
|
|
|
|
def _transformation_list_view(self):
|
|
return self.get(
|
|
viewname='converter:transformation_list', kwargs={
|
|
'app_label': 'documents', 'model': 'document',
|
|
'object_id': self.document.pk
|
|
}
|
|
)
|
|
|
|
def test_transformation_list_view_no_permissions(self):
|
|
response = self._transformation_list_view()
|
|
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
def test_transformation_list_view_with_permissions(self):
|
|
self.grant_permission(permission=permission_transformation_view)
|
|
response = self._transformation_list_view()
|
|
|
|
self.assertContains(
|
|
response, text=self.document.label, status_code=200
|
|
)
|