mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-16 00:36:22 +00:00
Feature: page count (#7750)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -389,6 +389,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
||||
title="B",
|
||||
filename=sample2,
|
||||
mime_type="application/pdf",
|
||||
page_count=8,
|
||||
)
|
||||
self.doc2.archive_filename = sample2_archive
|
||||
self.doc2.save()
|
||||
@@ -681,14 +682,20 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
||||
THEN:
|
||||
- Save should be called once
|
||||
- Archive file should be updated once
|
||||
- The document's page_count should be reduced by the number of deleted pages
|
||||
"""
|
||||
doc_ids = [self.doc2.id]
|
||||
initial_page_count = self.doc2.page_count
|
||||
pages = [1, 3]
|
||||
result = bulk_edit.delete_pages(doc_ids, pages)
|
||||
mock_pdf_save.assert_called_once()
|
||||
mock_update_archive_file.assert_called_once()
|
||||
self.assertEqual(result, "OK")
|
||||
|
||||
expected_page_count = initial_page_count - len(pages)
|
||||
self.doc2.refresh_from_db()
|
||||
self.assertEqual(self.doc2.page_count, expected_page_count)
|
||||
|
||||
@mock.patch("documents.tasks.update_document_archive_file.delay")
|
||||
@mock.patch("pikepdf.Pdf.save")
|
||||
def test_delete_pages_with_error(self, mock_pdf_save, mock_update_archive_file):
|
||||
|
59
src/documents/tests/test_migration_document_pages_count.py
Normal file
59
src/documents/tests/test_migration_document_pages_count.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from documents.tests.utils import TestMigrations
|
||||
|
||||
|
||||
def source_path_before(self):
|
||||
if self.filename:
|
||||
fname = str(self.filename)
|
||||
|
||||
return os.path.join(settings.ORIGINALS_DIR, fname)
|
||||
|
||||
|
||||
class TestMigrateDocumentPageCount(TestMigrations):
|
||||
migrate_from = "1052_document_transaction_id"
|
||||
migrate_to = "1053_document_page_count"
|
||||
|
||||
def setUpBeforeMigration(self, apps):
|
||||
Document = apps.get_model("documents", "Document")
|
||||
doc = Document.objects.create(
|
||||
title="test1",
|
||||
mime_type="application/pdf",
|
||||
filename="file1.pdf",
|
||||
)
|
||||
self.doc_id = doc.id
|
||||
shutil.copy(
|
||||
Path(__file__).parent / "samples" / "simple.pdf",
|
||||
source_path_before(doc),
|
||||
)
|
||||
|
||||
def testDocumentPageCountMigrated(self):
|
||||
Document = self.apps.get_model("documents", "Document")
|
||||
|
||||
doc = Document.objects.get(id=self.doc_id)
|
||||
self.assertEqual(doc.page_count, 1)
|
||||
|
||||
|
||||
class TestMigrateDocumentPageCountBackwards(TestMigrations):
|
||||
migrate_from = "1053_document_page_count"
|
||||
migrate_to = "1052_document_transaction_id"
|
||||
|
||||
def setUpBeforeMigration(self, apps):
|
||||
Document = apps.get_model("documents", "Document")
|
||||
doc = Document.objects.create(
|
||||
title="test1",
|
||||
mime_type="application/pdf",
|
||||
filename="file1.pdf",
|
||||
page_count=8,
|
||||
)
|
||||
self.doc_id = doc.id
|
||||
|
||||
def test_remove_number_of_pages_to_page_count(self):
|
||||
Document = self.apps.get_model("documents", "Document")
|
||||
self.assertFalse(
|
||||
"page_count" in [field.name for field in Document._meta.get_fields()],
|
||||
)
|
Reference in New Issue
Block a user