diff options
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 381efd070..1480eb502 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -33,7 +33,7 @@ from django.db.models import Q from django.test.client import Client from django.contrib.auth.models import User, Permission -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, pgettext import models from archaeological_operations import views @@ -1538,11 +1538,64 @@ class OperationSearchTest(TestCase, OperationInitTest): self.assertEqual(result['recordsTotal'], 2) # open search - response = c.get(reverse('get-operation'), - {'search_vector': 'cha*'}) + response = c.get(reverse('get-operation'), {'search_vector': 'cha*'}) result = json.loads(response.content) self.assertEqual(result['recordsTotal'], 3) + def test_facet_search_vector(self): + ope1 = self.operations[0] + ope2 = self.operations[1] + ope3 = self.operations[2] + 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.periods.add(gallo) + ope2.periods.add(neo) + ope3.periods.add(gallo) + + villa = models.RemainType.objects.get(txt_idx='villa') + ope1.remains.add(villa) + + # simple + search_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) + + # 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) + + # 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) + + # non hierarchic search + search_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) + + def create_relations(self): rel1 = models.RelationType.objects.create( symmetrical=True, label='Include', txt_idx='include') |