summaryrefslogtreecommitdiff
path: root/archaeological_context_records/tests.py
diff options
context:
space:
mode:
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 a84abdd4f..0a84bf4f4 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
+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
@@ -32,9 +33,15 @@ from django.urls import reverse
from django.utils.translation import pgettext_lazy
from ishtar_common.models import (
+ CustomForm,
+ CustomFormJsonField,
+ FormaterType,
IshtarSiteProfile,
+ ImporterColumn,
ImporterModel,
ImporterType,
+ ImportTarget,
+ JsonDataField,
UserProfile,
ProfileType,
Town,
@@ -385,6 +392,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