diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-07-04 11:43:34 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:03 +0200 |
commit | 493d366b3a69744a3089f17ffa172372fa391f29 (patch) | |
tree | 7c570daeb42e18b384f4069751935b507b0da767 /archaeological_operations/tests.py | |
parent | f73c33804ce7d3c675be81d6bf8f2cc4ed2ebc55 (diff) | |
download | Ishtar-493d366b3a69744a3089f17ffa172372fa391f29.tar.bz2 Ishtar-493d366b3a69744a3089f17ffa172372fa391f29.zip |
Search: do not parse for parentheses inside quotes (refs #4180)
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 109 |
1 files changed, 49 insertions, 60 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 19724ff8b..cfcbe010b 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1548,6 +1548,18 @@ class OperationSearchTest(TestCase, OperationInitTest): result = json.loads(response.content) self.assertEqual(result['recordsTotal'], 1) + def _test_search(self, c, term, query_string, number, name=""): + q = term + if query_string: + q = u'{}="{}"'.format(term, query_string) + search = {'search_vector': q} + response = c.get(reverse('get-operation'), search) + self.assertEqual(response.status_code, 200) + result = json.loads(response.content) + self.assertEqual(result['recordsTotal'], number, + u"{} - {} - {} result(s) expected got {}".format( + name, q, number, result['recordsTotal'])) + def test_facet_search_vector(self): ope1 = self.operations[0] ope2 = self.operations[1] @@ -1555,14 +1567,21 @@ class OperationSearchTest(TestCase, OperationInitTest): c = Client() c.login(username=self.username, password=self.password) - neo = models.Period.objects.get(txt_idx='neolithic') - final_neo = models.Period.objects.get(txt_idx='final-neolithic') - gallo = models.Period.objects.get(txt_idx="gallo-roman") - ope1.periods.add(final_neo) ope1.year = 2042 ope1.save() ope2.year = 2020 ope2.save() + + data = {'numero_insee': '05000', 'name': 'Champoleon (test)'} + town = self.create_towns(datas=data)[-1] + + ope1.towns.add(town) + + neo = models.Period.objects.get(txt_idx='neolithic') + final_neo = models.Period.objects.get(txt_idx='final-neolithic') + gallo = models.Period.objects.get(txt_idx="gallo-roman") + + ope1.periods.add(final_neo) ope1.periods.add(gallo) ope2.periods.add(neo) ope3.periods.add(gallo) @@ -1570,79 +1589,49 @@ class OperationSearchTest(TestCase, OperationInitTest): villa = models.RemainType.objects.get(txt_idx='villa') ope1.remains.add(villa) - # simple - search_q = unicode( + search_period_q = unicode( pgettext("key for text search (no accent, no spaces)", u"period") ) - search = {'search_vector': u'{}="{}"'.format(search_q, final_neo.label)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 1) - # integer field + self._test_search(c, search_period_q, final_neo.label, 1, "Simple") + search_year_q = unicode( pgettext("key for text search (no accent, no spaces)", u"year") ) - search = {'search_vector': u'{}="2042"'.format(search_year_q)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 1) + self._test_search(c, search_year_q, "2042", 1, "Integer") - # many integer field - search = {'search_vector': u'{}="2042";"2020"'.format(search_year_q)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 2) + self._test_search(c, search_year_q, '2042";"2020', 2, "Many integer") - # hierarchic - search = {'search_vector': u'{}="{}"'.format(search_q, neo.label)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 2) + search_town_q = unicode( + pgettext("key for text search (no accent, no spaces)", u"town") + ) + self._test_search(c, search_town_q, town.cached_label, 1, + "String search with parenthesis and minus") - # exclude - search = {'search_vector': u'-{}="{}"'.format(search_q, neo.label)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 1) + self._test_search(c, search_period_q, neo.label, 2, "Hierarchic") - # OR - search = {'search_vector': u'{}="{}";"{}"'.format(search_q, neo.label, - gallo.label)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 3) + self._test_search(c, u'-{}="{}"'.format(search_period_q, neo.label), "", + 1, "Exclude") - # OR - alt syntax - search = {'search_vector': u'{}="{}" {}="{}"'.format( - search_q, neo.label, search_q, gallo.label)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 3) + self._test_search(c, search_period_q, + u'{}";"{}'.format(neo.label, gallo.label), + 3, "OR") + + self._test_search( + c, u'{}="{}" {}="{}"'.format(search_period_q, neo.label, + search_period_q, gallo.label), "", 3, + "OR alt syntax") # open search '*' - search = {'search_vector': u'{}="{}*"'.format(search_q, neo.label[:3])} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 2) + self._test_search(c, search_period_q, + u'{}*'.format(neo.label[:3]), 2, "Open search") # non hierarchic search - search_q = unicode( + search_remain_q = unicode( pgettext("key for text search (no accent, no spaces)", u"remain") ) - search = {'search_vector': u'{}="{}"'.format(search_q, villa.label)} - response = c.get(reverse('get-operation'), search) - self.assertEqual(response.status_code, 200) - result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 1) + self._test_search(c, search_remain_q, villa.label, + 1, "Non hierarchic search") def create_relations(self): rel1 = models.RelationType.objects.create( |