paperless-ngx/src/documents/tests/test_migration_archive_files.py

577 lines
16 KiB
Python
Raw Normal View History

2021-02-08 20:59:14 +01:00
import hashlib
import os
import shutil
from pathlib import Path
from typing import Optional
2021-02-10 16:58:55 +01:00
from unittest import mock
2021-02-08 20:59:14 +01:00
from django.conf import settings
from django.test import override_settings
2021-02-10 16:58:55 +01:00
from documents.parsers import ParseError
from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import FileSystemAssertsMixin
from documents.tests.utils import TestMigrations
2021-02-08 20:59:14 +01:00
STORAGE_TYPE_GPG = "gpg"
2021-02-09 19:49:29 +01:00
def archive_name_from_filename(filename):
2021-02-08 20:59:14 +01:00
return os.path.splitext(filename)[0] + ".pdf"
def archive_path_old(self):
if self.filename:
2021-02-09 19:49:29 +01:00
fname = archive_name_from_filename(self.filename)
2021-02-08 20:59:14 +01:00
else:
fname = f"{self.pk:07}.pdf"
2021-02-08 20:59:14 +01:00
2022-02-27 15:26:41 +01:00
return os.path.join(settings.ARCHIVE_DIR, fname)
2021-02-08 20:59:14 +01:00
2021-02-09 19:49:29 +01:00
def archive_path_new(doc):
2022-02-27 15:26:41 +01:00
if doc.archive_filename is not None:
return os.path.join(settings.ARCHIVE_DIR, str(doc.archive_filename))
else:
return None
2021-02-08 20:59:14 +01:00
def source_path(doc):
if doc.filename:
fname = str(doc.filename)
else:
fname = f"{doc.pk:07}{doc.file_type}"
2021-02-08 20:59:14 +01:00
if doc.storage_type == STORAGE_TYPE_GPG:
fname += ".gpg" # pragma: no cover
2022-02-27 15:26:41 +01:00
return os.path.join(settings.ORIGINALS_DIR, fname)
2021-02-08 20:59:14 +01:00
def thumbnail_path(doc):
file_name = f"{doc.pk:07}.png"
2021-02-08 20:59:14 +01:00
if doc.storage_type == STORAGE_TYPE_GPG:
file_name += ".gpg"
2022-02-27 15:26:41 +01:00
return os.path.join(settings.THUMBNAIL_DIR, file_name)
2021-02-08 20:59:14 +01:00
2022-02-27 15:26:41 +01:00
def make_test_document(
document_class,
title: str,
mime_type: str,
original: str,
original_filename: str,
archive: Optional[str] = None,
archive_filename: Optional[str] = None,
2022-02-27 15:26:41 +01:00
):
2021-02-08 20:59:14 +01:00
doc = document_class()
2021-02-09 19:49:29 +01:00
doc.filename = original_filename
2021-02-08 20:59:14 +01:00
doc.title = title
doc.mime_type = mime_type
doc.content = "the content, does not matter for this test"
2021-02-09 19:49:29 +01:00
doc.save()
2021-02-08 20:59:14 +01:00
shutil.copy2(original, source_path(doc))
with open(original, "rb") as f:
doc.checksum = hashlib.md5(f.read()).hexdigest()
if archive:
2021-02-09 19:49:29 +01:00
if archive_filename:
doc.archive_filename = archive_filename
2021-02-08 20:59:14 +01:00
shutil.copy2(archive, archive_path_new(doc))
else:
shutil.copy2(archive, archive_path_old(doc))
2021-02-09 19:49:29 +01:00
2021-02-08 20:59:14 +01:00
with open(archive, "rb") as f:
doc.archive_checksum = hashlib.md5(f.read()).hexdigest()
doc.save()
Path(thumbnail_path(doc)).touch()
return doc
2021-02-09 19:49:29 +01:00
simple_jpg = os.path.join(os.path.dirname(__file__), "samples", "simple.jpg")
simple_pdf = os.path.join(os.path.dirname(__file__), "samples", "simple.pdf")
2022-02-27 15:26:41 +01:00
simple_pdf2 = os.path.join(
os.path.dirname(__file__),
"samples",
"documents",
"originals",
"0000002.pdf",
2022-02-27 15:26:41 +01:00
)
simple_pdf3 = os.path.join(
os.path.dirname(__file__),
"samples",
"documents",
"originals",
"0000003.pdf",
2022-02-27 15:26:41 +01:00
)
2021-02-09 19:49:29 +01:00
simple_txt = os.path.join(os.path.dirname(__file__), "samples", "simple.txt")
simple_png = os.path.join(os.path.dirname(__file__), "samples", "simple-noalpha.png")
2021-02-10 01:31:15 +01:00
simple_png2 = os.path.join(os.path.dirname(__file__), "examples", "no-text.png")
2021-02-09 19:49:29 +01:00
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
@override_settings(FILENAME_FORMAT="")
class TestMigrateArchiveFiles(DirectoriesMixin, FileSystemAssertsMixin, TestMigrations):
2022-02-27 15:26:41 +01:00
migrate_from = "1011_auto_20210101_2340"
migrate_to = "1012_fix_archive_files"
2021-02-08 20:59:14 +01:00
def setUpBeforeMigration(self, apps):
Document = apps.get_model("documents", "Document")
2022-02-27 15:26:41 +01:00
self.unrelated = make_test_document(
Document,
"unrelated",
"application/pdf",
simple_pdf3,
"unrelated.pdf",
simple_pdf,
)
self.no_text = make_test_document(
Document,
"no-text",
"image/png",
simple_png2,
"no-text.png",
simple_pdf,
2022-02-27 15:26:41 +01:00
)
self.doc_no_archive = make_test_document(
Document,
"no_archive",
"text/plain",
simple_txt,
"no_archive.txt",
2022-02-27 15:26:41 +01:00
)
self.clash1 = make_test_document(
Document,
"clash",
"application/pdf",
simple_pdf,
"clash.pdf",
simple_pdf,
2022-02-27 15:26:41 +01:00
)
self.clash2 = make_test_document(
Document,
"clash",
"image/jpeg",
simple_jpg,
"clash.jpg",
simple_pdf,
2022-02-27 15:26:41 +01:00
)
self.clash3 = make_test_document(
Document,
"clash",
"image/png",
simple_png,
"clash.png",
simple_pdf,
2022-02-27 15:26:41 +01:00
)
self.clash4 = make_test_document(
Document,
"clash.png",
"application/pdf",
simple_pdf2,
"clash.png.pdf",
simple_pdf2,
)
2021-02-08 20:59:14 +01:00
2021-02-09 20:54:02 +01:00
self.assertEqual(archive_path_old(self.clash1), archive_path_old(self.clash2))
self.assertEqual(archive_path_old(self.clash1), archive_path_old(self.clash3))
2022-02-27 15:26:41 +01:00
self.assertNotEqual(
archive_path_old(self.clash1),
archive_path_old(self.clash4),
2022-02-27 15:26:41 +01:00
)
2021-02-08 20:59:14 +01:00
def testArchiveFilesMigrated(self):
2022-02-27 15:26:41 +01:00
Document = self.apps.get_model("documents", "Document")
2021-02-08 20:59:14 +01:00
for doc in Document.objects.all():
2021-02-09 19:49:29 +01:00
if doc.archive_checksum:
self.assertIsNotNone(doc.archive_filename)
self.assertIsFile(archive_path_new(doc))
2021-02-09 19:49:29 +01:00
else:
self.assertIsNone(doc.archive_filename)
2021-02-08 20:59:14 +01:00
with open(source_path(doc), "rb") as f:
original_checksum = hashlib.md5(f.read()).hexdigest()
self.assertEqual(original_checksum, doc.checksum)
if doc.archive_checksum:
self.assertIsFile(archive_path_new(doc))
2021-02-08 20:59:14 +01:00
with open(archive_path_new(doc), "rb") as f:
archive_checksum = hashlib.md5(f.read()).hexdigest()
self.assertEqual(archive_checksum, doc.archive_checksum)
2022-02-27 15:26:41 +01:00
self.assertEqual(
Document.objects.filter(archive_checksum__isnull=False).count(),
6,
2022-02-27 15:26:41 +01:00
)
2021-02-09 00:13:13 +01:00
2021-02-09 20:54:02 +01:00
def test_filenames(self):
2022-02-27 15:26:41 +01:00
Document = self.apps.get_model("documents", "Document")
self.assertEqual(
Document.objects.get(id=self.unrelated.id).archive_filename,
"unrelated.pdf",
2022-02-27 15:26:41 +01:00
)
self.assertEqual(
Document.objects.get(id=self.no_text.id).archive_filename,
"no-text.pdf",
2022-02-27 15:26:41 +01:00
)
self.assertEqual(
Document.objects.get(id=self.doc_no_archive.id).archive_filename,
None,
2022-02-27 15:26:41 +01:00
)
self.assertEqual(
Document.objects.get(id=self.clash1.id).archive_filename,
f"{self.clash1.id:07}.pdf",
)
self.assertEqual(
Document.objects.get(id=self.clash2.id).archive_filename,
f"{self.clash2.id:07}.pdf",
)
self.assertEqual(
Document.objects.get(id=self.clash3.id).archive_filename,
f"{self.clash3.id:07}.pdf",
)
self.assertEqual(
Document.objects.get(id=self.clash4.id).archive_filename,
"clash.png.pdf",
2022-02-27 15:26:41 +01:00
)
2021-02-09 20:54:02 +01:00
2021-02-08 20:59:14 +01:00
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
@override_settings(FILENAME_FORMAT="{correspondent}/{title}")
2021-02-09 19:49:29 +01:00
class TestMigrateArchiveFilesWithFilenameFormat(TestMigrateArchiveFiles):
2021-02-09 20:54:02 +01:00
def test_filenames(self):
2022-02-27 15:26:41 +01:00
Document = self.apps.get_model("documents", "Document")
self.assertEqual(
Document.objects.get(id=self.unrelated.id).archive_filename,
"unrelated.pdf",
2022-02-27 15:26:41 +01:00
)
self.assertEqual(
Document.objects.get(id=self.no_text.id).archive_filename,
"no-text.pdf",
2022-02-27 15:26:41 +01:00
)
self.assertEqual(
Document.objects.get(id=self.doc_no_archive.id).archive_filename,
None,
2022-02-27 15:26:41 +01:00
)
self.assertEqual(
Document.objects.get(id=self.clash1.id).archive_filename,
"none/clash.pdf",
2022-02-27 15:26:41 +01:00
)
self.assertEqual(
Document.objects.get(id=self.clash2.id).archive_filename,
"none/clash_01.pdf",
)
self.assertEqual(
Document.objects.get(id=self.clash3.id).archive_filename,
"none/clash_02.pdf",
)
self.assertEqual(
Document.objects.get(id=self.clash4.id).archive_filename,
"clash.png.pdf",
2022-02-27 15:26:41 +01:00
)
2021-02-08 20:59:14 +01:00
2021-02-09 19:49:29 +01:00
2021-02-10 16:58:55 +01:00
def fake_parse_wrapper(parser, path, mime_type, file_name):
parser.archive_path = None
parser.text = "the text"
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
@override_settings(FILENAME_FORMAT="")
2021-02-10 01:31:15 +01:00
class TestMigrateArchiveFilesErrors(DirectoriesMixin, TestMigrations):
2022-02-27 15:26:41 +01:00
migrate_from = "1011_auto_20210101_2340"
migrate_to = "1012_fix_archive_files"
2021-02-10 01:31:15 +01:00
auto_migrate = False
def test_archive_missing(self):
Document = self.apps.get_model("documents", "Document")
2022-02-27 15:26:41 +01:00
doc = make_test_document(
Document,
"clash",
"application/pdf",
simple_pdf,
"clash.pdf",
simple_pdf,
2022-02-27 15:26:41 +01:00
)
2021-02-10 01:31:15 +01:00
os.unlink(archive_path_old(doc))
2022-02-27 15:26:41 +01:00
self.assertRaisesMessage(
ValueError,
"does not exist at: ",
self.performMigration,
2022-02-27 15:26:41 +01:00
)
2021-02-10 01:31:15 +01:00
2021-02-10 16:58:55 +01:00
def test_parser_missing(self):
Document = self.apps.get_model("documents", "Document")
make_test_document(
2022-02-27 15:26:41 +01:00
Document,
"document",
"invalid/typesss768",
simple_png,
"document.png",
simple_pdf,
)
make_test_document(
2022-02-27 15:26:41 +01:00
Document,
"document",
"invalid/typesss768",
simple_jpg,
"document.jpg",
simple_pdf,
)
self.assertRaisesMessage(
ValueError,
"no parsers are available",
self.performMigration,
2022-02-27 15:26:41 +01:00
)
2021-02-10 16:58:55 +01:00
@mock.patch("documents.migrations.1012_fix_archive_files.parse_wrapper")
def test_parser_error(self, m):
m.side_effect = ParseError()
Document = self.apps.get_model("documents", "Document")
2022-02-27 15:26:41 +01:00
doc1 = make_test_document(
Document,
"document",
"image/png",
simple_png,
"document.png",
simple_pdf,
2022-02-27 15:26:41 +01:00
)
doc2 = make_test_document(
Document,
"document",
"application/pdf",
simple_jpg,
"document.jpg",
simple_pdf,
)
2021-02-10 16:58:55 +01:00
self.assertIsNotNone(doc1.archive_checksum)
self.assertIsNotNone(doc2.archive_checksum)
with self.assertLogs() as capture:
self.performMigration()
self.assertEqual(m.call_count, 6)
self.assertEqual(
2022-02-27 15:26:41 +01:00
len(
list(
filter(
lambda log: "Parse error, will try again in 5 seconds" in log,
capture.output,
),
),
2022-02-27 15:26:41 +01:00
),
4,
)
2021-02-10 16:58:55 +01:00
self.assertEqual(
2022-02-27 15:26:41 +01:00
len(
list(
filter(
lambda log: "Unable to regenerate archive document for ID:"
in log,
capture.output,
),
),
2022-02-27 15:26:41 +01:00
),
2,
)
2021-02-10 16:58:55 +01:00
Document = self.apps.get_model("documents", "Document")
doc1 = Document.objects.get(id=doc1.id)
doc2 = Document.objects.get(id=doc2.id)
self.assertIsNone(doc1.archive_checksum)
self.assertIsNone(doc2.archive_checksum)
self.assertIsNone(doc1.archive_filename)
self.assertIsNone(doc2.archive_filename)
@mock.patch("documents.migrations.1012_fix_archive_files.parse_wrapper")
def test_parser_no_archive(self, m):
m.side_effect = fake_parse_wrapper
Document = self.apps.get_model("documents", "Document")
2022-02-27 15:26:41 +01:00
doc1 = make_test_document(
Document,
"document",
"image/png",
simple_png,
"document.png",
simple_pdf,
2022-02-27 15:26:41 +01:00
)
doc2 = make_test_document(
Document,
"document",
"application/pdf",
simple_jpg,
"document.jpg",
simple_pdf,
)
2021-02-10 16:58:55 +01:00
with self.assertLogs() as capture:
self.performMigration()
self.assertEqual(
2022-02-27 15:26:41 +01:00
len(
list(
filter(
lambda log: "Parser did not return an archive document for document"
in log,
capture.output,
),
),
2022-02-27 15:26:41 +01:00
),
2,
)
2021-02-10 16:58:55 +01:00
Document = self.apps.get_model("documents", "Document")
doc1 = Document.objects.get(id=doc1.id)
doc2 = Document.objects.get(id=doc2.id)
self.assertIsNone(doc1.archive_checksum)
self.assertIsNone(doc2.archive_checksum)
self.assertIsNone(doc1.archive_filename)
self.assertIsNone(doc2.archive_filename)
2021-02-10 01:31:15 +01:00
2021-02-11 13:47:17 +01:00
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
@override_settings(FILENAME_FORMAT="")
class TestMigrateArchiveFilesBackwards(
DirectoriesMixin,
FileSystemAssertsMixin,
TestMigrations,
):
2022-02-27 15:26:41 +01:00
migrate_from = "1012_fix_archive_files"
migrate_to = "1011_auto_20210101_2340"
2021-02-08 20:59:14 +01:00
def setUpBeforeMigration(self, apps):
Document = apps.get_model("documents", "Document")
make_test_document(
2022-02-27 15:26:41 +01:00
Document,
"unrelated",
"application/pdf",
simple_pdf2,
"unrelated.txt",
simple_pdf2,
"unrelated.pdf",
)
make_test_document(
Document,
"no_archive",
"text/plain",
simple_txt,
"no_archive.txt",
2022-02-27 15:26:41 +01:00
)
make_test_document(
2022-02-27 15:26:41 +01:00
Document,
"clash",
"image/jpeg",
simple_jpg,
"clash.jpg",
simple_pdf,
"clash_02.pdf",
)
2021-02-08 20:59:14 +01:00
def testArchiveFilesReverted(self):
2022-02-27 15:26:41 +01:00
Document = self.apps.get_model("documents", "Document")
2021-02-08 20:59:14 +01:00
for doc in Document.objects.all():
2021-02-09 19:49:29 +01:00
if doc.archive_checksum:
self.assertIsFile(archive_path_old(doc))
2021-02-08 20:59:14 +01:00
with open(source_path(doc), "rb") as f:
original_checksum = hashlib.md5(f.read()).hexdigest()
self.assertEqual(original_checksum, doc.checksum)
if doc.archive_checksum:
self.assertIsFile(archive_path_old(doc))
2021-02-08 20:59:14 +01:00
with open(archive_path_old(doc), "rb") as f:
archive_checksum = hashlib.md5(f.read()).hexdigest()
self.assertEqual(archive_checksum, doc.archive_checksum)
2021-02-09 19:49:29 +01:00
2022-02-27 15:26:41 +01:00
self.assertEqual(
Document.objects.filter(archive_checksum__isnull=False).count(),
2,
2022-02-27 15:26:41 +01:00
)
2021-02-09 19:49:29 +01:00
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
@override_settings(FILENAME_FORMAT="{correspondent}/{title}")
2022-02-27 15:26:41 +01:00
class TestMigrateArchiveFilesBackwardsWithFilenameFormat(
TestMigrateArchiveFilesBackwards,
2022-02-27 15:26:41 +01:00
):
2021-02-09 19:49:29 +01:00
pass
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
@override_settings(FILENAME_FORMAT="")
2021-02-09 19:49:29 +01:00
class TestMigrateArchiveFilesBackwardsErrors(DirectoriesMixin, TestMigrations):
2022-02-27 15:26:41 +01:00
migrate_from = "1012_fix_archive_files"
migrate_to = "1011_auto_20210101_2340"
2021-02-09 19:49:29 +01:00
auto_migrate = False
def test_filename_clash(self):
Document = self.apps.get_model("documents", "Document")
2022-02-27 15:26:41 +01:00
self.clashA = make_test_document(
Document,
"clash",
"application/pdf",
simple_pdf,
"clash.pdf",
simple_pdf,
"clash_02.pdf",
)
self.clashB = make_test_document(
Document,
"clash",
"image/jpeg",
simple_jpg,
"clash.jpg",
simple_pdf,
"clash_01.pdf",
)
self.assertRaisesMessage(
ValueError,
"would clash with another archive filename",
self.performMigration,
)
2021-02-09 19:49:29 +01:00
def test_filename_exists(self):
Document = self.apps.get_model("documents", "Document")
2022-02-27 15:26:41 +01:00
self.clashA = make_test_document(
Document,
"clash",
"application/pdf",
simple_pdf,
"clash.pdf",
simple_pdf,
"clash.pdf",
)
self.clashB = make_test_document(
Document,
"clash",
"image/jpeg",
simple_jpg,
"clash.jpg",
simple_pdf,
"clash_01.pdf",
)
self.assertRaisesMessage(
ValueError,
"file already exists.",
self.performMigration,
2022-02-27 15:26:41 +01:00
)