From 954951026722f59a7b9d988d8f01d34c2fb24096 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 29 Aug 2019 18:39:43 +0200 Subject: Restoration: restore types --- ishtar_common/tests.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'ishtar_common/tests.py') diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 03c2ad03a..e292ae097 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -632,16 +632,30 @@ class SerializationTest(TestCase): restore_serialized(zip_filename) def test_type_restore(self): + models.AuthorType.objects.create(label="Test", txt_idx="test") + zip_filename = type_serialization(archive=True) - initial_count = {} - with zipfile.ZipFile(zip_filename, "r") as zip_file: - for json_filename in zip_file.namelist(): - path = json_filename.split(os.sep) - if len(path) != 2 or path[0] != "types": - continue - model = get_model_from_filename(path[-1]) - initial_count[json_filename] = model.objects.count() - model.objects.all().delete() + models.AuthorType.objects.create( + label="Am I still here", txt_idx="am-i-still-here") + models.AuthorType.objects.filter(txt_idx="test").delete() + restore_serialized(zip_filename) + self.assertEqual( + models.AuthorType.objects.filter(txt_idx="test").count(), 1) + self.assertEqual( + models.AuthorType.objects.filter(txt_idx="am-i-still-here").count(), + 1) + + models.AuthorType.objects.filter(txt_idx="am-i-still-here").delete() + zip_filename = type_serialization(archive=True) + models.AuthorType.objects.create( + label="Am I still here", txt_idx="am-i-still-here") + models.AuthorType.objects.filter(txt_idx="test").delete() + restore_serialized(zip_filename, delete_existing=True) + self.assertEqual( + models.AuthorType.objects.filter(txt_idx="test").count(), 1) + self.assertEqual( + models.AuthorType.objects.filter(txt_idx="am-i-still-here").count(), + 0) class AccessControlTest(TestCase): -- cgit v1.2.3