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