From b32e7b35ae8c103a6cce466531c80d90dee204e1 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 5 May 2020 12:39:32 +0200 Subject: Tests: test import regex --- archaeological_operations/tests.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'archaeological_operations/tests.py') diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 672c06647..af6988568 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -47,7 +47,7 @@ from ishtar_common.models import OrganizationType, Organization, ItemKey, \ DocumentTemplate, PersonType, TargetKeyGroup, JsonDataField, \ JsonDataSection, ImportTarget, FormaterType, CustomForm, ExcludedField, \ UserProfile, ProfileType, Area, CustomFormJsonField, get_current_profile, \ - Document, ValueFormater + Document, ValueFormater, Regexp from archaeological_files.models import File, FileType from archaeological_context_records.models import Unit, ContextRecord @@ -586,6 +586,28 @@ class ImportOperationTest(ImportTest, TestCase): self.assertEqual(ope2.data, {u'autre_refs': {u'arbitraire': 456}, u"autre": 333}) + def test_regexp(self): + importer, form = self.init_ope_import("operations-with-json-fields.csv") + r, __ = Regexp.objects.get_or_create( + name="Code INSEE", + regexp='([0-9]{0,1}[0-9A-B]) *([0-9]{3})' + ) + col = ImporterColumn.objects.create( + importer_type=importer, col_number=13, regexp_pre_filter=r) + formater_type = FormaterType.objects.get( + formater_type='UnicodeFormater', options="") + ImportTarget.objects.create( + column=col, target='data__code_insee', + formater_type=formater_type) + impt = form.save(self.ishtar_user) + impt.initialize() + self.init_ope_targetkey(imp=impt) + impt.importation() + ope1 = models.Operation.objects.get(code_patriarche='4200') + self.assertEqual(ope1.data, {"code_insee": "45123"}) + ope2 = models.Operation.objects.get(code_patriarche='4201') + self.assertEqual(ope2.data, {"code_insee": "6456"}) + class ImportDocumentTest(ImportTest, TestCase): fixtures = OPERATION_TOWNS_FIXTURES -- cgit v1.2.3