PEP8 cleanups.
This commit is contained in:
@@ -13,21 +13,32 @@ from django_gpg.runtime import gpg
|
||||
|
||||
from .models import DocumentVersionSignature
|
||||
|
||||
TEST_SIGNED_DOCUMENT_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', 'mayan_11_1.pdf.gpg')
|
||||
TEST_SIGNATURE_FILE_PATH = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', 'mayan_11_1.pdf.sig')
|
||||
TEST_KEY_FILE = os.path.join(settings.BASE_DIR, 'contrib', 'sample_documents', 'key0x5F3F7F75D210724D.asc')
|
||||
TEST_SIGNED_DOCUMENT_PATH = os.path.join(
|
||||
settings.BASE_DIR, 'contrib', 'sample_documents', 'mayan_11_1.pdf.gpg'
|
||||
)
|
||||
TEST_SIGNATURE_FILE_PATH = os.path.join(
|
||||
settings.BASE_DIR, 'contrib', 'sample_documents', 'mayan_11_1.pdf.sig'
|
||||
)
|
||||
TEST_KEY_FILE = os.path.join(
|
||||
settings.BASE_DIR, 'contrib', 'sample_documents',
|
||||
'key0x5F3F7F75D210724D.asc'
|
||||
)
|
||||
|
||||
|
||||
class DocumentTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.document_type = DocumentType.objects.create(label=TEST_DOCUMENT_TYPE)
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE
|
||||
)
|
||||
|
||||
ocr_settings = self.document_type.ocr_settings
|
||||
ocr_settings.auto_ocr = False
|
||||
ocr_settings.save()
|
||||
|
||||
with open(TEST_DOCUMENT_PATH) as file_object:
|
||||
self.document = self.document_type.new_document(file_object=File(file_object), label='mayan_11_1.pdf')
|
||||
self.document = self.document_type.new_document(
|
||||
file_object=File(file_object), label='mayan_11_1.pdf'
|
||||
)
|
||||
|
||||
with open(TEST_KEY_FILE) as file_object:
|
||||
gpg.import_key(file_object.read())
|
||||
@@ -37,24 +48,52 @@ class DocumentTestCase(TestCase):
|
||||
self.document_type.delete()
|
||||
|
||||
def test_document_no_signature(self):
|
||||
self.assertEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), False)
|
||||
self.assertEqual(
|
||||
DocumentVersionSignature.objects.has_detached_signature(
|
||||
self.document.latest_version
|
||||
), False
|
||||
)
|
||||
|
||||
def test_new_document_version_signed(self):
|
||||
with open(TEST_SIGNED_DOCUMENT_PATH) as file_object:
|
||||
self.document.new_version(file_object=File(file_object), comment='test comment 1')
|
||||
self.document.new_version(
|
||||
file_object=File(file_object), comment='test comment 1'
|
||||
)
|
||||
|
||||
self.assertEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), False)
|
||||
self.assertEqual(DocumentVersionSignature.objects.verify_signature(self.document.latest_version).status, SIGNATURE_STATE_VALID)
|
||||
self.assertEqual(
|
||||
DocumentVersionSignature.objects.has_detached_signature(
|
||||
self.document.latest_version
|
||||
), False
|
||||
)
|
||||
self.assertEqual(
|
||||
DocumentVersionSignature.objects.verify_signature(
|
||||
self.document.latest_version
|
||||
).status, SIGNATURE_STATE_VALID
|
||||
)
|
||||
|
||||
def test_detached_signatures(self):
|
||||
with open(TEST_DOCUMENT_PATH) as file_object:
|
||||
self.document.new_version(file_object=File(file_object), comment='test comment 2')
|
||||
self.document.new_version(
|
||||
file_object=File(file_object), comment='test comment 2'
|
||||
)
|
||||
|
||||
# GPGVerificationError
|
||||
self.assertEqual(DocumentVersionSignature.objects.verify_signature(self.document.latest_version), None)
|
||||
self.assertEqual(DocumentVersionSignature.objects.verify_signature(
|
||||
self.document.latest_version), None
|
||||
)
|
||||
|
||||
with open(TEST_SIGNATURE_FILE_PATH, 'rb') as file_object:
|
||||
DocumentVersionSignature.objects.add_detached_signature(self.document.latest_version, File(file_object))
|
||||
DocumentVersionSignature.objects.add_detached_signature(
|
||||
self.document.latest_version, File(file_object)
|
||||
)
|
||||
|
||||
self.assertEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), True)
|
||||
self.assertEqual(DocumentVersionSignature.objects.verify_signature(self.document.latest_version).status, SIGNATURE_STATE_VALID)
|
||||
self.assertEqual(
|
||||
DocumentVersionSignature.objects.has_detached_signature(
|
||||
self.document.latest_version
|
||||
), True
|
||||
)
|
||||
self.assertEqual(
|
||||
DocumentVersionSignature.objects.verify_signature(
|
||||
self.document.latest_version
|
||||
).status, SIGNATURE_STATE_VALID
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user