diff options
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 |