diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-01-27 17:31:00 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-01-27 17:31:00 +0100 |
commit | 466398d76996c5219491807e28709ec17706e8d3 (patch) | |
tree | dc2627a86507fe03bf42b21bcc5fe21183573cf4 /archaeological_context_records/tests.py | |
parent | fe841330a8811a6a5b828c93520aae2727661dcb (diff) | |
download | Ishtar-466398d76996c5219491807e28709ec17706e8d3.tar.bz2 Ishtar-466398d76996c5219491807e28709ec17706e8d3.zip |
Add custom cached_label configuration for each main item
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index f0b12e0d6..28aa2208b 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -27,7 +27,7 @@ from django.conf import settings from django.contrib.auth.models import Permission from django.core.exceptions import ValidationError, ImproperlyConfigured from django.core.files.uploadedfile import SimpleUploadedFile -from django.test import tag +from django.template.defaultfilters import slugify from django.test.client import Client from django.urls import reverse from django.utils.translation import pgettext_lazy @@ -438,6 +438,30 @@ class ContextRecordTest(ContextRecordInit, TestCase): self.assertIsNotNone(cr.cached_label) self.assertIn(profile.operation_prefix.lower() + "patriarch", cr.search_vector) + def test_custom_cached_label(self): + profile, created = IshtarSiteProfile.objects.get_or_create( + slug="default", active=True + ) + profile.contextrecord_cached_label = \ + "OA{operation__code_patriarche}-{label|slug:0>7}" + profile.save() + cr1 = self.context_records[0] + cr1 = models.ContextRecord.objects.get(pk=cr1.pk) + cr1.save() + cr1 = models.ContextRecord.objects.get(pk=cr1.pk) + code_patriarche = cr1.operation.code_patriarche + label = slugify(cr1.label) + # label = "CR 1" - code patriarche = "1" + # -> OA1-000cr-1 + expected_lbl = f"OA{code_patriarche}-{label:0>7}" + self.assertEqual(cr1.cached_label, expected_lbl) + # test cascade update + cr1.operation.code_patriarche = "666" + cr1.operation.save() + cr1 = models.ContextRecord.objects.get(pk=cr1.pk) + expected_lbl = f"OA666-{label:0>7}" + self.assertEqual(cr1.cached_label, expected_lbl) + def test_upstream_cache_update(self): cr = self.create_context_record()[0] cr_pk = cr.pk |