mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	@@ -7,6 +7,7 @@ from django.test import TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from documents.management.commands.document_thumbnails import _process_document
 | 
					from documents.management.commands.document_thumbnails import _process_document
 | 
				
			||||||
from documents.models import Document
 | 
					from documents.models import Document
 | 
				
			||||||
 | 
					from documents.parsers import get_default_thumbnail
 | 
				
			||||||
from documents.tests.utils import DirectoriesMixin
 | 
					from documents.tests.utils import DirectoriesMixin
 | 
				
			||||||
from documents.tests.utils import FileSystemAssertsMixin
 | 
					from documents.tests.utils import FileSystemAssertsMixin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -26,9 +27,9 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.d2 = Document.objects.create(
 | 
					        self.d2 = Document.objects.create(
 | 
				
			||||||
            checksum="Ass",
 | 
					            checksum="B",
 | 
				
			||||||
            title="A",
 | 
					            title="B",
 | 
				
			||||||
            content="first document",
 | 
					            content="second document",
 | 
				
			||||||
            mime_type="application/pdf",
 | 
					            mime_type="application/pdf",
 | 
				
			||||||
            filename="test2.pdf",
 | 
					            filename="test2.pdf",
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
@@ -37,6 +38,18 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
 | 
				
			|||||||
            self.d2.source_path,
 | 
					            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:
 | 
					    def setUp(self) -> None:
 | 
				
			||||||
        super().setUp()
 | 
					        super().setUp()
 | 
				
			||||||
        self.make_models()
 | 
					        self.make_models()
 | 
				
			||||||
@@ -46,6 +59,14 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
 | 
				
			|||||||
        _process_document(self.d1.id)
 | 
					        _process_document(self.d1.id)
 | 
				
			||||||
        self.assertIsFile(self.d1.thumbnail_path)
 | 
					        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")
 | 
					    @mock.patch("documents.management.commands.document_thumbnails.shutil.move")
 | 
				
			||||||
    def test_process_document_invalid_mime_type(self, m: mock.Mock):
 | 
					    def test_process_document_invalid_mime_type(self, m: mock.Mock):
 | 
				
			||||||
        self.d1.mime_type = "asdasdasd"
 | 
					        self.d1.mime_type = "asdasdasd"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user