Include storage path in exporter + tests

This commit is contained in:
Michael Shamoon 2022-09-10 18:48:18 -07:00 committed by Trenton Holmes
parent 962d0ebb40
commit 15d074d39c
2 changed files with 13 additions and 3 deletions

View File

@ -18,6 +18,7 @@ from documents.models import Document
from documents.models import DocumentType from documents.models import DocumentType
from documents.models import SavedView from documents.models import SavedView
from documents.models import SavedViewFilterRule from documents.models import SavedViewFilterRule
from documents.models import StoragePath
from documents.models import Tag from documents.models import Tag
from documents.models import UiSettings from documents.models import UiSettings
from documents.settings import EXPORTER_ARCHIVE_NAME from documents.settings import EXPORTER_ARCHIVE_NAME
@ -114,8 +115,8 @@ class Command(BaseCommand):
map(lambda f: os.path.abspath(os.path.join(root, f)), files), map(lambda f: os.path.abspath(os.path.join(root, f)), files),
) )
# 2. Create manifest, containing all correspondents, types, tags, # 2. Create manifest, containing all correspondents, types, tags, storage paths
# documents and ui_settings # comments, documents and ui_settings
with transaction.atomic(): with transaction.atomic():
manifest = json.loads( manifest = json.loads(
serializers.serialize("json", Correspondent.objects.all()), serializers.serialize("json", Correspondent.objects.all()),
@ -127,6 +128,10 @@ class Command(BaseCommand):
serializers.serialize("json", DocumentType.objects.all()), serializers.serialize("json", DocumentType.objects.all()),
) )
manifest += json.loads(
serializers.serialize("json", StoragePath.objects.all()),
)
manifest += json.loads( manifest += json.loads(
serializers.serialize("json", Comment.objects.all()), serializers.serialize("json", Comment.objects.all()),
) )

View File

@ -14,6 +14,7 @@ from documents.models import Comment
from documents.models import Correspondent from documents.models import Correspondent
from documents.models import Document from documents.models import Document
from documents.models import DocumentType from documents.models import DocumentType
from documents.models import StoragePath
from documents.models import Tag from documents.models import Tag
from documents.models import User from documents.models import User
from documents.sanity_checker import check_sanity from documents.sanity_checker import check_sanity
@ -70,11 +71,14 @@ class TestExportImport(DirectoriesMixin, TestCase):
self.t1 = Tag.objects.create(name="t") self.t1 = Tag.objects.create(name="t")
self.dt1 = DocumentType.objects.create(name="dt") self.dt1 = DocumentType.objects.create(name="dt")
self.c1 = Correspondent.objects.create(name="c") self.c1 = Correspondent.objects.create(name="c")
self.sp1 = StoragePath.objects.create(path="{created_year}-{title}")
self.d1.tags.add(self.t1) self.d1.tags.add(self.t1)
self.d1.correspondent = self.c1 self.d1.correspondent = self.c1
self.d1.document_type = self.dt1 self.d1.document_type = self.dt1
self.d1.save() self.d1.save()
self.d4.storage_path = self.sp1
self.d4.save()
super().setUp() super().setUp()
def _get_document_from_manifest(self, manifest, id): def _get_document_from_manifest(self, manifest, id):
@ -120,7 +124,7 @@ class TestExportImport(DirectoriesMixin, TestCase):
manifest = self._do_export(use_filename_format=use_filename_format) manifest = self._do_export(use_filename_format=use_filename_format)
self.assertEqual(len(manifest), 10) self.assertEqual(len(manifest), 11)
self.assertEqual( self.assertEqual(
len(list(filter(lambda e: e["model"] == "documents.document", manifest))), len(list(filter(lambda e: e["model"] == "documents.document", manifest))),
4, 4,
@ -199,6 +203,7 @@ class TestExportImport(DirectoriesMixin, TestCase):
self.assertEqual(Tag.objects.count(), 1) self.assertEqual(Tag.objects.count(), 1)
self.assertEqual(Correspondent.objects.count(), 1) self.assertEqual(Correspondent.objects.count(), 1)
self.assertEqual(DocumentType.objects.count(), 1) self.assertEqual(DocumentType.objects.count(), 1)
self.assertEqual(StoragePath.objects.count(), 1)
self.assertEqual(Document.objects.get(id=self.d1.id).title, "wow1") self.assertEqual(Document.objects.get(id=self.d1.id).title, "wow1")
self.assertEqual(Document.objects.get(id=self.d2.id).title, "wow2") self.assertEqual(Document.objects.get(id=self.d2.id).title, "wow2")
self.assertEqual(Document.objects.get(id=self.d3.id).title, "wow2") self.assertEqual(Document.objects.get(id=self.d3.id).title, "wow2")