Improve document signatures tests

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-11-18 20:59:47 -04:00
parent 35aafc3f70
commit f55bf1b52e
4 changed files with 46 additions and 99 deletions

View File

@@ -6,7 +6,8 @@ from mayan.apps.django_gpg.permissions import permission_key_sign
from mayan.apps.django_gpg.tests.mixins import KeyTestMixin
from mayan.apps.documents.models import DocumentVersion
from mayan.apps.documents.tests import (
GenericDocumentViewTestCase, TEST_DOCUMENT_PATH
GenericDocumentViewTestCase, TEST_DOCUMENT_PATH,
TEST_SMALL_DOCUMENT_PATH
)
from ..models import DetachedSignature, EmbeddedSignature
@@ -36,9 +37,7 @@ class SignaturesViewTestCase(
auto_upload_document = False
def test_signature_delete_view_no_permission(self):
self._create_test_key_private()
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -53,9 +52,7 @@ class SignaturesViewTestCase(
self.assertEqual(DetachedSignature.objects.count(), 1)
def test_signature_delete_view_with_access(self):
self._create_test_key_private()
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -74,9 +71,7 @@ class SignaturesViewTestCase(
self.assertEqual(DetachedSignature.objects.count(), 0)
def test_signature_detail_view_no_permission(self):
self._create_test_key_private()
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -85,9 +80,7 @@ class SignaturesViewTestCase(
self.assertEqual(response.status_code, 404)
def test_signature_detail_view_with_access(self):
self._create_test_key_private()
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -103,40 +96,8 @@ class SignaturesViewTestCase(
status_code=200
)
"""
def test_signature_download_view_no_permission(self):
self.test_document_path = TEST_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
response = self._request_test_document_version_signature_download_view()
self.assertEqual(response.status_code, 403)
def test_signature_download_view_with_access(self):
self.test_document_path = TEST_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
self.grant_access(
obj=self.test_document,
permission=permission_document_version_signature_download
)
self.expected_content_type = 'application/octet-stream; charset=utf-8'
response = self._request_test_document_version_signature_download_view()
with self.test_signature.signature_file as file_object:
assert_download_response(
self, response=response, content=file_object.read(),
)
"""
def test_signature_list_view_no_permission(self):
self._create_test_key_private()
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -147,9 +108,7 @@ class SignaturesViewTestCase(
self.assertEqual(response.status_code, 403)
def test_signature_list_view_with_access(self):
self._create_test_key_private()
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -164,30 +123,7 @@ class SignaturesViewTestCase(
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['object_list'].count(), 1)
"""
def test_signature_upload_view_no_permission(self):
self.test_document_path = TEST_DOCUMENT_PATH
self.upload_document()
response = self._request_test_document_version_signature_upload_view()
self.assertEqual(response.status_code, 403)
self.assertEqual(DetachedSignature.objects.count(), 0)
def test_signature_upload_view_with_access(self):
self.test_document_path = TEST_DOCUMENT_PATH
self.upload_document()
self.grant_access(
obj=self.test_document,
permission=permission_document_version_signature_upload
)
response = self._request_test_document_version_signature_upload_view()
self.assertEqual(response.status_code, 302)
self.assertEqual(DetachedSignature.objects.count(), 1)
"""
def test_missing_signature_verify_view_no_permission(self):
# Silence converter logging
self._silence_logger(name='mayan.apps.converter.backends')
@@ -198,7 +134,7 @@ class SignaturesViewTestCase(
old_hooks = DocumentVersion._post_save_hooks
DocumentVersion._post_save_hooks = {}
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
for count in range(TEST_UNSIGNED_DOCUMENT_COUNT):
self.upload_document()
@@ -231,7 +167,7 @@ class SignaturesViewTestCase(
old_hooks = DocumentVersion._post_save_hooks
DocumentVersion._post_save_hooks = {}
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
for count in range(TEST_UNSIGNED_DOCUMENT_COUNT):
self.upload_document()
@@ -266,6 +202,7 @@ class DetachedSignaturesViewTestCase(
auto_upload_document = False
def test_detached_signature_create_view_with_no_permission(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()
@@ -280,6 +217,7 @@ class DetachedSignaturesViewTestCase(
)
def test_detached_signature_create_view_with_document_access(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()
@@ -299,6 +237,7 @@ class DetachedSignaturesViewTestCase(
)
def test_detached_signature_create_view_with_key_access(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()
@@ -318,6 +257,7 @@ class DetachedSignaturesViewTestCase(
)
def test_detached_signature_create_view_with_full_access(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()
@@ -341,7 +281,7 @@ class DetachedSignaturesViewTestCase(
)
def test_signature_download_view_no_permission(self):
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -350,7 +290,7 @@ class DetachedSignaturesViewTestCase(
self.assertEqual(response.status_code, 403)
def test_signature_download_view_with_access(self):
self.test_document_path = TEST_DOCUMENT_PATH
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_detached_signature()
@@ -371,6 +311,7 @@ class DetachedSignaturesViewTestCase(
def test_signature_upload_view_no_permission(self):
self.test_document_path = TEST_DOCUMENT_PATH
self.upload_document()
response = self._request_test_document_version_signature_upload_view()
@@ -399,6 +340,7 @@ class EmbeddedSignaturesViewTestCase(
auto_upload_document = False
def test_embedded_signature_create_view_with_no_permission(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()
@@ -413,6 +355,7 @@ class EmbeddedSignaturesViewTestCase(
)
def test_embedded_signature_create_view_with_document_access(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()
@@ -432,6 +375,7 @@ class EmbeddedSignaturesViewTestCase(
)
def test_embedded_signature_create_view_with_key_access(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()
@@ -451,6 +395,7 @@ class EmbeddedSignaturesViewTestCase(
)
def test_embedded_signature_create_view_with_full_access(self):
self.test_document_path = TEST_SMALL_DOCUMENT_PATH
self.upload_document()
self._create_test_key_private()