Basic verification of Comment export & exporter comment tuple fix

From oprhaned commits b1855a4b7a
53f21574fd

Co-Authored-By: Trenton Holmes <797416+stumpylog@users.noreply.github.com>
This commit is contained in:
Michael Shamoon 2022-08-23 22:04:27 -07:00
parent f5f2240828
commit 0f4b118b61
2 changed files with 18 additions and 5 deletions

View File

@ -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")

View File

@ -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()