diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-06-01 09:03:27 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-06-01 09:06:23 +0200 | 
| commit | d2f250e229fbd0751305d9dbfa352ce399a0a92e (patch) | |
| tree | 3c014ca751eff08e46f3ff6c90473c725dc2f123 /archaeological_operations/tests.py | |
| parent | f4045f303ee3bfbcde70992db3342bbad6b564ee (diff) | |
| download | Ishtar-d2f250e229fbd0751305d9dbfa352ce399a0a92e.tar.bz2 Ishtar-d2f250e229fbd0751305d9dbfa352ce399a0a92e.zip | |
Test boolean json field search
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 59 | 
1 files changed, 59 insertions, 0 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 3f4e73639..192d51214 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -33,6 +33,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile  from django.core.urlresolvers import reverse  from django.db.models import Q  from django.test.client import Client +from django.utils.text import slugify  from django.contrib.auth.models import User, Permission  from django.utils.translation import ugettext_lazy as _, pgettext, pgettext_lazy @@ -2487,6 +2488,64 @@ class CustomFormTest(TestCase, OperationInitTest):              msg="json field form: existing value should be presented in select",          ) +    def test_json_search(self): +        operation = self.operations[0] +        operation.data = { +            "groundhog": { +                "awake_state": "réveillée", +                "with_feather": True, +            }, +        } +        operation.save() + +        content_type = ContentType.objects.get_for_model(operation) +        field = JsonDataField.objects.create( +            name="État d'éveil", +            key="groundhog__awake_state", +            content_type=content_type, +            value_type="C", +        ) +        field2 = JsonDataField.objects.create( +            name="As une plume ?", +            key="groundhog__with_feather", +            content_type=content_type, +            value_type="B", +        ) +        form = CustomForm.objects.create( +            name="Test", form="operation-001-search", available=True, apply_to_all=True +        ) +        cf1 = CustomFormJsonField.objects.create( +            custom_form=form, +            json_field=field, +            label="Est-elle éveillée ?", +        ) +        cf2 = CustomFormJsonField.objects.create( +            custom_form=form, +            json_field=field2, +            label="Plume", +        ) + +        c = Client() +        c.login(username=self.username, password=self.password) + +        response = c.get( +            reverse("get-operation"), +            {"search_vector": "{}=endormie".format(slugify(cf1.label))}) +        result = json.loads(response.content.decode()) +        self.assertEqual(result["recordsTotal"], 0) + +        response = c.get( +            reverse("get-operation"), +            {"search_vector": "{}=réveillée".format(slugify(cf1.label))}) +        result = json.loads(response.content.decode()) +        self.assertEqual(result["recordsTotal"], 1) + +        response = c.get( +            reverse("get-operation"), +            {"search_vector": "{}=oui".format(slugify(cf2.label))}) +        result = json.loads(response.content.decode()) +        self.assertEqual(result["recordsTotal"], 1) +  class OperationSearchTest(TestCase, OperationInitTest, SearchText):      fixtures = FILE_FIXTURES | 
