From 80152f2f2692fd576b55ab7e6adb3292770bbc68 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 1 Sep 2019 11:41:59 +0200 Subject: Serialization: manage circular types - refactoring --- ishtar_common/tests.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'ishtar_common/tests.py') diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index e292ae097..7e1948bf0 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -604,8 +604,15 @@ class SerializationTest(TestCase): module_name, model_name = k.split("__") module = importlib.import_module(module_name + ".models") model = getattr(module, model_name) - self.assertEqual(model.objects.count(), - len(json.loads(json_result[k]))) + current_count = model.objects.count() + serialization_count = len(json.loads(json_result[k])) + # has to be at least equal (can be superior for model with + # recursivity) + self.assertTrue( + serialization_count >= current_count, + msg="Serialization for model {}.{} failed. {} serialized {} " + "expected".format(module.__name__, model_name, + serialization_count, current_count)) def test_serialization_zip(self): zip_filename = type_serialization(archive=True) @@ -632,6 +639,11 @@ class SerializationTest(TestCase): restore_serialized(zip_filename) def test_type_restore(self): + from archaeological_context_records.models import RelationType as CRRT + from archaeological_operations.models import RelationType as OperationRT + cr_rel_type_nb = CRRT.objects.count() + ope_rel_type_nb = OperationRT.objects.count() + models.AuthorType.objects.create(label="Test", txt_idx="test") zip_filename = type_serialization(archive=True) @@ -644,6 +656,10 @@ class SerializationTest(TestCase): self.assertEqual( models.AuthorType.objects.filter(txt_idx="am-i-still-here").count(), 1) + self.assertEqual(cr_rel_type_nb, CRRT.objects.count()) + self.assertEqual(ope_rel_type_nb, OperationRT.objects.count()) + self.assertTrue(OperationRT.objects.filter( + inverse_relation__isnull=False).count()) models.AuthorType.objects.filter(txt_idx="am-i-still-here").delete() zip_filename = type_serialization(archive=True) @@ -656,6 +672,10 @@ class SerializationTest(TestCase): self.assertEqual( models.AuthorType.objects.filter(txt_idx="am-i-still-here").count(), 0) + self.assertEqual(cr_rel_type_nb, CRRT.objects.count()) + self.assertEqual(ope_rel_type_nb, OperationRT.objects.count()) + self.assertTrue(OperationRT.objects.filter( + inverse_relation__isnull=False).count()) class AccessControlTest(TestCase): -- cgit v1.2.3