add warning about --no-archive & --no-thumbnails options

add given_when_then informaiton to tests
add use_filename_prefix test
clear documents before importing in tests
This commit is contained in:
Matthieu Helleboid 2023-01-20 19:21:43 +01:00 committed by Trenton H
parent 024921212a
commit 447edd1355
2 changed files with 68 additions and 2 deletions

View File

@ -267,13 +267,16 @@ Be careful when pointing paperless to a directory that already contains
other files. other files.
Paperless will not export archive files if you use `--no-archive`. After Paperless will not export archive files if you use `--no-archive`. After
importing, These files can be generated again by using `document_archiver`. importing, the sanity checker will warn about missing files until these files
are generated again by using `document_archiver`.
It can make sense to omit these files from backup as their content and checksum It can make sense to omit these files from backup as their content and checksum
can change (new archiver algorithm) and may then cause additional used space in can change (new archiver algorithm) and may then cause additional used space in
a deduplicated backup. a deduplicated backup.
Paperless will not export thumbnails if you use `--no-thumbnail`. After Paperless will not export thumbnails if you use `--no-thumbnail`. After
importing, These files can be generated again by using `document_thumbnails`. importing, the sanity checker will warn about missing files and the documents
view will not have thumbnails until these files are generated again by using
`document_thumbnails`.
It can make sense to omit these files from backup as their content and checksum It can make sense to omit these files from backup as their content and checksum
can change (new thumbnail generation algorithm) and may then cause additional can change (new thumbnail generation algorithm) and may then cause additional
used space in a deduplicated backup. used space in a deduplicated backup.

View File

@ -105,6 +105,7 @@ class TestExportImport(DirectoriesMixin, TestCase):
no_archive=False, no_archive=False,
no_thumbnail=False, no_thumbnail=False,
split_manifest=False, split_manifest=False,
use_filename_prefix=False,
): ):
args = ["document_exporter", self.target] args = ["document_exporter", self.target]
if use_filename_format: if use_filename_format:
@ -119,6 +120,8 @@ class TestExportImport(DirectoriesMixin, TestCase):
args += ["--no-thumbnail"] args += ["--no-thumbnail"]
if split_manifest: if split_manifest:
args += ["--split-manifest"] args += ["--split-manifest"]
if use_filename_prefix:
args += ["--use-filename-prefix"]
call_command(*args) call_command(*args)
@ -508,6 +511,15 @@ class TestExportImport(DirectoriesMixin, TestCase):
self.assertEqual("That path doesn't appear to be writable", str(e)) self.assertEqual("That path doesn't appear to be writable", str(e))
def test_no_archive(self): def test_no_archive(self):
"""
GIVEN:
- Request to export documents to directory
WHEN:
- Option no-archive is used
THEN:
- Manifest.json doesn't contain information about archive files
- Documents can be imported again
"""
shutil.rmtree(os.path.join(self.dirs.media_dir, "documents")) shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
shutil.copytree( shutil.copytree(
os.path.join(os.path.dirname(__file__), "samples", "documents"), os.path.join(os.path.dirname(__file__), "samples", "documents"),
@ -533,10 +545,22 @@ class TestExportImport(DirectoriesMixin, TestCase):
self.assertFalse(has_archive) self.assertFalse(has_archive)
with paperless_environment() as dirs: with paperless_environment() as dirs:
self.assertEqual(Document.objects.count(), 4)
Document.objects.all().delete()
self.assertEqual(Document.objects.count(), 0)
call_command("document_importer", self.target) call_command("document_importer", self.target)
self.assertEqual(Document.objects.count(), 4) self.assertEqual(Document.objects.count(), 4)
def test_no_thumbnail(self): def test_no_thumbnail(self):
"""
GIVEN:
- Request to export documents to directory
WHEN:
- Option no-thumbnails is used
THEN:
- Manifest.json doesn't contain information about thumbnails
- Documents can be imported again
"""
shutil.rmtree(os.path.join(self.dirs.media_dir, "documents")) shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
shutil.copytree( shutil.copytree(
os.path.join(os.path.dirname(__file__), "samples", "documents"), os.path.join(os.path.dirname(__file__), "samples", "documents"),
@ -564,10 +588,22 @@ class TestExportImport(DirectoriesMixin, TestCase):
self.assertFalse(has_thumbnail) self.assertFalse(has_thumbnail)
with paperless_environment() as dirs: with paperless_environment() as dirs:
self.assertEqual(Document.objects.count(), 4)
Document.objects.all().delete()
self.assertEqual(Document.objects.count(), 0)
call_command("document_importer", self.target) call_command("document_importer", self.target)
self.assertEqual(Document.objects.count(), 4) self.assertEqual(Document.objects.count(), 4)
def test_split_manifest(self): def test_split_manifest(self):
"""
GIVEN:
- Request to export documents to directory
WHEN:
- Option split_manifest is used
THEN:
- Main manifest.json file doesn't contain information about documents
- Documents can be imported again
"""
shutil.rmtree(os.path.join(self.dirs.media_dir, "documents")) shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
shutil.copytree( shutil.copytree(
os.path.join(os.path.dirname(__file__), "samples", "documents"), os.path.join(os.path.dirname(__file__), "samples", "documents"),
@ -581,5 +617,32 @@ class TestExportImport(DirectoriesMixin, TestCase):
self.assertFalse(has_document) self.assertFalse(has_document)
with paperless_environment() as dirs: with paperless_environment() as dirs:
self.assertEqual(Document.objects.count(), 4)
Document.objects.all().delete()
self.assertEqual(Document.objects.count(), 0)
call_command("document_importer", self.target)
self.assertEqual(Document.objects.count(), 4)
def test_filename_prefix(self):
"""
GIVEN:
- Request to export documents to directory
WHEN:
- Option use_filename_prefix is used
THEN:
- Documents can be imported again
"""
shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))
shutil.copytree(
os.path.join(os.path.dirname(__file__), "samples", "documents"),
os.path.join(self.dirs.media_dir, "documents"),
)
manifest = self._do_export(use_filename_prefix=True)
with paperless_environment() as dirs:
self.assertEqual(Document.objects.count(), 4)
Document.objects.all().delete()
self.assertEqual(Document.objects.count(), 0)
call_command("document_importer", self.target) call_command("document_importer", self.target)
self.assertEqual(Document.objects.count(), 4) self.assertEqual(Document.objects.count(), 4)