diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-11-18 16:46:37 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:21 +0100 |
commit | b27fabdea6c6bfba75521dc84f5a321e61e6ef52 (patch) | |
tree | 2b4452bc7fec7de7a90e81d9055a8b9971b18c5c /ishtar_common/tests.py | |
parent | 4fa501cb189c61d94a2ca53a604f3db7a212153c (diff) | |
download | Ishtar-b27fabdea6c6bfba75521dc84f5a321e61e6ef52.tar.bz2 Ishtar-b27fabdea6c6bfba75521dc84f5a321e61e6ef52.zip |
Complex index generation with JINJA2 templates
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 88 |
1 files changed, 82 insertions, 6 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 94a636b7b..05799a0aa 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1253,7 +1253,7 @@ class UserProfileTest(TestCase): base_profile = models.UserProfile.objects.get(pk=base_profile.pk) self.assertEqual( base_profile.name, - u"New name" + "New name" ) self.client.post( @@ -2217,7 +2217,6 @@ class ShortMenuTest(TestCase): class ImportTest(TestCase): - def create_import(self): create_user() imp_model = models.ImporterModel.objects.create( @@ -2494,8 +2493,6 @@ class NewItems(TestCase): self.assertEqual(person.author.count(), 1) - - class AccountWizardTest(WizardTest, TestCase): fixtures = [settings.ROOT_PATH + '../fixtures/initial_data-auth-fr.json', @@ -2538,7 +2535,6 @@ class AccountWizardTest(WizardTest, TestCase): class DashboardTest(TestCase): - def setUp(self): self.username, self.password, self.user = create_superuser() profile, created = models.IshtarSiteProfile.objects.get_or_create( @@ -2568,7 +2564,6 @@ class DashboardTest(TestCase): class CleanMedia(TestCase): - def test_rename(self): test_names = [ ("éofficier2-12-02-04.93_gvK3hAr-1_2m7zZPn-1_nKhh2S2-1_"\ @@ -2646,3 +2641,84 @@ class PersonQATest(TestCase): self.title_2 ) + +class DocumentTest(TestCase): + def test_custom_index(self): + Operation = apps.get_model("archaeological_operations", "Operation") + ContextRecord = apps.get_model("archaeological_context_records", + "ContextRecord") + Unit = apps.get_model("archaeological_context_records", "Unit") + BaseFind = apps.get_model("archaeological_finds", "BaseFind") + Find = apps.get_model("archaeological_finds", "Find") + operation_type, __ = models.OperationType.objects.get_or_create( + txt_idx="arch_diagnostic", label="Diagnostic") + ope1 = Operation.objects.create( + code_patriarche="001", + operation_type_id=operation_type.pk) + ope2 = Operation.objects.create( + code_patriarche="002", + operation_type_id=operation_type.pk) + su, __ = Unit.objects.get_or_create( + txt_idx='stratigraphic-unit', label="Stratigraphic unit", order=1) + cr1 = ContextRecord.objects.create(operation=ope1, unit=su) + cr2 = ContextRecord.objects.create(operation=ope2, unit=su) + bf1 = BaseFind.objects.create(context_record=cr1) + bf2 = BaseFind.objects.create(context_record=cr2) + find1 = Find.objects.create() + find1.base_finds.add(bf1) + find2 = Find.objects.create() + find2.base_finds.add(bf2) + st1 = models.SourceType.objects.create(label="Report", code="REP") + st2 = models.SourceType.objects.create(label="Illustration", code="ILL") + + profile, created = models.IshtarSiteProfile.objects.get_or_create( + slug='default', active=True) + profile.document_complete_identifier = \ + "{operation_codes}-{source_type__code}-{custom_index}" + profile.document_custom_index = "operation" + profile.save() + + doc = models.Document.objects.create(source_type=st1, + title="Operation report") + doc.operations.add(ope1) + doc = models.Document.objects.get(pk=doc.pk) + self.assertEqual(doc.complete_identifier, "001-REP-1") + + doc2 = models.Document.objects.create(source_type=st2, + title="Illustration CR") + doc2.context_records.add(cr1) + doc2 = models.Document.objects.get(pk=doc2.pk) + self.assertEqual(doc2.complete_identifier, "001-ILL-2") + + doc3 = models.Document.objects.create(source_type=st1, + title="Operation report 2") + doc3.operations.add(ope2) + doc3 = models.Document.objects.get(pk=doc3.pk) + self.assertEqual(doc3.complete_identifier, "002-REP-1") + + doc3.operations.add(ope1) + doc3.custom_index = None + doc3.save() + doc3 = models.Document.objects.get(pk=doc3.pk) + self.assertEqual(doc3.custom_index, None) # 2 operations - no index + self.assertEqual(doc3.complete_identifier, '001|002-REP-') + + # complex jinja identifier + profile.document_complete_identifier = \ + "{% if custom_index %}{{operation_codes}}-{{source_type__code}}-" \ + "{{ \"%03d\" % (custom_index|int)}}{% else %}no-code{% endif %}" + profile.save() + + doc3.operations.remove(ope1) + doc3.custom_index = None + doc3.complete_identifier = "" + doc3.save() + doc3 = models.Document.objects.get(pk=doc3.pk) + self.assertEqual(doc3.complete_identifier, '002-REP-001') + + doc3.operations.remove(ope2) + doc3.custom_index = None + doc3.complete_identifier = "" + doc3.save() + doc3 = models.Document.objects.get(pk=doc3.pk) + self.assertEqual(doc3.complete_identifier, 'no-code') |