diff options
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index a9fdf38cc..f0d07c33c 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -768,6 +768,51 @@ class OperationTest(TestCase, OperationInitTest):          self.assertEqual(ope_id, 'OP2011-1')          self.assertEqual(town, self.towns[0].name) +    def test_cache_bulk_update(self): +        if settings.USE_SPATIALITE_FOR_TESTS: +            # using views can only be tested with postgresql +            return + +        operation = self.operations[0] +        init_parcel = self.create_parcel()[0] +        operation.parcels.add(init_parcel) + +        from archaeological_context_records.models import ContextRecord +        cr_data = {'label': "Context record", "operation": operation, +                   'parcel': init_parcel, +                   'history_modifier': self.get_default_user()} +        cr = ContextRecord.objects.create(**cr_data) + +        class TestObj(object): +            def __init__(self): +                self.context_record_reached = [] + +            def reached(self, sender, **kwargs): +                instance = kwargs.get('instance') +                if sender == ContextRecord: +                    self.context_record_reached.append(instance) + +        test_obj = TestObj() +        operation = models.Operation.objects.get(pk=operation.pk) +        operation.test_obj = test_obj +        operation.year = 2011 +        operation.save() +        # bulk update of context records cached label gen don't have to be +        # reached +        self.assertEqual(len(test_obj.context_record_reached), 0) + +        # verify the relevance of the update +        cr = ContextRecord.objects.get(pk=cr.pk) +        ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ') +        self.assertEqual(ope_id, '{}2011-1'.format( +            settings.ISHTAR_DEF_OPE_PREFIX)) + +        operation.code_patriarche = '666' +        operation.save() +        cr = ContextRecord.objects.get(pk=cr.pk) +        ope_id, parcel_sec, parcel_nb, cr_label = cr.cached_label.split(' | ') +        self.assertEqual(ope_id, '666'.format(settings.ISHTAR_OPE_PREFIX)) +  class OperationSearchTest(TestCase, OperationInitTest):      fixtures = [settings.ROOT_PATH + | 
