summaryrefslogtreecommitdiff
path: root/archaeological_context_records/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2026-02-11 16:19:18 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2026-02-12 10:43:18 +0100
commitbe6fc87760c8558f83a4ba6617776e132c1de6c6 (patch)
treedbcc984bfd64950eff492d71b028cf06e076a626 /archaeological_context_records/tests.py
parent9d348ebd98b3405305365b5da36cb3c2b2956198 (diff)
downloadIshtar-be6fc87760c8558f83a4ba6617776e132c1de6c6.tar.bz2
Ishtar-be6fc87760c8558f83a4ba6617776e132c1de6c6.zip
🐛 CSV export: fix export of json field when a json field is used as search (refs #6602)
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r--archaeological_context_records/tests.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 676cdf2a8..835819e42 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -24,6 +24,7 @@ import locale
from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import Permission, Group
+from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.template.defaultfilters import slugify
@@ -33,11 +34,17 @@ from django.utils.translation import pgettext_lazy
from ishtar_common.models import (
Area,
+ CustomForm,
+ CustomFormJsonField,
+ FormaterType,
get_current_profile,
+ ImporterColumn,
ImporterModel,
ImporterType,
+ ImportTarget,
IshtarSiteProfile,
IshtarUser,
+ JsonDataField,
ProfileType,
Town,
UserProfile,
@@ -387,6 +394,59 @@ class ExportTest(ContextRecordInit, TestCase):
self.assertEqual(row_cr[1], "12345")
self.assertEqual(row_cr[2], "A1")
+ def test_ishtar_export_json_field(self):
+ """
+ Export JSON fields with a JSON search (#6602)
+ """
+ ope = self.create_operation()[0]
+ ope.code_patriarche = "45000"
+ ope.save()
+ self.create_context_record(
+ data={"label": "CR 1", "data": {"test": "value test"}}
+ )
+ imp = ImporterType.objects.get(slug="ishtar-context-record")
+ col_number = imp.columns.order_by("-col_number").values_list(
+ "col_number", flat=True
+ )[0] + 1
+ col = ImporterColumn.objects.create(
+ col_number=col_number, label="Json value", importer_type=imp
+ )
+ ImportTarget.objects.create(
+ column=col, target="data__test",
+ formater_type=FormaterType.objects.get(
+ formater_type="UnicodeFormater", options="")
+ )
+
+ json_field = JsonDataField.objects.create(
+ name="test", key="test",
+ content_type=ContentType.objects.get_for_model(models.ContextRecord)
+ )
+ cf = CustomForm.objects.create(
+ name="Contect record search form",
+ form="contextrecord-001-search",
+ apply_to_all=True
+ )
+ CustomFormJsonField.objects.create(json_field=json_field, custom_form=cf,
+ order=200)
+
+ c = Client()
+
+ url = reverse(
+ "get-by-importer", kwargs={"slug": "ishtar-context-record", "type": "csv"}
+ )
+ get_args = {"search_vector": 'test="value test"'}
+ response = c.get(url, get_args)
+ # no result when no authentication
+ self.assertTrue(not response.content)
+ c.login(username=self.username, password=self.password)
+ response = c.get(url, get_args)
+ ENCODING = settings.ENCODING or "utf-8"
+ rows = list(csv.reader(StringIO(response.content.decode(ENCODING))))
+ # one header + one context record
+ self.assertEqual(len(rows), 2)
+ row_cr = rows[1]
+ self.assertEqual(row_cr[-1], "value test")
+
class ContextRecordTest(ContextRecordInit, TestCase):
fixtures = CONTEXT_RECORD_TOWNS_FIXTURES