From e228dfc8c55a4226085a111dbf77406d70f861ac Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 27 May 2016 18:01:31 -0400 Subject: [PATCH] Add initial organization view tests for the documents app. --- mayan/apps/documents/tests/literals.py | 5 ++ .../tests/test_organization_views.py | 62 +++++++++++++++++++ mayan/apps/documents/tests/test_views.py | 12 ++-- 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 mayan/apps/documents/tests/test_organization_views.py diff --git a/mayan/apps/documents/tests/literals.py b/mayan/apps/documents/tests/literals.py index 4956dbbee1..a69b96bfec 100644 --- a/mayan/apps/documents/tests/literals.py +++ b/mayan/apps/documents/tests/literals.py @@ -21,10 +21,13 @@ __all__ = ( # Filenames TEST_COMPRESSED_DOCUMENTS_FILENAME = 'compressed_documents.zip' TEST_DEU_DOCUMENT_FILENAME = 'deu_website.png' + TEST_DOCUMENT_DESCRIPTION = 'test description' TEST_DOCUMENT_FILENAME = 'mayan_11_1.pdf' TEST_DOCUMENT_TYPE = 'test_document_type' TEST_DOCUMENT_TYPE_2 = 'test document type 2' +TEST_DOCUMENT_TYPE_EDITED_LABEL = 'test document type edited label' +TEST_DOCUMENT_TYPE_2_LABEL = 'test document type 2 label' TEST_HYBRID_DOCUMENT = 'hybrid_text_and_image.pdf' TEST_MULTI_PAGE_TIFF = 'multi_page.tiff' TEST_NON_ASCII_COMPRESSED_DOCUMENT_FILENAME = 'I18N_title_áéíóúüñÑ.png.zip' @@ -70,3 +73,5 @@ TEST_SMALL_DOCUMENT_PATH = os.path.join( settings.BASE_DIR, 'contrib', 'sample_documents', TEST_SMALL_DOCUMENT_FILENAME ) +TEST_TRANSFORMATION_NAME = 'rotate' +TEST_TRANSFORMATION_ARGUMENT = 'degrees: 180' diff --git a/mayan/apps/documents/tests/test_organization_views.py b/mayan/apps/documents/tests/test_organization_views.py new file mode 100644 index 0000000000..2baced6680 --- /dev/null +++ b/mayan/apps/documents/tests/test_organization_views.py @@ -0,0 +1,62 @@ +from __future__ import unicode_literals + +from organizations.tests.test_organization_views import OrganizationViewTestCase + +from ..models import Document,DocumentType + +from .literals import ( + TEST_DOCUMENT_TYPE, TEST_DOCUMENT_TYPE_2_LABEL, + TEST_DOCUMENT_TYPE_QUICK_LABEL, TEST_SMALL_DOCUMENT_CHECKSUM, + TEST_SMALL_DOCUMENT_PATH +) + + +class DocumentOrganizationViewTestCase(OrganizationViewTestCase): + def setUp(self): + super(DocumentOrganizationViewTestCase, self).setUp() + + # Create a document for organization A + with self.settings(ORGANIZATION_ID=self.organization_a.pk): + self.document_type = DocumentType.on_organization.create( + label=TEST_DOCUMENT_TYPE + ) + + with open(TEST_SMALL_DOCUMENT_PATH) as file_object: + self.document = self.document_type.new_document( + file_object=file_object + ) + + def tearDown(self): + super(DocumentOrganizationViewTestCase, self).tearDown() + if self.document_type.pk: + self.document_type.delete() + + def test_document_delete_view(self): + with self.settings(ORGANIZATION_ID=self.organization_b.pk): + response = self.post( + 'documents:document_delete', args=(self.document.pk,) + ) + self.assertEqual(response.status_code, 404) + + def test_document_view_view(self): + with self.settings(ORGANIZATION_ID=self.organization_b.pk): + # Make sure admin for organization B cannot find the document for + # organization A + response = self.get( + 'documents:document_properties', args=(self.document.pk,), + ) + self.assertEqual(response.status_code, 404) + + def test_document_document_type_change_view(self): + with self.settings(ORGANIZATION_ID=self.organization_b.pk): + document_type = DocumentType.objects.create( + label=TEST_DOCUMENT_TYPE_2_LABEL + ) + + response = self.post( + 'documents:document_document_type_edit', + args=(self.document.pk,), + data={'document_type': document_type.pk} + ) + + self.assertEqual(response.status_code, 403) diff --git a/mayan/apps/documents/tests/test_views.py b/mayan/apps/documents/tests/test_views.py index d952db9aab..9b80054c8d 100644 --- a/mayan/apps/documents/tests/test_views.py +++ b/mayan/apps/documents/tests/test_views.py @@ -28,17 +28,13 @@ from ..permissions import ( ) from .literals import ( - TEST_DOCUMENT_TYPE, TEST_DOCUMENT_TYPE_QUICK_LABEL, - TEST_SMALL_DOCUMENT_CHECKSUM, TEST_SMALL_DOCUMENT_PATH + TEST_DOCUMENT_TYPE, TEST_DOCUMENT_TYPE_EDITED_LABEL, + TEST_DOCUMENT_TYPE_2_LABEL, TEST_DOCUMENT_TYPE_QUICK_LABEL, + TEST_SMALL_DOCUMENT_CHECKSUM, TEST_SMALL_DOCUMENT_PATH, + TEST_TRANSFORMATION_ARGUMENT, TEST_TRANSFORMATION_NAME ) -TEST_DOCUMENT_TYPE_EDITED_LABEL = 'test document type edited label' -TEST_DOCUMENT_TYPE_2_LABEL = 'test document type 2 label' -TEST_TRANSFORMATION_NAME = 'rotate' -TEST_TRANSFORMATION_ARGUMENT = 'degrees: 180' - - @override_settings(OCR_AUTO_OCR=False) class GenericDocumentViewTestCase(GenericViewTestCase): def setUp(self):