diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/models.py | 26 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 21 | 
2 files changed, 34 insertions, 13 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 435394592..004ee8d06 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -125,11 +125,11 @@ class ArchaeologicalSite(BaseHistorizedItem):      ALT_NAMES = {          'reference': (              pgettext_lazy("key for text search", u"reference"), -            'reference' +            'reference__iexact'          ),          'name': (              pgettext_lazy("key for text search", u"name"), -            'name' +            'name__iexact'          ),          'periods': (              pgettext_lazy("key for text search", u"period"), @@ -145,15 +145,15 @@ class ArchaeologicalSite(BaseHistorizedItem):          ),          'comment': (              pgettext_lazy("key for text search", u"comment"), -            'comment__icontains' +            'comment__iexact'          ),          'locality_ngi': (              pgettext_lazy("key for text search", u"locality-ngi"), -            'locality_ngi__icontains' +            'locality_ngi__iexact'          ),          'locality_cadastral': (              pgettext_lazy("key for text search", u"locality-cadastral"), -            'locality_cadastral__icontains' +            'locality_cadastral__iexact'          ),          'shipwreck_name': (              pgettext_lazy("key for text search", u"shipwreck-name"), @@ -162,7 +162,7 @@ class ArchaeologicalSite(BaseHistorizedItem):          'oceanographic_service_localisation': (              pgettext_lazy("key for text search",                            u"oceanographic-service-localisation"), -            'oceanographic_service_localisation__icontains' +            'oceanographic_service_localisation__iexact'          ),          'shipwreck_code': (              pgettext_lazy("key for text search", u"shipwreck-code"), @@ -174,7 +174,7 @@ class ArchaeologicalSite(BaseHistorizedItem):          ),          'discovery_area': (              pgettext_lazy("key for text search", u"discovery-area"), -            'discovery_area__icontains' +            'discovery_area__iexact'          ),      }      for v in ALT_NAMES.values(): @@ -474,7 +474,7 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          ),          'code_patriarche': (              pgettext_lazy("key for text search", u"patriarche"), -            'code_patriarche' +            'code_patriarche__iexact'          ),          'towns': (              pgettext_lazy("key for text search", u"town"), @@ -490,11 +490,11 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          ),          'common_name': (              pgettext_lazy("key for text search", u"name"), -            'common_name__icontains' +            'common_name__iexact'          ),          'address': (              pgettext_lazy("key for text search", u"address"), -            'address__icontains' +            'address__iexact'          ),          'operation_type': (              pgettext_lazy("key for text search", u"type"), @@ -546,16 +546,16 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          ),          'comment': (              pgettext_lazy("key for text search", u"comment"), -            'comment__icontains' +            'comment__iexact'          ),          'abstract': (              pgettext_lazy("key for text search", u"abstract"), -            'abstract__icontains' +            'abstract__iexact'          ),          'scientific_documentation_comment': (              pgettext_lazy("key for text search",                            u"scientific-documentation-comment"), -            'scientific_documentation_comment__icontains' +            'scientific_documentation_comment__iexact'          ),          'record_quality_type': (              pgettext_lazy("key for text search", u"record-quality"), diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index a396adecf..f45355558 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2467,3 +2467,24 @@ class SiteTest(TestCase, OperationInitTest):          ]          self.assertIn(operation_0, attached)          self.assertIn(operation_1, attached) + +    def test_search(self): +        site = models.ArchaeologicalSite.objects.create( +            reference="reference-site" +        ) +        c = Client() +        search = {'search_vector': 'reference="reference-site"'} +        response = c.get(reverse('get-site'), search) +        # no result when no authentication +        self.assertTrue(not json.loads(response.content)) +        c.login(username=self.username, password=self.password) +        response = c.get(reverse('get-site'), search) +        self.assertEqual(json.loads(response.content)['recordsTotal'], 1) + +        search = {'search_vector': 'reference="reference"'} +        response = c.get(reverse('get-site'), search) +        self.assertEqual(json.loads(response.content)['recordsTotal'], 0) + +        search = {'search_vector': 'reference="reference*"'} +        response = c.get(reverse('get-site'), search) +        self.assertEqual(json.loads(response.content)['recordsTotal'], 1)  | 
