Tests: Modernize some test cases
Update some view tests in the tags, sources and linking apps to use the test case classes provided by the common app. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from mayan.apps.common.tests import GenericViewTestCase
|
||||
from mayan.apps.documents.permissions import permission_document_view
|
||||
from mayan.apps.documents.tests import GenericDocumentViewTestCase
|
||||
|
||||
@@ -15,7 +16,7 @@ from .literals import (
|
||||
)
|
||||
|
||||
|
||||
class SmartLinkViewTestCase(GenericDocumentViewTestCase):
|
||||
class SmartLinkViewTestCase(GenericViewTestCase):
|
||||
def setUp(self):
|
||||
super(SmartLinkViewTestCase, self).setUp()
|
||||
self.login_user()
|
||||
@@ -98,6 +99,12 @@ class SmartLinkViewTestCase(GenericDocumentViewTestCase):
|
||||
self.assertContains(response, text='update', status_code=200)
|
||||
self.assertEqual(smart_link.label, TEST_SMART_LINK_LABEL_EDITED)
|
||||
|
||||
|
||||
class SmartLinkDocumentsViewTestCase(GenericDocumentViewTestCase):
|
||||
def setUp(self):
|
||||
super(SmartLinkDocumentsViewTestCase, self).setUp()
|
||||
self.login_user()
|
||||
|
||||
def setup_smart_links(self):
|
||||
smart_link = SmartLink.objects.create(
|
||||
label=TEST_SMART_LINK_LABEL,
|
||||
|
||||
@@ -4,17 +4,14 @@ import logging
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from django.test import override_settings
|
||||
|
||||
from mayan.apps.checkouts.models import NewVersionBlock
|
||||
from mayan.apps.common.tests import GenericViewTestCase
|
||||
from mayan.apps.common.utils import fs_cleanup, mkdtemp
|
||||
from mayan.apps.documents.models import Document, DocumentType
|
||||
from mayan.apps.documents.models import Document
|
||||
from mayan.apps.documents.permissions import permission_document_create
|
||||
from mayan.apps.documents.tests import (
|
||||
TEST_DOCUMENT_DESCRIPTION, TEST_DOCUMENT_TYPE_LABEL,
|
||||
TEST_SMALL_DOCUMENT_CHECKSUM, TEST_SMALL_DOCUMENT_PATH,
|
||||
GenericDocumentViewTestCase
|
||||
TEST_DOCUMENT_DESCRIPTION, TEST_SMALL_DOCUMENT_CHECKSUM,
|
||||
TEST_SMALL_DOCUMENT_PATH, GenericDocumentViewTestCase
|
||||
)
|
||||
|
||||
from ..links import link_upload_version
|
||||
@@ -31,15 +28,19 @@ from .literals import (
|
||||
|
||||
|
||||
class DocumentUploadTestCase(GenericDocumentViewTestCase):
|
||||
auto_upload_document = False
|
||||
|
||||
def setUp(self):
|
||||
super(DocumentUploadTestCase, self).setUp()
|
||||
self._create_source()
|
||||
self.login_user()
|
||||
|
||||
def _create_source(self):
|
||||
self.source = WebFormSource.objects.create(
|
||||
enabled=True, label=TEST_SOURCE_LABEL,
|
||||
uncompress=TEST_SOURCE_UNCOMPRESS_N
|
||||
)
|
||||
|
||||
self.document.delete()
|
||||
|
||||
def _request_upload_wizard_view(self):
|
||||
logging.getLogger('django.request').setLevel(level=logging.CRITICAL)
|
||||
|
||||
@@ -53,15 +54,11 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase):
|
||||
)
|
||||
|
||||
def test_upload_wizard_without_permission(self):
|
||||
self.login_user()
|
||||
|
||||
response = self._request_upload_wizard_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
|
||||
def test_upload_wizard_with_permission(self):
|
||||
self.login_user()
|
||||
|
||||
self.grant_permission(permission=permission_document_create)
|
||||
|
||||
response = self._request_upload_wizard_view()
|
||||
@@ -77,8 +74,6 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase):
|
||||
Test uploading of documents by granting the document create
|
||||
permssion for the document type to the user
|
||||
"""
|
||||
self.login_user()
|
||||
|
||||
# Create an access control entry giving the role the document
|
||||
# create permission for the selected document type.
|
||||
self.grant_access(
|
||||
@@ -107,13 +102,10 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase):
|
||||
)
|
||||
|
||||
def test_upload_interactive_view_no_permission(self):
|
||||
self.login_user()
|
||||
|
||||
response = self._request_upload_interactive_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_upload_interactive_view_with_access(self):
|
||||
self.login_user()
|
||||
self.grant_access(
|
||||
permission=permission_document_create, obj=self.document_type
|
||||
)
|
||||
@@ -123,17 +115,8 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase):
|
||||
)
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class DocumentUploadIssueTestCase(GenericViewTestCase):
|
||||
def setUp(self):
|
||||
super(DocumentUploadIssueTestCase, self).setUp()
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.document_type.delete()
|
||||
super(DocumentUploadIssueTestCase, self).tearDown()
|
||||
class DocumentUploadIssueTestCase(GenericDocumentViewTestCase):
|
||||
auto_upload_document = False
|
||||
|
||||
def test_issue_25(self):
|
||||
self.login_admin_user()
|
||||
@@ -221,64 +204,61 @@ class StagingFolderViewTestCase(GenericViewTestCase):
|
||||
super(StagingFolderViewTestCase, self).setUp()
|
||||
self.temporary_directory = mkdtemp()
|
||||
shutil.copy(TEST_SMALL_DOCUMENT_PATH, self.temporary_directory)
|
||||
|
||||
self.filename = os.path.basename(TEST_SMALL_DOCUMENT_PATH)
|
||||
self.login_user()
|
||||
|
||||
def tearDown(self):
|
||||
fs_cleanup(self.temporary_directory)
|
||||
super(StagingFolderViewTestCase, self).tearDown()
|
||||
|
||||
def _request_staging_file_delete_view(self, staging_folder, staging_file):
|
||||
def _request_staging_file_delete_view(self, staging_file):
|
||||
return self.post(
|
||||
viewname='sources:staging_file_delete', args=(
|
||||
staging_folder.pk, staging_file.encoded_filename
|
||||
self.staging_folder.pk, staging_file.encoded_filename
|
||||
)
|
||||
)
|
||||
|
||||
def test_staging_folder_delete_no_permission(self):
|
||||
self.login_user()
|
||||
|
||||
staging_folder = StagingFolderSource.objects.create(
|
||||
def _create_staging_folder(self):
|
||||
self.staging_folder = StagingFolderSource.objects.create(
|
||||
label=TEST_SOURCE_LABEL,
|
||||
folder_path=self.temporary_directory,
|
||||
preview_width=TEST_STAGING_PREVIEW_WIDTH,
|
||||
uncompress=TEST_SOURCE_UNCOMPRESS_N,
|
||||
)
|
||||
|
||||
self.assertEqual(len(list(staging_folder.get_files())), 1)
|
||||
def test_staging_folder_delete_no_permission(self):
|
||||
self._create_staging_folder()
|
||||
|
||||
staging_file = list(staging_folder.get_files())[0]
|
||||
self.assertEqual(len(list(self.staging_folder.get_files())), 1)
|
||||
|
||||
staging_file = list(self.staging_folder.get_files())[0]
|
||||
|
||||
response = self._request_staging_file_delete_view(
|
||||
staging_folder=staging_folder, staging_file=staging_file
|
||||
staging_file=staging_file
|
||||
)
|
||||
self.assertEqual(response.status_code, 403)
|
||||
self.assertEqual(len(list(staging_folder.get_files())), 1)
|
||||
self.assertEqual(len(list(self.staging_folder.get_files())), 1)
|
||||
|
||||
def test_staging_folder_delete_with_permission(self):
|
||||
self.login_user()
|
||||
|
||||
self._create_staging_folder()
|
||||
self.grant_permission(permission=permission_staging_file_delete)
|
||||
|
||||
staging_folder = StagingFolderSource.objects.create(
|
||||
label=TEST_SOURCE_LABEL,
|
||||
folder_path=self.temporary_directory,
|
||||
preview_width=TEST_STAGING_PREVIEW_WIDTH,
|
||||
uncompress=TEST_SOURCE_UNCOMPRESS_N,
|
||||
)
|
||||
self.assertEqual(len(list(self.staging_folder.get_files())), 1)
|
||||
|
||||
self.assertEqual(len(list(staging_folder.get_files())), 1)
|
||||
|
||||
staging_file = list(staging_folder.get_files())[0]
|
||||
staging_file = list(self.staging_folder.get_files())[0]
|
||||
|
||||
response = self._request_staging_file_delete_view(
|
||||
staging_folder=staging_folder, staging_file=staging_file
|
||||
staging_file=staging_file
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(len(list(staging_folder.get_files())), 0)
|
||||
self.assertEqual(len(list(self.staging_folder.get_files())), 0)
|
||||
|
||||
|
||||
class SourcesTestCase(GenericDocumentViewTestCase):
|
||||
def setUp(self):
|
||||
super(SourcesTestCase, self).setUp()
|
||||
self.login_user()
|
||||
|
||||
def _create_web_source(self):
|
||||
self.source = WebFormSource.objects.create(
|
||||
enabled=True, label=TEST_SOURCE_LABEL,
|
||||
@@ -291,16 +271,12 @@ class SourcesTestCase(GenericDocumentViewTestCase):
|
||||
def test_source_list_view_no_permission(self):
|
||||
self._create_web_source()
|
||||
|
||||
self.login_user()
|
||||
|
||||
response = self._request_setup_source_list_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_source_list_view_with_permission(self):
|
||||
self._create_web_source()
|
||||
|
||||
self.login_user()
|
||||
|
||||
self.grant_permission(permission=permission_sources_setup_view)
|
||||
|
||||
response = self._request_setup_source_list_view()
|
||||
@@ -318,8 +294,6 @@ class SourcesTestCase(GenericDocumentViewTestCase):
|
||||
)
|
||||
|
||||
def test_source_create_view_no_permission(self):
|
||||
self.login_user()
|
||||
|
||||
self.grant_permission(permission=permission_sources_setup_view)
|
||||
|
||||
response = self._request_setup_source_create_view()
|
||||
@@ -328,8 +302,6 @@ class SourcesTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(WebFormSource.objects.count(), 0)
|
||||
|
||||
def test_source_create_view_with_permission(self):
|
||||
self.login_user()
|
||||
|
||||
self.grant_permission(permission=permission_sources_setup_create)
|
||||
self.grant_permission(permission=permission_sources_setup_view)
|
||||
|
||||
@@ -349,8 +321,6 @@ class SourcesTestCase(GenericDocumentViewTestCase):
|
||||
def test_source_delete_view_with_permission(self):
|
||||
self._create_web_source()
|
||||
|
||||
self.login_user()
|
||||
|
||||
self.grant_permission(permission=permission_sources_setup_delete)
|
||||
self.grant_permission(permission=permission_sources_setup_view)
|
||||
|
||||
@@ -361,8 +331,6 @@ class SourcesTestCase(GenericDocumentViewTestCase):
|
||||
def test_source_delete_view_no_permission(self):
|
||||
self._create_web_source()
|
||||
|
||||
self.login_user()
|
||||
|
||||
self.grant_permission(permission=permission_sources_setup_view)
|
||||
|
||||
response = self._request_setup_source_delete_view()
|
||||
|
||||
@@ -33,3 +33,58 @@ class TagTestMixin(object):
|
||||
'label': TEST_TAG_LABEL_EDITED, 'color': TEST_TAG_COLOR_EDITED
|
||||
}
|
||||
)
|
||||
|
||||
def _request_multiple_delete_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_multiple_delete',
|
||||
data={'id_list': self.tag.pk},
|
||||
)
|
||||
|
||||
def _request_edit_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_edit', args=(self.tag.pk,), data={
|
||||
'label': TEST_TAG_LABEL_EDITED, 'color': TEST_TAG_COLOR_EDITED
|
||||
}
|
||||
)
|
||||
|
||||
def _request_create_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_create', data={
|
||||
'label': TEST_TAG_LABEL,
|
||||
'color': TEST_TAG_COLOR
|
||||
}
|
||||
)
|
||||
|
||||
def _request_attach_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_attach', args=(self.document.pk,), data={
|
||||
'tags': self.tag.pk,
|
||||
'user': self.user.pk
|
||||
}
|
||||
)
|
||||
|
||||
def _request_multiple_attach_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:multiple_documents_tag_attach', data={
|
||||
'id_list': self.document.pk, 'tags': self.tag.pk,
|
||||
'user': self.user.pk
|
||||
}
|
||||
)
|
||||
|
||||
def _request_single_document_multiple_tag_remove_view(self):
|
||||
return self.post(
|
||||
viewname='tags:single_document_multiple_tag_remove',
|
||||
args=(self.document.pk,), data={
|
||||
'id_list': self.document.pk,
|
||||
'tags': self.tag.pk,
|
||||
}
|
||||
)
|
||||
|
||||
def _request_multiple_documents_selection_tag_remove_view(self):
|
||||
return self.post(
|
||||
viewname='tags:multiple_documents_selection_tag_remove',
|
||||
data={
|
||||
'id_list': self.document.pk,
|
||||
'tags': self.tag.pk,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from mayan.apps.common.tests import GenericViewTestCase
|
||||
from mayan.apps.documents.permissions import permission_document_view
|
||||
from mayan.apps.documents.tests import GenericDocumentViewTestCase
|
||||
|
||||
@@ -13,26 +14,14 @@ from .literals import (
|
||||
TEST_TAG_COLOR, TEST_TAG_COLOR_EDITED, TEST_TAG_LABEL,
|
||||
TEST_TAG_LABEL_EDITED
|
||||
)
|
||||
from .mixins import TagTestMixin
|
||||
|
||||
|
||||
class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
def _create_tag(self):
|
||||
self.tag = Tag.objects.create(
|
||||
color=TEST_TAG_COLOR, label=TEST_TAG_LABEL
|
||||
)
|
||||
|
||||
def _request_create_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_create', data={
|
||||
'label': TEST_TAG_LABEL,
|
||||
'color': TEST_TAG_COLOR
|
||||
}
|
||||
)
|
||||
|
||||
class TagViewTestCase(TagTestMixin, GenericViewTestCase):
|
||||
def test_tag_create_view_no_permissions(self):
|
||||
self.login_user()
|
||||
|
||||
response = self._request_create_tag_view()
|
||||
response = self._request_tag_create_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
self.assertEqual(Tag.objects.count(), 0)
|
||||
@@ -41,7 +30,7 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
self.login_user()
|
||||
|
||||
self.grant_permission(permission=permission_tag_create)
|
||||
response = self._request_create_tag_view()
|
||||
response = self._request_tag_create_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertEqual(Tag.objects.count(), 1)
|
||||
@@ -49,16 +38,11 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(tag.label, TEST_TAG_LABEL)
|
||||
self.assertEqual(tag.color, TEST_TAG_COLOR)
|
||||
|
||||
def _request_delete_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_delete', args=(self.tag.pk,)
|
||||
)
|
||||
|
||||
def test_tag_delete_view_no_permissions(self):
|
||||
self.login_user()
|
||||
self._create_tag()
|
||||
|
||||
response = self._request_delete_tag_view()
|
||||
response = self._request_tag_delete_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(Tag.objects.count(), 1)
|
||||
|
||||
@@ -68,17 +52,11 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
self.grant_access(obj=self.tag, permission=permission_tag_delete)
|
||||
|
||||
response = self._request_delete_tag_view()
|
||||
response = self._request_tag_delete_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertEqual(Tag.objects.count(), 0)
|
||||
|
||||
def _request_multiple_delete_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_multiple_delete',
|
||||
data={'id_list': self.tag.pk},
|
||||
)
|
||||
|
||||
def test_tag_multiple_delete_view_no_permissions(self):
|
||||
self.login_user()
|
||||
self._create_tag()
|
||||
@@ -98,13 +76,6 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
self.assertEqual(Tag.objects.count(), 0)
|
||||
|
||||
def _request_edit_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_edit', args=(self.tag.pk,), data={
|
||||
'label': TEST_TAG_LABEL_EDITED, 'color': TEST_TAG_COLOR_EDITED
|
||||
}
|
||||
)
|
||||
|
||||
def test_tag_edit_view_no_permissions(self):
|
||||
self.login_user()
|
||||
self._create_tag()
|
||||
@@ -127,6 +98,8 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(tag.label, TEST_TAG_LABEL_EDITED)
|
||||
self.assertEqual(tag.color, TEST_TAG_COLOR_EDITED)
|
||||
|
||||
|
||||
class TagDocumentsViewTestCase(TagTestMixin, GenericDocumentViewTestCase):
|
||||
def _request_document_list_view(self):
|
||||
return self.get(viewname='documents:document_list')
|
||||
|
||||
@@ -156,14 +129,6 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
response=response, text=TEST_TAG_LABEL, status_code=200
|
||||
)
|
||||
|
||||
def _request_attach_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:tag_attach', args=(self.document.pk,), data={
|
||||
'tags': self.tag.pk,
|
||||
'user': self.user.pk
|
||||
}
|
||||
)
|
||||
|
||||
def test_document_attach_tag_view_no_permission(self):
|
||||
self.login_user()
|
||||
self._create_tag()
|
||||
@@ -197,14 +162,6 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
self.document.tags.all(), (repr(self.tag),)
|
||||
)
|
||||
|
||||
def _request_multiple_attach_tag_view(self):
|
||||
return self.post(
|
||||
viewname='tags:multiple_documents_tag_attach', data={
|
||||
'id_list': self.document.pk, 'tags': self.tag.pk,
|
||||
'user': self.user.pk
|
||||
}
|
||||
)
|
||||
|
||||
def test_document_multiple_attach_tag_view_no_permission(self):
|
||||
self.login_user()
|
||||
self._create_tag()
|
||||
@@ -233,15 +190,6 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
self.document.tags.all(), (repr(self.tag),)
|
||||
)
|
||||
|
||||
def _request_single_document_multiple_tag_remove_view(self):
|
||||
return self.post(
|
||||
viewname='tags:single_document_multiple_tag_remove',
|
||||
args=(self.document.pk,), data={
|
||||
'id_list': self.document.pk,
|
||||
'tags': self.tag.pk,
|
||||
}
|
||||
)
|
||||
|
||||
def test_single_document_multiple_tag_remove_view_no_permissions(self):
|
||||
self.login_user()
|
||||
self._create_tag()
|
||||
@@ -270,15 +218,6 @@ class TagViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
self.assertEqual(self.document.tags.count(), 0)
|
||||
|
||||
def _request_multiple_documents_selection_tag_remove_view(self):
|
||||
return self.post(
|
||||
viewname='tags:multiple_documents_selection_tag_remove',
|
||||
data={
|
||||
'id_list': self.document.pk,
|
||||
'tags': self.tag.pk,
|
||||
}
|
||||
)
|
||||
|
||||
def test_multiple_documents_selection_tag_remove_view_no_permissions(self):
|
||||
self.login_user()
|
||||
self._create_tag()
|
||||
|
||||
Reference in New Issue
Block a user