diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-11-17 15:37:22 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:21 +0100 |
commit | 4fa501cb189c61d94a2ca53a604f3db7a212153c (patch) | |
tree | e983fd246f6fd2ce0e9521ea23c1f93c73cc8bc9 /archaeological_context_records/tests.py | |
parent | a255ff5f509225c3258aa9546d9cbd4ce0c0fa0b (diff) | |
download | Ishtar-4fa501cb189c61d94a2ca53a604f3db7a212153c.tar.bz2 Ishtar-4fa501cb189c61d94a2ca53a604f3db7a212153c.zip |
Manage a "custom_index" for base types
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index cd547bc07..6c2c256a0 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -488,6 +488,60 @@ class ContextRecordTest(ContextRecordInit, TestCase): obj.fix() self.assertEqual(obj.datings.count(), 2) + def test_custom_index(self): + profile, created = IshtarSiteProfile.objects.get_or_create( + slug='default', active=True) + + # key: operation + profile.contextrecord_custom_index = 'operation_id' + profile.save() + cr1 = self.context_records[0] + cr1.save() + cr1 = models.ContextRecord.objects.get(pk=cr1.pk) + self.assertEqual(cr1.custom_index, 1) + cr2 = self.context_records[1] + cr2.operation = cr1.operation + cr2.save() + cr2 = models.ContextRecord.objects.get(pk=cr2.pk) + self.assertEqual(cr2.custom_index, 2) + ope = self.create_operation()[-1] + cr3 = self.create_context_record( + data={"operation": ope})[-1] + cr3 = models.ContextRecord.objects.get(pk=cr3.pk) + self.assertEqual(cr3.custom_index, 1) + + # key: operation, unit + profile.contextrecord_custom_index = 'unit_id;operation_id' + profile.save() + + su = models.Unit.objects.get(txt_idx='stratigraphic-unit') + dest = models.Unit.objects.get(txt_idx='sector') + cr1.unit, cr2.unit = su, dest + cr1.save() + cr2.save() + cr2 = models.ContextRecord.objects.get(pk=cr2.pk) + # no change if custom_index not reinit + self.assertEqual(cr2.custom_index, 2) + cr1 = models.ContextRecord.objects.get(pk=cr1.pk) + self.assertEqual(cr1.custom_index, 1) + cr2.custom_index = None + cr2.save() + cr2 = models.ContextRecord.objects.get(pk=cr2.pk) + # different unit -> 1 + self.assertEqual(cr2.custom_index, 1) + cr2.unit = cr1.unit + cr2.custom_index = None + cr2.save() + cr2 = models.ContextRecord.objects.get(pk=cr2.pk) + # same unit and operation -> 2 + self.assertEqual(cr2.custom_index, 2) + cr3.unit = cr1.unit + cr3.custom_index = None + cr3.save() + cr3 = models.ContextRecord.objects.get(pk=cr3.pk) + # same unit and other operation -> 1 + self.assertEqual(cr3.custom_index, 1) + class ContextRecordSearchTest(ContextRecordInit, TestCase, SearchText): fixtures = CONTEXT_RECORD_TOWNS_FIXTURES |