mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-16 21:55:37 -05:00
Development: fix localization failing tests (#10840)
--------- Co-authored-by: Trenton H <797416+stumpylog@users.noreply.github.com>
This commit is contained in:
@@ -18,14 +18,17 @@ class TestDocument(TestCase):
|
|||||||
self.originals_dir = tempfile.mkdtemp()
|
self.originals_dir = tempfile.mkdtemp()
|
||||||
self.thumb_dir = tempfile.mkdtemp()
|
self.thumb_dir = tempfile.mkdtemp()
|
||||||
|
|
||||||
override_settings(
|
self.overrides = override_settings(
|
||||||
ORIGINALS_DIR=self.originals_dir,
|
ORIGINALS_DIR=self.originals_dir,
|
||||||
THUMBNAIL_DIR=self.thumb_dir,
|
THUMBNAIL_DIR=self.thumb_dir,
|
||||||
).enable()
|
)
|
||||||
|
|
||||||
|
self.overrides.enable()
|
||||||
|
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
shutil.rmtree(self.originals_dir)
|
shutil.rmtree(self.originals_dir)
|
||||||
shutil.rmtree(self.thumb_dir)
|
shutil.rmtree(self.thumb_dir)
|
||||||
|
self.overrides.disable()
|
||||||
|
|
||||||
def test_file_deletion(self):
|
def test_file_deletion(self):
|
||||||
document = Document.objects.create(
|
document = Document.objects.create(
|
||||||
|
@@ -97,12 +97,6 @@ class TestArchiver(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestDecryptDocuments(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")
|
@mock.patch("documents.management.commands.decrypt_documents.input")
|
||||||
def test_decrypt(self, m):
|
def test_decrypt(self, m):
|
||||||
media_dir = tempfile.mkdtemp()
|
media_dir = tempfile.mkdtemp()
|
||||||
@@ -111,55 +105,55 @@ class TestDecryptDocuments(FileSystemAssertsMixin, TestCase):
|
|||||||
originals_dir.mkdir(parents=True, exist_ok=True)
|
originals_dir.mkdir(parents=True, exist_ok=True)
|
||||||
thumb_dir.mkdir(parents=True, exist_ok=True)
|
thumb_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
override_settings(
|
with override_settings(
|
||||||
ORIGINALS_DIR=originals_dir,
|
ORIGINALS_DIR=originals_dir,
|
||||||
THUMBNAIL_DIR=thumb_dir,
|
THUMBNAIL_DIR=thumb_dir,
|
||||||
PASSPHRASE="test",
|
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(
|
shutil.copy(
|
||||||
checksum="82186aaa94f0b98697d704b90fd1c072",
|
(
|
||||||
title="wow",
|
Path(__file__).parent
|
||||||
filename="0000004.pdf.gpg",
|
/ "samples"
|
||||||
mime_type="application/pdf",
|
/ "documents"
|
||||||
storage_type=Document.STORAGE_TYPE_GPG,
|
/ "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(
|
call_command("decrypt_documents")
|
||||||
(
|
|
||||||
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")
|
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)
|
with doc.source_file as f:
|
||||||
self.assertEqual(doc.filename, "0000004.pdf")
|
checksum: str = hashlib.md5(f.read()).hexdigest()
|
||||||
self.assertIsFile(Path(originals_dir) / "0000004.pdf")
|
self.assertEqual(checksum, doc.checksum)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class TestMakeIndex(TestCase):
|
class TestMakeIndex(TestCase):
|
||||||
|
@@ -3410,8 +3410,8 @@ class TestDateWorkflowLocalization(
|
|||||||
w.actions.add(action)
|
w.actions.add(action)
|
||||||
w.save()
|
w.save()
|
||||||
|
|
||||||
settings.SCRATCH_DIR = tmp_path / "scratch"
|
|
||||||
(tmp_path / "scratch").mkdir(parents=True, exist_ok=True)
|
(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
|
# Temporarily override "now" for the environment so templates using
|
||||||
# added/created placeholders behave as if it's a different system date.
|
# added/created placeholders behave as if it's a different system date.
|
||||||
@@ -3424,6 +3424,10 @@ class TestDateWorkflowLocalization(
|
|||||||
"django.utils.timezone.now",
|
"django.utils.timezone.now",
|
||||||
return_value=self.TEST_DATETIME,
|
return_value=self.TEST_DATETIME,
|
||||||
),
|
),
|
||||||
|
override_settings(
|
||||||
|
SCRATCH_DIR=tmp_path / "scratch",
|
||||||
|
THUMBNAIL_DIR=tmp_path / "thumbnails",
|
||||||
|
),
|
||||||
):
|
):
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
|
Reference in New Issue
Block a user