summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-25 12:11:37 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-25 12:11:37 +0100
commitcdb5af349c931fa12ccf642cf2080aa117dc4a1f (patch)
tree29d18903e39024ac46daf27eb2322a44252cd6ef /archaeological_operations/tests.py
parent0a280ab1b2a3623780b74528d67debddd891fc6c (diff)
downloadIshtar-cdb5af349c931fa12ccf642cf2080aa117dc4a1f.tar.bz2
Ishtar-cdb5af349c931fa12ccf642cf2080aa117dc4a1f.zip
Operations: bulk update of context records (refs #3472)
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py45
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 +