diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-06-21 11:42:59 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-06-21 11:42:59 +0200 |
commit | 0a6b8708431eb45fcd426227fa7b54505d6eb668 (patch) | |
tree | 7e3804a3de1bd2ca6e18a3e557036a4d4ef3afe4 /archaeological_context_records/tests.py | |
parent | aa6033dea383be81c7ddef058d77f695ef8bea14 (diff) | |
download | Ishtar-0a6b8708431eb45fcd426227fa7b54505d6eb668.tar.bz2 Ishtar-0a6b8708431eb45fcd426227fa7b54505d6eb668.zip |
Context records: auto generate relation tree on insert and update
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 6b3e9f648..0d1c84c7f 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -973,6 +973,7 @@ class RecordRelationsTest(ContextRecordInit, TestCase): (1, 3), (2, 3), (3, 4), (3, 5), (4, 6), (4, 7), (4, 8), (5, 9), (5, 10) ) + models.RecordRelations._no_post_treatments = True for child_idx, parent_idx in relations: models.RecordRelations.objects.create( left_record=crs[child_idx - 1], @@ -996,10 +997,11 @@ class RecordRelationsTest(ContextRecordInit, TestCase): cr_parent_id=crs[2].pk, cr_id=crs[0].pk) self.assertGreaterEqual(q.count(), 1) + ## use tables self.assertIsNone(models.ContextRecordTree.check_engine()) # no change profile.parent_relations_engine = "T" profile.save() - profile = get_current_profile(force=True) + get_current_profile(force=True) self.assertTrue(models.ContextRecordTree.check_engine()) # change to table q = models.ContextRecordTree.objects.filter(cr=crs[0], cr_parent=crs[1]) self.assertEqual(q.count(), 0) # empty table @@ -1075,6 +1077,45 @@ class RecordRelationsTest(ContextRecordInit, TestCase): cr_parent=crs[10 - 1], cr=crs[14 - 1]).count() self.assertEqual(nb, 0) + # auto update + models.RecordRelations._no_post_treatments = False + models.RecordRelations.objects.create( + left_record=crs[3 - 1], + right_record=crs[4 - 1], + relation_type=rel_type_1 + ) + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[6 - 1], cr=crs[3 - 1]).count() + self.assertEqual(nb, 1) + models.RecordRelations.objects.create( + left_record=crs[3 - 1], + right_record=crs[5 - 1], + relation_type=rel_type_1 + ) + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[10 - 1], cr=crs[14 - 1]).count() + self.assertEqual(nb, 1) + + # delete + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[13 - 1], cr=crs[1 - 1]).count() + self.assertEqual(nb, 1) + crs[3 - 1].delete() + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[13 - 1], cr=crs[1 - 1]).count() + self.assertEqual(nb, 0) + + # delete on views + profile = get_current_profile() + profile.parent_relations_engine = "V" + profile.save() + get_current_profile(force=True) + models.ContextRecordTree.objects.filter(pk__isnull=False).delete() + crs[4 - 1].delete() + q = models.ContextRecordTree.objects.filter( + cr_parent_id=crs[1 - 1].pk, cr_id=crs[6 - 1].pk) + self.assertGreaterEqual(q.count(), 0) + def _test_tree_(self, test_trees, context_record): crs = self.context_records for tree in test_trees: @@ -1094,6 +1135,12 @@ class RecordRelationsTest(ContextRecordInit, TestCase): models.ContextRecordTree.update(crs[cr_idx].id) self._test_tree_(test_trees, cr_idx + 1) + def tearDown(self): + models.ContextRecordTree.objects.filter(pk__isnull=False).delete() + profile = get_current_profile() + profile.parent_relations_engine = "V" + profile.save() + class ContextRecordWizardCreationTest(WizardTest, ContextRecordInit, TestCase): fixtures = OPERATION_TOWNS_FIXTURES |