diff --git a/mayan/apps/documents/tests/literals.py b/mayan/apps/documents/tests/literals.py index 12e1b85686..4e89bd23fd 100644 --- a/mayan/apps/documents/tests/literals.py +++ b/mayan/apps/documents/tests/literals.py @@ -6,6 +6,7 @@ import os from django.conf import settings from mayan.apps.common.literals import TIME_DELTA_UNIT_DAYS +from mayan.apps.converter.transformations import TransformationRotate __all__ = ( 'TEST_COMPRESSED_DOCUMENTS_FILENAME', 'TEST_COMPRESSED_DOCUMENT_PATH', @@ -49,6 +50,7 @@ TEST_SMALL_DOCUMENT_CHECKSUM = 'efa10e6cc21f83078aaa94d5cbe51de67b51af706143b\ afc7fd6d4c02124879a' TEST_SMALL_DOCUMENT_MIMETYPE = 'image/png' TEST_SMALL_DOCUMENT_SIZE = 17436 +TEST_TRANSFORMATION_CLASS = TransformationRotate TEST_TRANSFORMATION_NAME = 'rotate' TEST_TRANSFORMATION_ARGUMENT = 'degrees: 180' diff --git a/mayan/apps/documents/tests/test_api.py b/mayan/apps/documents/tests/test_api.py index 2a16ea74ae..217907c19b 100644 --- a/mayan/apps/documents/tests/test_api.py +++ b/mayan/apps/documents/tests/test_api.py @@ -7,6 +7,7 @@ from django.utils.encoding import force_text from django_downloadview import assert_download_response from rest_framework import status +from mayan.apps.converter.tests.mixins import LayerTestMixin from mayan.apps.rest_api.tests import BaseAPITestCase from ..models import Document, DocumentType @@ -29,7 +30,7 @@ from .literals import ( from .mixins import DocumentTestMixin -class DocumentTypeAPITestCase(DocumentTestMixin, BaseAPITestCase): +class DocumentTypeAPITestCase(LayerTestMixin, DocumentTestMixin, BaseAPITestCase): auto_upload_document = False auto_create_document_type = False diff --git a/mayan/apps/documents/tests/test_document_views.py b/mayan/apps/documents/tests/test_document_views.py index bd57dc905e..367b2e0728 100644 --- a/mayan/apps/documents/tests/test_document_views.py +++ b/mayan/apps/documents/tests/test_document_views.py @@ -1,10 +1,10 @@ from __future__ import unicode_literals -from django.contrib.contenttypes.models import ContentType from django.utils.encoding import force_text -from mayan.apps.converter.models import Transformation +from mayan.apps.converter.layers import layer_saved_transformations from mayan.apps.converter.permissions import permission_transformation_delete +from mayan.apps.converter.tests.mixins import LayerTestMixin from ..models import DeletedDocument, Document, DocumentType from ..permissions import ( @@ -17,12 +17,14 @@ from ..permissions import ( from .base import GenericDocumentViewTestCase from .literals import ( TEST_DOCUMENT_TYPE_2_LABEL, TEST_SMALL_DOCUMENT_FILENAME, - TEST_TRANSFORMATION_ARGUMENT, TEST_TRANSFORMATION_NAME, + TEST_TRANSFORMATION_ARGUMENT, TEST_TRANSFORMATION_CLASS ) from .mixins import DocumentViewTestMixin -class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase): +class DocumentsViewsTestCase( + LayerTestMixin, DocumentViewTestMixin, GenericDocumentViewTestCase +): def test_document_view_no_permissions(self): response = self._request_document_properties_view() self.assertEqual(response.status_code, 404) @@ -327,19 +329,19 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) self.assertEqual(self.test_document.pages.count(), page_count) - def test_document_clear_transformations_view_no_permission(self): - document_page = self.test_document.pages.first() - content_type = ContentType.objects.get_for_model(model=document_page) - transformation = Transformation.objects.create( - content_type=content_type, object_id=document_page.pk, - name=TEST_TRANSFORMATION_NAME, + def _create_document_transformation(self): + layer_saved_transformations.add_transformation_to( + obj=self.test_document.pages.first(), + transformation_class=TEST_TRANSFORMATION_CLASS, arguments=TEST_TRANSFORMATION_ARGUMENT ) - self.assertQuerysetEqual( - Transformation.objects.get_for_object(obj=document_page), - (repr(transformation),) - ) + def test_document_clear_transformations_view_no_permission(self): + self._create_document_transformation() + + transformation_count = layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() self.grant_access( obj=self.test_document, permission=permission_document_view @@ -348,26 +350,23 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) response = self._request_document_clear_transformations_view() self.assertEqual(response.status_code, 404) - self.assertQuerysetEqual( - Transformation.objects.get_for_object(obj=document_page), - (repr(transformation),) + self.assertEqual( + transformation_count, + layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() ) def test_document_clear_transformations_view_with_access(self): - document_page = self.test_document.pages.first() - content_type = ContentType.objects.get_for_model(model=document_page) - transformation = Transformation.objects.create( - content_type=content_type, object_id=document_page.pk, - name=TEST_TRANSFORMATION_NAME, - arguments=TEST_TRANSFORMATION_ARGUMENT - ) - self.assertQuerysetEqual( - Transformation.objects.get_for_object(obj=document_page), - (repr(transformation),) - ) + self._create_document_transformation() + + transformation_count = layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() self.grant_access( - obj=self.test_document, permission=permission_transformation_delete + obj=self.test_document, + permission=permission_transformation_delete ) self.grant_access( obj=self.test_document, permission=permission_document_view @@ -377,45 +376,39 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) self.assertEqual(response.status_code, 302) self.assertEqual( - Transformation.objects.get_for_object(obj=document_page).count(), 0 + transformation_count - 1, + layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() ) def test_document_multiple_clear_transformations_view_no_permission(self): - document_page = self.test_document.pages.first() - content_type = ContentType.objects.get_for_model(model=document_page) - transformation = Transformation.objects.create( - content_type=content_type, object_id=document_page.pk, - name=TEST_TRANSFORMATION_NAME, - arguments=TEST_TRANSFORMATION_ARGUMENT - ) + self._create_document_transformation() - self.assertQuerysetEqual( - Transformation.objects.get_for_object(obj=document_page), - (repr(transformation),) - ) + transformation_count = layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() - self.grant_permission(permission=permission_document_view) + self.grant_access( + obj=self.test_document, permission=permission_document_view + ) response = self._request_document_multiple_clear_transformations() self.assertEqual(response.status_code, 404) - self.assertQuerysetEqual( - Transformation.objects.get_for_object(obj=document_page), - (repr(transformation),) + + self.assertEqual( + transformation_count, + layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() ) def test_document_multiple_clear_transformations_view_with_access(self): - document_page = self.test_document.pages.first() - content_type = ContentType.objects.get_for_model(model=document_page) - transformation = Transformation.objects.create( - content_type=content_type, object_id=document_page.pk, - name=TEST_TRANSFORMATION_NAME, - arguments=TEST_TRANSFORMATION_ARGUMENT - ) + self._create_document_transformation() - self.assertQuerysetEqual( - Transformation.objects.get_for_object(obj=document_page), - (repr(transformation),) - ) + transformation_count = layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() self.grant_access( obj=self.test_document, permission=permission_document_view @@ -428,7 +421,10 @@ class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase) self.assertEqual(response.status_code, 302) self.assertEqual( - Transformation.objects.get_for_object(obj=document_page).count(), 0 + transformation_count - 1, + layer_saved_transformations.get_transformations_for( + obj=self.test_document.pages.first() + ).count() ) def test_trash_can_empty_view_no_permission(self):