summaryrefslogtreecommitdiff
path: root/archaeological_context_records/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-01-25 13:39:09 +0100
committerÉtienne Loks <etienne.loks@proxience.com>2015-01-25 13:39:09 +0100
commit9a5d47d504c105d4606b88b155f161262e15e619 (patch)
treedafd829767f91b12fdc045c587c60e372ae39ea8 /archaeological_context_records/tests.py
parentfd43bf6ac13673537ca1fbd50ee037ecb022bb6b (diff)
downloadIshtar-9a5d47d504c105d4606b88b155f161262e15e619.tar.bz2
Ishtar-9a5d47d504c105d4606b88b155f161262e15e619.zip
Automatically add symetric/inverse for context records relations
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r--archaeological_context_records/tests.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index fb3abb317..aa1e2f7c7 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -70,17 +70,37 @@ class RecordRelationsTest(TestCase, ContextRecordInit):
self.create_context_record({"label":u"CR 2"})
def testRelations(self):
- sym_rel = models.RelationType.objects.create(symmetrical=True,
+ sym_rel_type = models.RelationType.objects.create(symmetrical=True,
txt_idx='sym')
- rel_1 = models.RelationType.objects.create(symmetrical=False,
+ rel_type_1 = models.RelationType.objects.create(symmetrical=False,
txt_idx='rel_1')
# cannot have symmetrical and an inverse_relation
with self.assertRaises(ValidationError):
rel_test = models.RelationType.objects.create(symmetrical=True,
- inverse_relation=rel_1, txt_idx='rel_3')
+ inverse_relation=rel_type_1, txt_idx='rel_3')
rel_test.full_clean()
# auto fill inverse relations
- rel_2 = models.RelationType.objects.create(symmetrical=False,
- inverse_relation=rel_1, txt_idx='rel_2')
- self.assertEqual(rel_1.inverse_relation, rel_2)
-
+ rel_type_2 = models.RelationType.objects.create(symmetrical=False,
+ inverse_relation=rel_type_1, txt_idx='rel_2')
+ self.assertEqual(rel_type_1.inverse_relation, rel_type_2)
+
+ cr_1 = self.context_records[0]
+ cr_2 = self.context_records[1]
+
+ # inserting a new symetric relation automatically create the inverse
+ # relation
+ rel = models.RecordRelations.objects.create(left_record=cr_1,
+ right_record=cr_2, relation_type=sym_rel_type)
+ self.assertEqual(models.RecordRelations.objects.filter(left_record=cr_2,
+ right_record=cr_1, relation_type=sym_rel_type).count(), 1)
+
+ # remove one symetric relation remove the other
+ rel.delete()
+ self.assertEqual(models.RecordRelations.objects.filter(left_record=cr_2,
+ right_record=cr_1, relation_type=sym_rel_type).count(), 0)
+
+ # for non symetric relation adding one relation add the inverse
+ rel = models.RecordRelations.objects.create(left_record=cr_1,
+ right_record=cr_2, relation_type=rel_type_1)
+ self.assertEqual(models.RecordRelations.objects.filter(left_record=cr_2,
+ right_record=cr_1, relation_type=rel_type_2).count(), 1)