summaryrefslogtreecommitdiff
path: root/archaeological_context_records/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-06-14 19:41:59 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-06-16 12:11:20 +0200
commit9cbbd92a15d169825ac5bacd7f0a3d41c4601b07 (patch)
treeb789de27120d29dbc90e15755761f1434c4bcd5a /archaeological_context_records/tests.py
parent839bb85c66e952368f4ed18c8544249b832adc45 (diff)
downloadIshtar-9cbbd92a15d169825ac5bacd7f0a3d41c4601b07.tar.bz2
Ishtar-9cbbd92a15d169825ac5bacd7f0a3d41c4601b07.zip
WIP - optimize record relations
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r--archaeological_context_records/tests.py64
1 files changed, 60 insertions, 4 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 64950bd91..1f919b5d9 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -884,9 +884,8 @@ class RecordRelationsTest(ContextRecordInit, TestCase):
model = models.ContextRecord
def setUp(self):
- # two different context records
- self.create_context_record({"label": "CR 1"})
- self.create_context_record({"label": "CR 2"})
+ for idx in range(1, 11):
+ self.create_context_record({"label": f"CR {idx}"})
def test_relations(self):
sym_rel_type = models.RelationType.objects.create(
@@ -933,7 +932,7 @@ class RecordRelationsTest(ContextRecordInit, TestCase):
# for non-symmetrical relation, adding one relation automatically
# adds the inverse
- rel = models.RecordRelations.objects.create(
+ models.RecordRelations.objects.create(
left_record=cr_1, right_record=cr_2, relation_type=rel_type_1
)
self.assertEqual(
@@ -943,6 +942,63 @@ class RecordRelationsTest(ContextRecordInit, TestCase):
1,
)
+ def test_relation_view(self):
+ ## TODO : branches multiples
+ ## TODO : cyclique
+ profile = get_current_profile()
+ profile.parent_relations_engine = "V"
+ profile.save()
+ 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'
+ )
+ """
+ 6 7 8 9 10
+ | | | | |
+ ------- -----
+ | |
+ 4 5
+ | |
+ ---------
+ |
+ 3
+ |
+ ---------
+ | |
+ 1 2
+ """
+ relations = (
+ (1, 3), (2, 3), (3, 4), (3, 5), (4, 6), (4, 7), (4, 8),
+ (5, 9), (5, 10)
+ )
+ for child_idx, parent_idx in relations:
+ models.RecordRelations.objects.create(
+ left_record=crs[child_idx - 1],
+ right_record=crs[parent_idx - 1],
+ relation_type=rel_type_1
+ )
+ q = models.ContextRecordTree.objects.filter(
+ cr_parent_id=crs[2].pk, cr_id=crs[0].pk)
+ self.assertGreaterEqual(q.count(), 1)
+
+ self.assertIsNone(models.ContextRecordTree.check_engine()) # no change
+ profile.parent_relations_engine = "T"
+ profile.save()
+ profile = 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
+ print("~~~ CR1 - child of all")
+ models.ContextRecordTree.update(crs[0].id)
+ print("~~~ CR2")
+ models.ContextRecordTree.update(crs[1].id)
+ print("~~~ CR3 - parent of all")
+ models.ContextRecordTree.update(crs[2].id)
+ # vérifier cr1 -> cr3
+
class ContextRecordWizardCreationTest(WizardTest, ContextRecordInit, TestCase):
fixtures = OPERATION_TOWNS_FIXTURES