A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
fixed test case. fixed bug with the decryption logic.
jonaswinkler2be0ba9f72f4
diff --git a/src/documents/management/commands/decrypt_documents.py b/src/documents/management/commands/decrypt_documents.pyindex 2287bfa72..918f1a175 100644--- a/src/documents/management/commands/decrypt_documents.py+++ b/src/documents/management/commands/decrypt_documents.py@@ -82,7 +82,8 @@ class Command(BaseCommand):with open(document.thumbnail_path, "wb") as f:f.write(raw_thumb)- document.save(update_fields=("storage_type", "filename"))+ Document.objects.filter(id=document.id).update(+ storage_type=document.storage_type, filename=document.filename)for path in old_paths:os.unlink(path)diff --git a/src/documents/tests/test_management_archiver.py b/src/documents/tests/test_management_archiver.pyindex fdb588acf..0828f05ff 100644--- a/src/documents/tests/test_management_archiver.py+++ b/src/documents/tests/test_management_archiver.py@@ -16,25 +16,23 @@ sample_file = os.path.join(os.path.dirname(__file__), "samples", "simple.pdf")class TestArchiver(DirectoriesMixin, TestCase):def make_models(self):- self.d1 = Document.objects.create(checksum="A", title="A", content="first document", pk=1, mime_type="application/pdf")- #self.d2 = Document.objects.create(checksum="B", title="B", content="second document")- #self.d3 = Document.objects.create(checksum="C", title="C", content="unrelated document")+ return Document.objects.create(checksum="A", title="A", content="first document", mime_type="application/pdf")def test_archiver(self):- shutil.copy(sample_file, os.path.join(self.dirs.originals_dir, "0000001.pdf"))- self.make_models()+ doc = self.make_models()+ shutil.copy(sample_file, os.path.join(self.dirs.originals_dir, f"{doc.id:07}.pdf"))call_command('document_archiver')def test_handle_document(self):- shutil.copy(sample_file, os.path.join(self.dirs.originals_dir, "0000001.pdf"))- self.make_models()+ doc = self.make_models()+ shutil.copy(sample_file, os.path.join(self.dirs.originals_dir, f"{doc.id:07}.pdf"))- handle_document(self.d1.pk)+ handle_document(doc.pk)- doc = Document.objects.get(id=self.d1.id)+ doc = Document.objects.get(id=doc.id)self.assertIsNotNone(doc.checksum)self.assertTrue(os.path.isfile(doc.archive_path))diff --git a/src/documents/tests/test_management_decrypt.py b/src/documents/tests/test_management_decrypt.pyindex f68ea7cc1..1d64b1105 100644--- a/src/documents/tests/test_management_decrypt.py+++ b/src/documents/tests/test_management_decrypt.py@@ -35,20 +35,20 @@ class TestDecryptDocuments(TestCase):PASSPHRASE="test").enable()- shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "originals", "0000002.pdf.gpg"), os.path.join(originals_dir, "0000002.pdf.gpg"))- shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "thumbnails", "0000002.png.gpg"), os.path.join(thumb_dir, "0000002.png.gpg"))+ doc = Document.objects.create(checksum="9c9691e51741c1f4f41a20896af31770", title="wow", filename="0000002.pdf.gpg", mime_type="application/pdf", storage_type=Document.STORAGE_TYPE_GPG)- Document.objects.create(checksum="9c9691e51741c1f4f41a20896af31770", title="wow", filename="0000002.pdf.gpg", id=2, mime_type="application/pdf", storage_type=Document.STORAGE_TYPE_GPG)+ shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "originals", "0000002.pdf.gpg"), os.path.join(originals_dir, "0000002.pdf.gpg"))+ shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "documents", "thumbnails", f"0000002.png.gpg"), os.path.join(thumb_dir, f"{doc.id:07}.png.gpg"))call_command('decrypt_documents')- doc = Document.objects.get(id=2)+ doc.refresh_from_db()self.assertEqual(doc.storage_type, Document.STORAGE_TYPE_UNENCRYPTED)self.assertEqual(doc.filename, "0000002.pdf")self.assertTrue(os.path.isfile(os.path.join(originals_dir, "0000002.pdf")))self.assertTrue(os.path.isfile(doc.source_path))- self.assertTrue(os.path.isfile(os.path.join(thumb_dir, "0000002.png")))+ self.assertTrue(os.path.isfile(os.path.join(thumb_dir, f"{doc.id:07}.png")))self.assertTrue(os.path.isfile(doc.thumbnail_path))with doc.source_file as f:diff --git a/src/documents/tests/test_management_exporter.py b/src/documents/tests/test_management_exporter.pyindex ab9733dc4..22d6fc7f6 100644--- a/src/documents/tests/test_management_exporter.py+++ b/src/documents/tests/test_management_exporter.py@@ -24,13 +24,14 @@ class TestExportImport(DirectoriesMixin, TestCase):file = os.path.join(self.dirs.originals_dir, "0000001.pdf")- Document.objects.create(content="Content", checksum="42995833e01aea9b3edee44bbfdd7ce1", archive_checksum="62acb0bcbfbcaa62ca6ad3668e4e404b", title="wow", filename="0000001.pdf", id=1, mime_type="application/pdf")- Document.objects.create(content="Content", checksum="9c9691e51741c1f4f41a20896af31770", title="wow", filename="0000002.pdf.gpg", id=2, mime_type="application/pdf", storage_type=Document.STORAGE_TYPE_GPG)+ Document.objects.create(content="Content", checksum="42995833e01aea9b3edee44bbfdd7ce1", archive_checksum="62acb0bcbfbcaa62ca6ad3668e4e404b", title="wow", filename="0000001.pdf", mime_type="application/pdf")+ Document.objects.create(content="Content", checksum="9c9691e51741c1f4f41a20896af31770", title="wow", filename="0000002.pdf.gpg", mime_type="application/pdf", storage_type=Document.STORAGE_TYPE_GPG)Tag.objects.create(name="t")DocumentType.objects.create(name="dt")Correspondent.objects.create(name="c")target = tempfile.mkdtemp()+ self.addCleanup(shutil.rmtree, target)call_command('document_exporter', target)@@ -66,9 +67,6 @@ class TestExportImport(DirectoriesMixin, TestCase):def test_export_missing_files(self):target = tempfile.mkdtemp()- Document.objects.create(checksum="AAAAAAAAAAAAAAAAA", title="wow", filename="0000004.pdf", id=3, mime_type="application/pdf")+ self.addCleanup(shutil.rmtree, target)+ Document.objects.create(checksum="AAAAAAAAAAAAAAAAA", title="wow", filename="0000004.pdf", mime_type="application/pdf")self.assertRaises(FileNotFoundError, call_command, 'document_exporter', target)-- def test_duplicate_titles(self):- # TODO- pass