diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-29 18:45:21 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-13 18:26:03 +0200 |
commit | 9de2c94a7a528e1ae24bc2a0a9bb9354329d0a93 (patch) | |
tree | 3acc5fe0568d4bc91e6f38abbadff7e05af35aa7 /archaeological_operations/tests.py | |
parent | f94890fe2d2ab241ee1cd5b980bf88409b47a998 (diff) | |
download | Ishtar-9de2c94a7a528e1ae24bc2a0a9bb9354329d0a93.tar.bz2 Ishtar-9de2c94a7a528e1ae24bc2a0a9bb9354329d0a93.zip |
Searches: manage AND, OR, parentheses and open search '*' (refs #4180)
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 9f08f1e48..381efd070 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1456,8 +1456,11 @@ class OperationSearchTest(TestCase, OperationInitTest): profile.areas.add(area) self.orgas = self.create_orgas(self.user) - self.operations = self.create_operation(self.user, self.orgas[0]) - self.operations += self.create_operation(self.alt_user, self.orgas[0]) + self.create_operation(self.user, self.orgas[0]) + self.create_operation(self.alt_user, self.orgas[0]) + self.operations = self.create_operation(self.alt_user, self.orgas[0]) + self.operations[2].year = 2018 + self.operations[2].save() self.item = self.operations[0] def test_base_search(self): @@ -1471,11 +1474,11 @@ class OperationSearchTest(TestCase, OperationInitTest): response = c.get(reverse('get-operation'), {'operator': self.orgas[0].pk}) result = json.loads(response.content) - self.assertEqual(result['recordsTotal'], 2) + self.assertEqual(result['recordsTotal'], 3) - def test_search_vector(self): + def test_base_search_vector(self): c = Client() - response = c.get(reverse('get-operation'), {'year': '2010'}) + response = c.get(reverse('get-operation'), {'search_vector': 'chaTEAU'}) # no result when no authentication self.assertTrue(not json.loads(response.content)) c.login(username=self.username, password=self.password) @@ -1490,6 +1493,56 @@ class OperationSearchTest(TestCase, OperationInitTest): result = json.loads(response.content) self.assertEqual(result['recordsTotal'], 1) + def test_complex_search_vector(self): + c = Client() + c.login(username=self.username, password=self.password) + operation_1 = models.Operation.objects.get(pk=self.operations[0].pk) + operation_2 = models.Operation.objects.get(pk=self.operations[1].pk) + operation_3 = models.Operation.objects.get(pk=self.operations[2].pk) + operation_1.common_name = u"Opération : Château de Fougères" + operation_1.save() + operation_2.common_name = u"Opération : Fougère filicophyta et " \ + u"herbe à chat" + operation_2.save() + operation_3.common_name = u"Opération : Château Filicophyta" + operation_3.save() + + # simple separation + response = c.get(reverse('get-operation'), + {'search_vector': 'chaTEAU fougere'}) + result = json.loads(response.content) + self.assertEqual(result['recordsTotal'], 1) + + # explicit AND + response = c.get(reverse('get-operation'), + {'search_vector': 'chaTEAU & fougere'}) + result = json.loads(response.content) + self.assertEqual(result['recordsTotal'], 1) + + # explicit OR + response = c.get(reverse('get-operation'), + {'search_vector': 'chaTEAU | fougere'}) + result = json.loads(response.content) + self.assertEqual(result['recordsTotal'], 3) + + # query with parenthesis + response = c.get(reverse('get-operation'), + {'search_vector': '2010 & (fougere | filicophyta)'}) + result = json.loads(response.content) + self.assertEqual(result['recordsTotal'], 2) + + # query with mistmatch parenthesis + response = c.get(reverse('get-operation'), + {'search_vector': ')) 2010 &) ((chaTEAU | fougere)'}) + result = json.loads(response.content) + self.assertEqual(result['recordsTotal'], 2) + + # open search + response = c.get(reverse('get-operation'), + {'search_vector': 'cha*'}) + result = json.loads(response.content) + self.assertEqual(result['recordsTotal'], 3) + def create_relations(self): rel1 = models.RelationType.objects.create( symmetrical=True, label='Include', txt_idx='include') @@ -1513,7 +1566,7 @@ class OperationSearchTest(TestCase, OperationInitTest): self.assertTrue(not json.loads(response.content)) c.login(username=self.username, password=self.password) response = c.get(reverse('get-operation'), search) - self.assertTrue(json.loads(response.content)['recordsTotal'] == 2) + self.assertEqual(json.loads(response.content)['recordsTotal'], 2) def testHierarchicSearch(self): ope = self.operations[1] |