From 0f4b118b61c14a00efc1b282a320a3eebe2760a6 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 23 Aug 2022 22:04:27 -0700 Subject: [PATCH] Basic verification of Comment export & exporter comment tuple fix From oprhaned commits https://github.com/paperless-ngx/paperless-ngx/commit/b1855a4b7af689d0a7c7f18bf7ef513967da269f https://github.com/paperless-ngx/paperless-ngx/commit/53f21574fd8af0f3561c12f709a14980f8f1cb7f Co-Authored-By: Trenton Holmes <797416+stumpylog@users.noreply.github.com> --- .../management/commands/document_exporter.py | 6 ++---- src/documents/tests/test_management_exporter.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/documents/management/commands/document_exporter.py b/src/documents/management/commands/document_exporter.py index 1493bf078..dc53a690e 100644 --- a/src/documents/management/commands/document_exporter.py +++ b/src/documents/management/commands/document_exporter.py @@ -127,10 +127,8 @@ class Command(BaseCommand): serializers.serialize("json", DocumentType.objects.all()), ) - manifest += ( - json.loads( - serializers.serialize("json", Comment.objects.all()), - ), + manifest += json.loads( + serializers.serialize("json", Comment.objects.all()), ) documents = Document.objects.order_by("id") diff --git a/src/documents/tests/test_management_exporter.py b/src/documents/tests/test_management_exporter.py index a9dcabc4d..92f1d3b62 100644 --- a/src/documents/tests/test_management_exporter.py +++ b/src/documents/tests/test_management_exporter.py @@ -10,10 +10,12 @@ from django.core.management import call_command from django.test import override_settings from django.test import TestCase from documents.management.commands import document_exporter +from documents.models import Comment from documents.models import Correspondent from documents.models import Document from documents.models import DocumentType from documents.models import Tag +from documents.models import User from documents.sanity_checker import check_sanity from documents.settings import EXPORTER_FILE_NAME from documents.tests.utils import DirectoriesMixin @@ -25,6 +27,8 @@ class TestExportImport(DirectoriesMixin, TestCase): self.target = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.target) + self.user = User.objects.create(username="temp_admin") + self.d1 = Document.objects.create( content="Content", checksum="42995833e01aea9b3edee44bbfdd7ce1", @@ -57,6 +61,12 @@ class TestExportImport(DirectoriesMixin, TestCase): storage_type=Document.STORAGE_TYPE_GPG, ) + self.comment = Comment.objects.create( + comment="This is a comment. amaze.", + document=self.d1, + user=self.user, + ) + self.t1 = Tag.objects.create(name="t") self.dt1 = DocumentType.objects.create(name="dt") self.c1 = Correspondent.objects.create(name="c") @@ -110,7 +120,7 @@ class TestExportImport(DirectoriesMixin, TestCase): manifest = self._do_export(use_filename_format=use_filename_format) - self.assertEqual(len(manifest), 8) + self.assertEqual(len(manifest), 10) self.assertEqual( len(list(filter(lambda e: e["model"] == "documents.document", manifest))), 4, @@ -171,6 +181,11 @@ class TestExportImport(DirectoriesMixin, TestCase): checksum = hashlib.md5(f.read()).hexdigest() self.assertEqual(checksum, element["fields"]["archive_checksum"]) + elif element["model"] == "documents.comment": + self.assertEqual(element["fields"]["comment"], self.comment.comment) + self.assertEqual(element["fields"]["document"], self.d1.id) + self.assertEqual(element["fields"]["user"], self.user.id) + with paperless_environment() as dirs: self.assertEqual(Document.objects.count(), 4) Document.objects.all().delete()