]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
added some test cases that I still need to address
authorjonaswinkler <jonas.winkler@jpwinkler.de>
Wed, 10 Feb 2021 22:53:48 +0000 (23:53 +0100)
committerjonaswinkler <jonas.winkler@jpwinkler.de>
Wed, 10 Feb 2021 22:53:48 +0000 (23:53 +0100)
src/documents/tests/test_file_handling.py
src/documents/tests/test_management.py

index 927c865c6d40ed372dcc62c9a2657efd30dfe72e..a806e1025b21ebf6110ae12acc63d8808ed61358 100644 (file)
@@ -507,6 +507,38 @@ class TestFileHandlingWithArchive(DirectoriesMixin, TestCase):
         self.assertTrue(os.path.isfile(existing_archive_file))
         self.assertEqual(doc.archive_filename, "none/my_doc_01.pdf")
 
+    @override_settings(PAPERLESS_FILENAME_FORMAT="{title}")
+    def test_move_original_only(self):
+        original = os.path.join(settings.ORIGINALS_DIR, "document_01.pdf")
+        archive = os.path.join(settings.ARCHIVE_DIR, "document.pdf")
+        Path(original).touch()
+        Path(archive).touch()
+
+        doc = Document.objects.create(mime_type="application/pdf", title="document", filename="document_01.pdf", checksum="A",
+                                      archive_checksum="B", archive_filename="document.pdf")
+
+        self.assertEqual(doc.filename, "document.pdf")
+        self.assertEqual(doc.archive_filename, "document.pdf")
+
+        self.assertTrue(os.path.isfile(doc.source_path))
+        self.assertTrue(os.path.isfile(doc.archive_path))
+
+    @override_settings(PAPERLESS_FILENAME_FORMAT="{title}")
+    def test_move_archive_only(self):
+        original = os.path.join(settings.ORIGINALS_DIR, "document.pdf")
+        archive = os.path.join(settings.ARCHIVE_DIR, "document_01.pdf")
+        Path(original).touch()
+        Path(archive).touch()
+
+        doc = Document.objects.create(mime_type="application/pdf", title="document", filename="document.pdf", checksum="A",
+                                      archive_checksum="B", archive_filename="document_01.pdf")
+
+        self.assertEqual(doc.filename, "document.pdf")
+        self.assertEqual(doc.archive_filename, "document.pdf")
+
+        self.assertTrue(os.path.isfile(doc.source_path))
+        self.assertTrue(os.path.isfile(doc.archive_path))
+
     @override_settings(PAPERLESS_FILENAME_FORMAT="{correspondent}/{title}")
     @mock.patch("documents.signals.handlers.os.rename")
     def test_move_archive_error(self, m):
index 978dff8b3530ce61805d080f8c6cf9ca33bdc54a..1a550a4b4efa947ce2defa56dcfab9baa87de312 100644 (file)
@@ -43,11 +43,27 @@ class TestArchiver(DirectoriesMixin, TestCase):
         doc = Document.objects.get(id=doc.id)
 
         self.assertIsNotNone(doc.checksum)
+        self.assertIsNotNone(doc.archive_checksum)
         self.assertTrue(os.path.isfile(doc.archive_path))
         self.assertTrue(os.path.isfile(doc.source_path))
         self.assertTrue(filecmp.cmp(sample_file, doc.source_path))
         self.assertEqual(doc.archive_filename, "none/A.pdf")
 
+    @override_settings(PAPERLESS_FILENAME_FORMAT="{title}")
+    def test_naming_priorities(self):
+        doc1 = Document.objects.create(checksum="A", title="document", content="first document", mime_type="application/pdf", filename="document.pdf")
+        doc2 = Document.objects.create(checksum="B", title="document", content="second document", mime_type="application/pdf", filename="document_01.pdf")
+        shutil.copy(sample_file, os.path.join(self.dirs.originals_dir, f"document.pdf"))
+        shutil.copy(sample_file, os.path.join(self.dirs.originals_dir, f"document_01.pdf"))
+
+        handle_document(doc2.pk)
+        handle_document(doc1.pk)
+
+        doc1 = Document.objects.get(id=doc1.id)
+        doc2 = Document.objects.get(id=doc2.id)
+
+        self.assertEqual(doc1.archive_filename, "document.pdf")
+        self.assertEqual(doc2.archive_filename, "document_01.pdf")
 
 class TestDecryptDocuments(TestCase):