diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-06-17 18:31:26 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-06-17 18:31:26 +0200 |
commit | aa6033dea383be81c7ddef058d77f695ef8bea14 (patch) | |
tree | 3e63695736a8981a9c8b4391b671765f5deef6d4 /archaeological_context_records/tests.py | |
parent | 25f23ed03ad48fb4e5ca2f14527c0bc381dc8c9b (diff) | |
download | Ishtar-aa6033dea383be81c7ddef058d77f695ef8bea14.tar.bz2 Ishtar-aa6033dea383be81c7ddef058d77f695ef8bea14.zip |
Context records: Optimize record relations - fix equals
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 97 |
1 files changed, 47 insertions, 50 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 553731542..6b3e9f648 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -884,7 +884,7 @@ class RecordRelationsTest(ContextRecordInit, TestCase): model = models.ContextRecord def setUp(self): - for idx in range(1, 11): + for idx in range(1, 15): self.create_context_record({"label": f"CR {idx}"}) def test_relations(self): @@ -949,6 +949,7 @@ class RecordRelationsTest(ContextRecordInit, TestCase): profile = get_current_profile(force=True) models.ContextRecordTree.check_engine() crs = self.context_records + rel_type_1 = models.RelationType.objects.create( symmetrical=False, txt_idx="rel_1", logical_relation='included' @@ -978,6 +979,19 @@ class RecordRelationsTest(ContextRecordInit, TestCase): right_record=crs[parent_idx - 1], relation_type=rel_type_1 ) + rel_type_2 = models.RelationType.objects.create( + symmetrical=True, txt_idx="rel_2", + logical_relation='equal' + ) + equal_relations = ( + (10, 11), (11, 12), (5, 13), (3, 14) + ) + for child_idx, parent_idx in equal_relations: + models.RecordRelations.objects.create( + left_record=crs[child_idx - 1], + right_record=crs[parent_idx - 1], + relation_type=rel_type_2 + ) q = models.ContextRecordTree.objects.filter( cr_parent_id=crs[2].pk, cr_id=crs[0].pk) self.assertGreaterEqual(q.count(), 1) @@ -992,6 +1006,11 @@ class RecordRelationsTest(ContextRecordInit, TestCase): # verify tree generation full_trees = [ [10, 5, 3, 2], + [11, 5, 3, 2], + [12, 5, 3, 2], + [12, 13, 14, 2], + [10, 5, 14, 2], + [10, 14], [10, 5, 3, 1], [9, 5, 3, 2], [9, 5, 3, 1], @@ -1004,53 +1023,6 @@ class RecordRelationsTest(ContextRecordInit, TestCase): ] self._test_tree_generation(0, full_trees) trees = [ - [10, 5, 3, 2], - [10, 5, 3, 1], - [9, 5, 3, 2], - [9, 5, 3, 1], - [8, 4, 3, 2], - [8, 4, 3, 1], - [7, 4, 3, 2], - [7, 4, 3, 1], - [6, 4, 3, 2], - [6, 4, 3, 1], - ] - self._test_tree_generation(1, trees) - trees = [ - [10, 5, 3, 2], - [10, 5, 3, 1], - [9, 5, 3, 2], - [9, 5, 3, 1], - [8, 4, 3, 2], - [8, 4, 3, 1], - [7, 4, 3, 2], - [7, 4, 3, 1], - [6, 4, 3, 2], - [6, 4, 3, 1], - ] - self._test_tree_generation(2, trees) - trees = [ - [8, 4, 3, 2], - [8, 4, 3, 1], - [7, 4, 3, 2], - [7, 4, 3, 1], - [6, 4, 3, 2], - [6, 4, 3, 1], - ] - self._test_tree_generation(3, trees) - trees = [ - [10, 5, 3, 2], - [10, 5, 3, 1], - [9, 5, 3, 2], - [9, 5, 3, 1], - ] - self._test_tree_generation(4, trees) - trees = [ - [6, 4, 3, 2], - [6, 4, 3, 1], - ] - self._test_tree_generation(5, trees) - trees = [ [7, 4, 3, 2], [7, 4, 3, 1], ] @@ -1075,8 +1047,33 @@ class RecordRelationsTest(ContextRecordInit, TestCase): models.ContextRecordTree.regenerate_all() self._test_tree_(full_trees, "'FULL GENERATION'") - # test remove a Node - # test EQUIV + # test remove a node + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[6 - 1], cr=crs[3 - 1]).count() + self.assertEqual(nb, 1) + models.RecordRelations.objects.filter( + left_record=crs[3 - 1], + right_record=crs[4 - 1] + ).delete() + models.ContextRecordTree.update(crs[3 - 1].pk) + models.ContextRecordTree.update(crs[4 - 1].pk) + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[6 - 1], cr=crs[3 - 1]).count() + self.assertEqual(nb, 0) + + # test remove a node (update equal links) + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[10 - 1], cr=crs[14 - 1]).count() + self.assertEqual(nb, 1) + models.RecordRelations.objects.filter( + left_record=crs[3 - 1], + right_record=crs[5 - 1] + ).delete() + models.ContextRecordTree.update(crs[3 - 1].pk) + models.ContextRecordTree.update(crs[5 - 1].pk) + nb = models.ContextRecordTree.objects.filter( + cr_parent=crs[10 - 1], cr=crs[14 - 1]).count() + self.assertEqual(nb, 0) def _test_tree_(self, test_trees, context_record): crs = self.context_records |