From 1709aee903a586203e6654a22ab997aa82f441fe Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Fri, 12 Sep 2025 16:42:52 -0700
Subject: [PATCH 2/2] Development: fix localization failing tests (#10840)
---------
Co-authored-by: Trenton H <797416+stumpylog@users.noreply.github.com>
---
src/documents/tests/test_document_model.py | 7 +-
src/documents/tests/test_management.py | 88 ++++++++++------------
src/documents/tests/test_workflows.py | 6 +-
3 files changed, 51 insertions(+), 50 deletions(-)
diff --git a/src/documents/tests/test_document_model.py b/src/documents/tests/test_document_model.py
index fc4f17e04..46b16d727 100644
--- a/src/documents/tests/test_document_model.py
+++ b/src/documents/tests/test_document_model.py
@@ -18,14 +18,17 @@ class TestDocument(TestCase):
self.originals_dir = tempfile.mkdtemp()
self.thumb_dir = tempfile.mkdtemp()
- override_settings(
+ self.overrides = override_settings(
ORIGINALS_DIR=self.originals_dir,
THUMBNAIL_DIR=self.thumb_dir,
- ).enable()
+ )
+
+ self.overrides.enable()
def tearDown(self) -> None:
shutil.rmtree(self.originals_dir)
shutil.rmtree(self.thumb_dir)
+ self.overrides.disable()
def test_file_deletion(self):
document = Document.objects.create(
diff --git a/src/documents/tests/test_management.py b/src/documents/tests/test_management.py
index 0a51b71e1..014f5d673 100644
--- a/src/documents/tests/test_management.py
+++ b/src/documents/tests/test_management.py
@@ -97,12 +97,6 @@ class TestArchiver(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
class TestDecryptDocuments(FileSystemAssertsMixin, TestCase):
- @override_settings(
- ORIGINALS_DIR=(Path(__file__).parent / "samples" / "originals"),
- THUMBNAIL_DIR=(Path(__file__).parent / "samples" / "thumb"),
- PASSPHRASE="test",
- FILENAME_FORMAT=None,
- )
@mock.patch("documents.management.commands.decrypt_documents.input")
def test_decrypt(self, m):
media_dir = tempfile.mkdtemp()
@@ -111,55 +105,55 @@ class TestDecryptDocuments(FileSystemAssertsMixin, TestCase):
originals_dir.mkdir(parents=True, exist_ok=True)
thumb_dir.mkdir(parents=True, exist_ok=True)
- override_settings(
+ with override_settings(
ORIGINALS_DIR=originals_dir,
THUMBNAIL_DIR=thumb_dir,
PASSPHRASE="test",
- ).enable()
+ FILENAME_FORMAT=None,
+ ):
+ doc = Document.objects.create(
+ checksum="82186aaa94f0b98697d704b90fd1c072",
+ title="wow",
+ filename="0000004.pdf.gpg",
+ mime_type="application/pdf",
+ storage_type=Document.STORAGE_TYPE_GPG,
+ )
- doc = Document.objects.create(
- checksum="82186aaa94f0b98697d704b90fd1c072",
- title="wow",
- filename="0000004.pdf.gpg",
- mime_type="application/pdf",
- storage_type=Document.STORAGE_TYPE_GPG,
- )
+ shutil.copy(
+ (
+ Path(__file__).parent
+ / "samples"
+ / "documents"
+ / "originals"
+ / "0000004.pdf.gpg"
+ ),
+ originals_dir / "0000004.pdf.gpg",
+ )
+ shutil.copy(
+ (
+ Path(__file__).parent
+ / "samples"
+ / "documents"
+ / "thumbnails"
+ / "0000004.webp.gpg"
+ ),
+ thumb_dir / f"{doc.id:07}.webp.gpg",
+ )
- shutil.copy(
- (
- Path(__file__).parent
- / "samples"
- / "documents"
- / "originals"
- / "0000004.pdf.gpg"
- ),
- originals_dir / "0000004.pdf.gpg",
- )
- shutil.copy(
- (
- Path(__file__).parent
- / "samples"
- / "documents"
- / "thumbnails"
- / "0000004.webp.gpg"
- ),
- thumb_dir / f"{doc.id:07}.webp.gpg",
- )
+ call_command("decrypt_documents")
- call_command("decrypt_documents")
+ doc.refresh_from_db()
- doc.refresh_from_db()
+ self.assertEqual(doc.storage_type, Document.STORAGE_TYPE_UNENCRYPTED)
+ self.assertEqual(doc.filename, "0000004.pdf")
+ self.assertIsFile(Path(originals_dir) / "0000004.pdf")
+ self.assertIsFile(doc.source_path)
+ self.assertIsFile(Path(thumb_dir) / f"{doc.id:07}.webp")
+ self.assertIsFile(doc.thumbnail_path)
- self.assertEqual(doc.storage_type, Document.STORAGE_TYPE_UNENCRYPTED)
- self.assertEqual(doc.filename, "0000004.pdf")
- self.assertIsFile(Path(originals_dir) / "0000004.pdf")
- self.assertIsFile(doc.source_path)
- self.assertIsFile(Path(thumb_dir) / f"{doc.id:07}.webp")
- self.assertIsFile(doc.thumbnail_path)
-
- with doc.source_file as f:
- checksum: str = hashlib.md5(f.read()).hexdigest()
- self.assertEqual(checksum, doc.checksum)
+ with doc.source_file as f:
+ checksum: str = hashlib.md5(f.read()).hexdigest()
+ self.assertEqual(checksum, doc.checksum)
class TestMakeIndex(TestCase):
diff --git a/src/documents/tests/test_workflows.py b/src/documents/tests/test_workflows.py
index fe5c4ff7d..7652d22b5 100644
--- a/src/documents/tests/test_workflows.py
+++ b/src/documents/tests/test_workflows.py
@@ -3410,8 +3410,8 @@ class TestDateWorkflowLocalization(
w.actions.add(action)
w.save()
- settings.SCRATCH_DIR = tmp_path / "scratch"
(tmp_path / "scratch").mkdir(parents=True, exist_ok=True)
+ (tmp_path / "thumbnails").mkdir(parents=True, exist_ok=True)
# Temporarily override "now" for the environment so templates using
# added/created placeholders behave as if it's a different system date.
@@ -3424,6 +3424,10 @@ class TestDateWorkflowLocalization(
"django.utils.timezone.now",
return_value=self.TEST_DATETIME,
),
+ override_settings(
+ SCRATCH_DIR=tmp_path / "scratch",
+ THUMBNAIL_DIR=tmp_path / "thumbnails",
+ ),
):
tasks.consume_file(
ConsumableDocument(