Move quick label tests to the document type module
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import os
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from ..literals import PAGE_RANGE_ALL
|
||||
from ..models import DocumentType
|
||||
|
||||
from .literals import (
|
||||
@@ -141,3 +142,94 @@ class DocumentVersionTestMixin(object):
|
||||
self.test_document.new_version(
|
||||
comment=TEST_VERSION_COMMENT, file_object=file_object
|
||||
)
|
||||
|
||||
|
||||
class DocumentViewTestMixin(object):
|
||||
def _request_document_properties_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_properties',
|
||||
kwargs={'pk': self.test_document.pk}
|
||||
)
|
||||
|
||||
def _request_test_document_list_view(self):
|
||||
return self.get(viewname='documents:document_list')
|
||||
|
||||
def _request_test_document_type_edit_view(self, document_type):
|
||||
return self.post(
|
||||
viewname='documents:document_document_type_edit',
|
||||
kwargs={'pk': self.test_document.pk},
|
||||
data={'document_type': document_type.pk}
|
||||
)
|
||||
|
||||
def _request_multiple_document_type_edit(self, document_type):
|
||||
return self.post(
|
||||
viewname='documents:document_multiple_document_type_edit',
|
||||
data={
|
||||
'id_list': self.test_document.pk,
|
||||
'document_type': document_type.pk
|
||||
}
|
||||
)
|
||||
|
||||
def _request_document_download_form_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_download_form', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}
|
||||
)
|
||||
|
||||
def _request_document_download_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_download', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}
|
||||
)
|
||||
|
||||
def _request_document_multiple_download_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_multiple_download',
|
||||
data={'id_list': self.test_document.pk}
|
||||
)
|
||||
|
||||
def _request_document_version_download(self, data=None):
|
||||
data = data or {}
|
||||
return self.get(
|
||||
viewname='documents:document_version_download', kwargs={
|
||||
'pk': self.test_document.latest_version.pk
|
||||
}, data=data
|
||||
)
|
||||
|
||||
def _request_document_update_page_count_view(self):
|
||||
return self.post(
|
||||
viewname='documents:document_update_page_count',
|
||||
kwargs={'pk': self.test_document.pk}
|
||||
)
|
||||
|
||||
def _request_document_multiple_update_page_count_view(self):
|
||||
return self.post(
|
||||
viewname='documents:document_multiple_update_page_count',
|
||||
data={'id_list': self.test_document.pk}
|
||||
)
|
||||
|
||||
def _request_document_clear_transformations_view(self):
|
||||
return self.post(
|
||||
viewname='documents:document_clear_transformations',
|
||||
kwargs={'pk': self.test_document.pk}
|
||||
)
|
||||
|
||||
def _request_document_multiple_clear_transformations(self):
|
||||
return self.post(
|
||||
viewname='documents:document_multiple_clear_transformations',
|
||||
data={'id_list': self.test_document.pk}
|
||||
)
|
||||
|
||||
def _request_empty_trash_view(self):
|
||||
return self.post(viewname='documents:trash_can_empty')
|
||||
|
||||
def _request_document_print_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_print', kwargs={
|
||||
'pk': self.test_document.pk,
|
||||
}, data={
|
||||
'page_group': PAGE_RANGE_ALL
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from ..models import DocumentType
|
||||
from ..permissions import (
|
||||
permission_document_properties_edit,
|
||||
permission_document_type_create, permission_document_type_delete,
|
||||
permission_document_type_edit, permission_document_type_view,
|
||||
)
|
||||
@@ -198,3 +201,78 @@ class DocumentTypeQuickLabelViewsTestCase(
|
||||
self.assertContains(
|
||||
response, text=self.test_document_type_filename, status_code=200
|
||||
)
|
||||
|
||||
|
||||
class DocumentsQuickLabelViewsTestCase(DocumentTypeQuickLabelTestMixin, GenericDocumentViewTestCase):
|
||||
def _request_document_quick_label_edit_view(self, extra_data=None):
|
||||
data = {
|
||||
'document_type_available_filenames': self.test_document_type_filename.pk,
|
||||
'label': ''
|
||||
# View needs at least an empty label for quick
|
||||
# label to work. Cause is unknown.
|
||||
}
|
||||
data.update(extra_data or {})
|
||||
|
||||
return self.post(
|
||||
viewname='documents:document_edit', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}, data=data
|
||||
)
|
||||
|
||||
def test_document_quick_label_no_permission(self):
|
||||
self._create_test_quick_label()
|
||||
|
||||
response = self._request_document_quick_label_edit_view()
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_document_quick_label_with_access(self):
|
||||
self._create_test_quick_label()
|
||||
self.grant_access(
|
||||
obj=self.test_document,
|
||||
permission=permission_document_properties_edit
|
||||
)
|
||||
|
||||
response = self._request_document_quick_label_edit_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.test_document.refresh_from_db()
|
||||
self.assertEqual(
|
||||
self.test_document.label, self.test_document_type_filename.filename
|
||||
)
|
||||
|
||||
def test_document_quick_label_preserve_extension_with_access(self):
|
||||
self._create_test_quick_label()
|
||||
self.grant_access(
|
||||
permission=permission_document_properties_edit, obj=self.test_document
|
||||
)
|
||||
filename, extension = os.path.splitext(self.test_document.label)
|
||||
|
||||
response = self._request_document_quick_label_edit_view(
|
||||
extra_data={'preserve_extension': True}
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.test_document.refresh_from_db()
|
||||
self.assertEqual(
|
||||
self.test_document.label, '{}{}'.format(
|
||||
self.test_document_type_filename.filename, extension
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_quick_label_no_preserve_extension_with_access(self):
|
||||
self._create_test_quick_label()
|
||||
self.grant_access(
|
||||
obj=self.test_document,
|
||||
permission=permission_document_properties_edit
|
||||
)
|
||||
filename, extension = os.path.splitext(self.test_document.label)
|
||||
|
||||
response = self._request_document_quick_label_edit_view(
|
||||
extra_data={'preserve_extension': False}
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.test_document.refresh_from_db()
|
||||
self.assertEqual(
|
||||
self.test_document.label, self.test_document_type_filename.filename
|
||||
)
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
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.permissions import permission_transformation_delete
|
||||
|
||||
from ..literals import PAGE_RANGE_ALL
|
||||
from ..models import DeletedDocument, Document, DocumentType
|
||||
from ..permissions import (
|
||||
permission_document_create, permission_document_download,
|
||||
@@ -22,16 +19,10 @@ from .literals import (
|
||||
TEST_DOCUMENT_TYPE_2_LABEL, TEST_SMALL_DOCUMENT_FILENAME,
|
||||
TEST_TRANSFORMATION_ARGUMENT, TEST_TRANSFORMATION_NAME,
|
||||
)
|
||||
from .mixins import DocumentTypeQuickLabelTestMixin
|
||||
from .mixins import DocumentViewTestMixin
|
||||
|
||||
|
||||
class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
def _request_document_properties_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_properties',
|
||||
kwargs={'pk': self.test_document.pk}
|
||||
)
|
||||
|
||||
class DocumentsViewsTestCase(DocumentViewTestMixin, GenericDocumentViewTestCase):
|
||||
def test_document_view_no_permissions(self):
|
||||
response = self._request_document_properties_view()
|
||||
self.assertEqual(response.status_code, 404)
|
||||
@@ -46,11 +37,8 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
response=response, text=self.test_document.label, status_code=200
|
||||
)
|
||||
|
||||
def _request_document_list_view(self):
|
||||
return self.get(viewname='documents:document_list')
|
||||
|
||||
def test_document_list_view_no_permissions(self):
|
||||
response = self._request_document_list_view()
|
||||
response = self._request_test_document_list_view()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
self.assertEqual(response.context['object_list'].count(), 0)
|
||||
@@ -60,18 +48,11 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
obj=self.test_document, permission=permission_document_view
|
||||
)
|
||||
|
||||
response = self._request_document_list_view()
|
||||
response = self._request_test_document_list_view()
|
||||
self.assertContains(
|
||||
response=response, text=self.test_document.label, status_code=200
|
||||
)
|
||||
|
||||
def _request_test_document_type_edit_view(self, document_type):
|
||||
return self.post(
|
||||
viewname='documents:document_document_type_edit',
|
||||
kwargs={'pk': self.test_document.pk},
|
||||
data={'document_type': document_type.pk}
|
||||
)
|
||||
|
||||
def test_document_document_type_change_view_no_permissions(self):
|
||||
self.assertEqual(
|
||||
self.test_document.document_type, self.test_document_type
|
||||
@@ -117,15 +98,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
document_type_2
|
||||
)
|
||||
|
||||
def _request_multiple_document_type_edit(self, document_type):
|
||||
return self.post(
|
||||
viewname='documents:document_multiple_document_type_edit',
|
||||
data={
|
||||
'id_list': self.test_document.pk,
|
||||
'document_type': document_type.pk
|
||||
}
|
||||
)
|
||||
|
||||
def test_document_multiple_document_type_change_view_no_permission(self):
|
||||
self.assertEqual(
|
||||
Document.objects.first().document_type, self.test_document_type
|
||||
@@ -170,13 +142,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
Document.objects.first().document_type, document_type_2
|
||||
)
|
||||
|
||||
def _request_document_download_form_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_download_form', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}
|
||||
)
|
||||
|
||||
def test_document_download_form_view_no_permission(self):
|
||||
response = self._request_document_download_form_view()
|
||||
self.assertNotContains(
|
||||
@@ -193,13 +158,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
response=response, text=self.test_document.label, status_code=200
|
||||
)
|
||||
|
||||
def _request_document_download_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_download', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}
|
||||
)
|
||||
|
||||
def test_document_download_view_no_permission(self):
|
||||
response = self._request_document_download_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
@@ -225,12 +183,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
mime_type=self.test_document.file_mimetype
|
||||
)
|
||||
|
||||
def _request_document_multiple_download_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_multiple_download',
|
||||
data={'id_list': self.test_document.pk}
|
||||
)
|
||||
|
||||
def test_document_multiple_download_view_no_permission(self):
|
||||
response = self._request_document_multiple_download_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
@@ -255,14 +207,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
mime_type=self.test_document.file_mimetype
|
||||
)
|
||||
|
||||
def _request_document_version_download(self, data=None):
|
||||
data = data or {}
|
||||
return self.get(
|
||||
viewname='documents:document_version_download', kwargs={
|
||||
'pk': self.test_document.latest_version.pk
|
||||
}, data=data
|
||||
)
|
||||
|
||||
def test_document_version_download_view_no_permission(self):
|
||||
response = self._request_document_version_download()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
@@ -316,12 +260,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def _request_document_update_page_count_view(self):
|
||||
return self.post(
|
||||
viewname='documents:document_update_page_count',
|
||||
kwargs={'pk': self.test_document.pk}
|
||||
)
|
||||
|
||||
def test_document_update_page_count_view_no_permission(self):
|
||||
self.test_document.pages.all().delete()
|
||||
self.assertEqual(self.test_document.pages.count(), 0)
|
||||
@@ -345,12 +283,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
self.assertEqual(self.test_document.pages.count(), page_count)
|
||||
|
||||
def _request_document_multiple_update_page_count_view(self):
|
||||
return self.post(
|
||||
viewname='documents:document_multiple_update_page_count',
|
||||
data={'id_list': self.test_document.pk}
|
||||
)
|
||||
|
||||
def test_document_multiple_update_page_count_view_no_permission(self):
|
||||
self.test_document.pages.all().delete()
|
||||
self.assertEqual(self.test_document.pages.count(), 0)
|
||||
@@ -372,12 +304,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
self.assertEqual(self.test_document.pages.count(), page_count)
|
||||
|
||||
def _request_document_clear_transformations_view(self):
|
||||
return self.post(
|
||||
viewname='documents:document_clear_transformations',
|
||||
kwargs={'pk': self.test_document.pk}
|
||||
)
|
||||
|
||||
def test_document_clear_transformations_view_no_permission(self):
|
||||
document_page = self.test_document.pages.first()
|
||||
content_type = ContentType.objects.get_for_model(document_page)
|
||||
@@ -431,12 +357,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
Transformation.objects.get_for_object(obj=document_page).count(), 0
|
||||
)
|
||||
|
||||
def _request_document_multiple_clear_transformations(self):
|
||||
return self.post(
|
||||
viewname='documents:document_multiple_clear_transformations',
|
||||
data={'id_list': self.test_document.pk}
|
||||
)
|
||||
|
||||
def test_document_multiple_clear_transformations_view_no_permission(self):
|
||||
document_page = self.test_document.pages.first()
|
||||
content_type = ContentType.objects.get_for_model(document_page)
|
||||
@@ -488,9 +408,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
Transformation.objects.get_for_object(obj=document_page).count(), 0
|
||||
)
|
||||
|
||||
def _request_empty_trash_view(self):
|
||||
return self.post(viewname='documents:trash_can_empty')
|
||||
|
||||
def test_trash_can_empty_view_no_permission(self):
|
||||
self.test_document.delete()
|
||||
self.assertEqual(DeletedDocument.objects.count(), 1)
|
||||
@@ -510,15 +427,6 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(DeletedDocument.objects.count(), 0)
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
|
||||
def _request_document_print_view(self):
|
||||
return self.get(
|
||||
viewname='documents:document_print', kwargs={
|
||||
'pk': self.test_document.pk,
|
||||
}, data={
|
||||
'page_group': PAGE_RANGE_ALL
|
||||
}
|
||||
)
|
||||
|
||||
def test_document_print_view_no_access(self):
|
||||
response = self._request_document_print_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
@@ -530,78 +438,3 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
response = self._request_document_print_view()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
class DocumentsQuickLabelViewsTestCase(DocumentTypeQuickLabelTestMixin, GenericDocumentViewTestCase):
|
||||
def _request_document_quick_label_edit_view(self, extra_data=None):
|
||||
data = {
|
||||
'document_type_available_filenames': self.test_document_type_filename.pk,
|
||||
'label': ''
|
||||
# View needs at least an empty label for quick
|
||||
# label to work. Cause is unknown.
|
||||
}
|
||||
data.update(extra_data or {})
|
||||
|
||||
return self.post(
|
||||
viewname='documents:document_edit', kwargs={
|
||||
'pk': self.test_document.pk
|
||||
}, data=data
|
||||
)
|
||||
|
||||
def test_document_quick_label_no_permission(self):
|
||||
self._create_test_quick_label()
|
||||
|
||||
response = self._request_document_quick_label_edit_view()
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_document_quick_label_with_access(self):
|
||||
self._create_test_quick_label()
|
||||
self.grant_access(
|
||||
obj=self.test_document,
|
||||
permission=permission_document_properties_edit
|
||||
)
|
||||
|
||||
response = self._request_document_quick_label_edit_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.test_document.refresh_from_db()
|
||||
self.assertEqual(
|
||||
self.test_document.label, self.test_document_type_filename.filename
|
||||
)
|
||||
|
||||
def test_document_quick_label_preserve_extension_with_access(self):
|
||||
self._create_test_quick_label()
|
||||
self.grant_access(
|
||||
permission=permission_document_properties_edit, obj=self.test_document
|
||||
)
|
||||
filename, extension = os.path.splitext(self.test_document.label)
|
||||
|
||||
response = self._request_document_quick_label_edit_view(
|
||||
extra_data={'preserve_extension': True}
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.test_document.refresh_from_db()
|
||||
self.assertEqual(
|
||||
self.test_document.label, '{}{}'.format(
|
||||
self.test_document_type_filename.filename, extension
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_quick_label_no_preserve_extension_with_access(self):
|
||||
self._create_test_quick_label()
|
||||
self.grant_access(
|
||||
obj=self.test_document,
|
||||
permission=permission_document_properties_edit
|
||||
)
|
||||
filename, extension = os.path.splitext(self.test_document.label)
|
||||
|
||||
response = self._request_document_quick_label_edit_view(
|
||||
extra_data={'preserve_extension': False}
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.test_document.refresh_from_db()
|
||||
self.assertEqual(
|
||||
self.test_document.label, self.test_document_type_filename.filename
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user