]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
add warning about --no-archive & --no-thumbnails options
authorMatthieu Helleboid <mhelleboid@hotmail.com>
Fri, 20 Jan 2023 18:21:43 +0000 (19:21 +0100)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 24 Jan 2023 19:06:49 +0000 (11:06 -0800)
add given_when_then informaiton to tests
add use_filename_prefix test
clear documents before importing in tests

docs/administration.md
src/documents/tests/test_management_exporter.py

index 468f62b401e8931aaa6376ef4f6a47737316ef55..3d68089861d64cbb6b103293a5417a9a21d785b9 100644 (file)
@@ -267,13 +267,16 @@ Be careful when pointing paperless to a directory that already contains
 other files.
 
 Paperless will not export archive files if you use `--no-archive`. After
-importing, These files can be generated again by using `document_archiver`.
+importing, the sanity checker will warn about missing files until these files
+are generated again by using `document_archiver`.
 It can make sense to omit these files from backup as their content and checksum
 can change (new archiver algorithm) and may then cause additional used space in
 a deduplicated backup.
 
 Paperless will not export thumbnails if you use `--no-thumbnail`. After
-importing, These files can be generated again by using `document_thumbnails`.
+importing, the sanity checker will warn about missing files and the documents
+view will not have thumbnails until these files are generated again by using
+`document_thumbnails`.
 It can make sense to omit these files from backup as their content and checksum
 can change (new thumbnail generation algorithm) and may then cause additional
 used space in a deduplicated backup.
index 9f75772a67522bacf770237f927e389f2b3b0559..d9b5a6dd20b5dc8f64ada797d38d6d04dce0f7f7 100644 (file)
@@ -105,6 +105,7 @@ class TestExportImport(DirectoriesMixin, TestCase):
         no_archive=False,
         no_thumbnail=False,
         split_manifest=False,
+        use_filename_prefix=False,
     ):
         args = ["document_exporter", self.target]
         if use_filename_format:
@@ -119,6 +120,8 @@ class TestExportImport(DirectoriesMixin, TestCase):
             args += ["--no-thumbnail"]
         if split_manifest:
             args += ["--split-manifest"]
+        if use_filename_prefix:
+            args += ["--use-filename-prefix"]
 
         call_command(*args)
 
@@ -508,6 +511,15 @@ class TestExportImport(DirectoriesMixin, TestCase):
                 self.assertEqual("That path doesn't appear to be writable", str(e))
 
     def test_no_archive(self):
+        """
+        GIVEN:
+            - Request to export documents to directory
+        WHEN:
+            - Option no-archive is used
+        THEN:
+            - Manifest.json doesn't contain information about archive files
+            - Documents can be imported again
+        """
         shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
         shutil.copytree(
             os.path.join(os.path.dirname(__file__), "samples", "documents"),
@@ -533,10 +545,22 @@ class TestExportImport(DirectoriesMixin, TestCase):
         self.assertFalse(has_archive)
 
         with paperless_environment() as dirs:
+            self.assertEqual(Document.objects.count(), 4)
+            Document.objects.all().delete()
+            self.assertEqual(Document.objects.count(), 0)
             call_command("document_importer", self.target)
             self.assertEqual(Document.objects.count(), 4)
 
     def test_no_thumbnail(self):
+        """
+        GIVEN:
+            - Request to export documents to directory
+        WHEN:
+            - Option no-thumbnails is used
+        THEN:
+            - Manifest.json doesn't contain information about thumbnails
+            - Documents can be imported again
+        """
         shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
         shutil.copytree(
             os.path.join(os.path.dirname(__file__), "samples", "documents"),
@@ -564,10 +588,22 @@ class TestExportImport(DirectoriesMixin, TestCase):
         self.assertFalse(has_thumbnail)
 
         with paperless_environment() as dirs:
+            self.assertEqual(Document.objects.count(), 4)
+            Document.objects.all().delete()
+            self.assertEqual(Document.objects.count(), 0)
             call_command("document_importer", self.target)
             self.assertEqual(Document.objects.count(), 4)
 
     def test_split_manifest(self):
+        """
+        GIVEN:
+            - Request to export documents to directory
+        WHEN:
+            - Option split_manifest is used
+        THEN:
+            - Main manifest.json file doesn't contain information about documents
+            - Documents can be imported again
+        """
         shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
         shutil.copytree(
             os.path.join(os.path.dirname(__file__), "samples", "documents"),
@@ -581,5 +617,32 @@ class TestExportImport(DirectoriesMixin, TestCase):
         self.assertFalse(has_document)
 
         with paperless_environment() as dirs:
+            self.assertEqual(Document.objects.count(), 4)
+            Document.objects.all().delete()
+            self.assertEqual(Document.objects.count(), 0)
+            call_command("document_importer", self.target)
+            self.assertEqual(Document.objects.count(), 4)
+
+    def test_filename_prefix(self):
+        """
+        GIVEN:
+            - Request to export documents to directory
+        WHEN:
+            - Option use_filename_prefix is used
+        THEN:
+            - Documents can be imported again
+        """
+        shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
+        shutil.copytree(
+            os.path.join(os.path.dirname(__file__), "samples", "documents"),
+            os.path.join(self.dirs.media_dir, "documents"),
+        )
+
+        manifest = self._do_export(use_filename_prefix=True)
+
+        with paperless_environment() as dirs:
+            self.assertEqual(Document.objects.count(), 4)
+            Document.objects.all().delete()
+            self.assertEqual(Document.objects.count(), 0)
             call_command("document_importer", self.target)
             self.assertEqual(Document.objects.count(), 4)