]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Add test for not moving default thumbnail 3645/head
authorJohannes Plunien <johannes@plunien.com>
Tue, 20 Jun 2023 18:23:52 +0000 (20:23 +0200)
committerJohannes Plunien <johannes@plunien.com>
Tue, 20 Jun 2023 18:54:15 +0000 (20:54 +0200)
See also #3632 and #3631

src/documents/tests/test_management_thumbnails.py

index 1b9d9f6642cf36b88a68d74b1bdbeea1c0f74f98..9f3ff63c593b0bcb230fb87ef22cf46b272d3335 100644 (file)
@@ -7,6 +7,7 @@ from django.test import TestCase
 
 from documents.management.commands.document_thumbnails import _process_document
 from documents.models import Document
+from documents.parsers import get_default_thumbnail
 from documents.tests.utils import DirectoriesMixin
 from documents.tests.utils import FileSystemAssertsMixin
 
@@ -26,9 +27,9 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
         )
 
         self.d2 = Document.objects.create(
-            checksum="Ass",
-            title="A",
-            content="first document",
+            checksum="B",
+            title="B",
+            content="second document",
             mime_type="application/pdf",
             filename="test2.pdf",
         )
@@ -37,6 +38,18 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
             self.d2.source_path,
         )
 
+        self.d3 = Document.objects.create(
+            checksum="C",
+            title="C",
+            content="third document",
+            mime_type="application/pdf",
+            filename="test3.pdf",
+        )
+        shutil.copy(
+            os.path.join(os.path.dirname(__file__), "samples", "password-is-test.pdf"),
+            self.d3.source_path,
+        )
+
     def setUp(self) -> None:
         super().setUp()
         self.make_models()
@@ -46,6 +59,14 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
         _process_document(self.d1.id)
         self.assertIsFile(self.d1.thumbnail_path)
 
+    def test_process_document_password_protected(self):
+        self.assertIsFile(get_default_thumbnail())
+        self.assertIsNotFile(self.d3.thumbnail_path)
+        _process_document(self.d3.id)
+        # Ensure default thumbnail is still there
+        self.assertIsFile(get_default_thumbnail())
+        self.assertIsFile(self.d3.thumbnail_path)
+
     @mock.patch("documents.management.commands.document_thumbnails.shutil.move")
     def test_process_document_invalid_mime_type(self, m: mock.Mock):
         self.d1.mime_type = "asdasdasd"