diff options
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 127 | 
1 files changed, 78 insertions, 49 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index bb8c02c78..7b93c7d5e 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -55,7 +55,7 @@ from ishtar_common import forms_common  from ishtar_common.tests import WizardTest, WizardTestFormData as FormData, \      create_superuser, create_user, TestCase, OPERATION_FIXTURES, \      AutocompleteTestBase, AcItem, OPERATION_TOWNS_FIXTURES, FILE_FIXTURES, \ -    COMMON_FIXTURES, GenericSerializationTest, WAREHOUSE_FIXTURES +    COMMON_FIXTURES, GenericSerializationTest, WAREHOUSE_FIXTURES, SearchText  from ishtar_common.serializers import restore_serialized @@ -1898,8 +1898,9 @@ class CustomFormTest(TestCase, OperationInitTest):          ) -class OperationSearchTest(TestCase, OperationInitTest): +class OperationSearchTest(TestCase, OperationInitTest, SearchText):      fixtures = FILE_FIXTURES +    SEARCH_URL = 'get-operation'      def setUp(self):          IshtarSiteProfile.objects.get_or_create( @@ -2027,20 +2028,6 @@ class OperationSearchTest(TestCase, OperationInitTest):          result = json.loads(response.content.decode())          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.decode()) -        if not result: -            result = {"recordsTotal": 0} -        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] @@ -2071,49 +2058,76 @@ class OperationSearchTest(TestCase, OperationInitTest):          villa = models.RemainType.objects.get(txt_idx='villa')          ope1.remains.add(villa) -        search_period_q = str(pgettext("key for text search", u"period")) -        self._test_search(c, search_period_q, final_neo.label, 1, "Simple") +        search_period_q = str(pgettext("key for text search", "period")) +        result = [ +            ('{}="{}"'.format(search_period_q, str(final_neo)), 1), +        ] +        self._test_search(c, result, context="Simple period") -        search_year_q = str(pgettext("key for text search", u"year")) -        self._test_search(c, search_year_q, "2042", 1, "Integer") +        search_year_q = str(pgettext("key for text search", "year")) +        result = [ +            ('{}="{}"'.format(search_year_q, "2042"), 1), +        ] +        self._test_search(c, result, context="Integer") -        self._test_search(c, search_year_q, '2042";"2020', 2, "Many integer") +        result = [ +            ('{}="{}"'.format(search_year_q, '2042";"2020'), 2), +        ] +        self._test_search(c, result, context="Many integer") -        search_town_q = str(pgettext("key for text search", u"town")) +        search_town_q = str(pgettext("key for text search", "town"))          town = Town.objects.get(pk=town.pk) -        self._test_search(c, search_town_q, town.cached_label, 1, -                          "String search with parenthesis and minus") - -        self._test_search(c, search_period_q, neo.label, 2, "Hierarchic") - -        self._test_search(c, u'-{}="{}"'.format(search_period_q, neo.label), "", -                          1, "Exclude") +        result = [ +            ('{}="{}"'.format(search_town_q, town.cached_label), 1), +        ] +        self._test_search(c, result, +                          context="String search with parenthesis and minus") +        result = [ +            ('{}="{}"'.format(search_period_q, str(neo)), 2), +        ] +        self._test_search(c, result, context="Hierarchic period") -        self._test_search(c, search_period_q, -                          u'{}";"{}'.format(neo.label, gallo.label), -                          3, "OR") +        result = [ +            ('-{}="{}"'.format(search_period_q, str(neo)), 1), +        ] +        self._test_search(c, result, context="Period exclude") -        self._test_search( -            c, u'{}="{}" {}="{}"'.format(search_period_q, neo.label, -                                         search_period_q, gallo.label), "", 3, -            "OR alt syntax") +        result = [ +            ('{}="{}"'.format(search_period_q, +                              '{}";"{}'.format(neo.label, gallo.label)), 3), +            ('{}="{}" {}="{}"'.format(search_period_q, neo.label, +                                         search_period_q, gallo.label), 3), +        ] +        self._test_search(c, result, context="Period OR")          # open search '*' +        result = [ +            ('{}="{}*"'.format(search_period_q, neo.label[:3]), 2), +        ] +        self._test_search(c, result, context="Period open search") +        """          self._test_search(c, search_period_q,                            u'{}*'.format(neo.label[:3]), 2, "Open search") +                          """          # non hierarchic search -        search_remain_q = str(pgettext("key for text search", u"remain")) -        self._test_search(c, search_remain_q, villa.label, -                          1, "Non hierarchic search") +        search_remain_q = str(pgettext("key for text search", "remain")) +        result = [ +            ('{}="{}"'.format(search_remain_q, str(villa)), 1), +        ] +        self._test_search(c, result, +                          context="Non hierarchic remain search")          # boolean search -        search_open_q = str(pgettext("key for text search", u"is-open")) -        self._test_search(c, search_open_q, u"Yes", 2, "Boolean") +        search_open_q = str(pgettext("key for text search", "is-open")) +        result = [ +            ('{}="{}"'.format(search_open_q, str(_("Yes"))), 2), +        ] +        self._test_search(c, result, context="Boolean search")      def test_mixed_search_vector(self):          operation_1 = models.Operation.objects.get(pk=self.operations[0].pk) -        operation_1.common_name = u"Opération : Château de Fougères" +        operation_1.common_name = "Opération : Château de Fougères"          operation_1.year = 2042          operation_1.save() @@ -2149,7 +2163,7 @@ class OperationSearchTest(TestCase, OperationInitTest):                  reltype_key, rel2.name)          }          response = c.get(reverse('get-operation'), search) -        # no result when no authentification +        # no result when no authentication          self.assertTrue(not json.loads(response.content.decode()))          c.login(username=self.username, password=self.password)          response = c.get(reverse('get-operation'), search) @@ -2163,9 +2177,12 @@ class OperationSearchTest(TestCase, OperationInitTest):          lbl = "aha = take on me | take me on"          ope.common_name = lbl          ope.save() -        search_name_q = str(pgettext("key for text search", u"name")) -        self._test_search(c, search_name_q, lbl, 1, -                          "Facet search with = and | characters") +        search_name_q = str(pgettext("key for text search", "name")) +        result = [ +            ('{}="{}"'.format(search_name_q, lbl), 1), +        ] +        self._test_search(c, result, +                          context="Facet search with = and | characters")      def test_search_with_asterisk_inside_names(self):          c = Client() @@ -2174,10 +2191,13 @@ class OperationSearchTest(TestCase, OperationInitTest):          ope_type = ope.operation_type          ope_type.label = 'label*with*asterisk'          ope_type.save() -        search_name_q = str(pgettext("key for text search", u"type")) +        search_name_q = str(pgettext("key for text search", "type"))          nb = models.Operation.objects.filter(operation_type=ope_type).count() -        self._test_search(c, search_name_q, ope_type.label, nb, -                          "Facet search with * characters") +        result = [ +            ('{}="{}"'.format(search_name_q, ope_type.label), nb), +        ] +        self._test_search(c, result, +                          context="Facet search with * characters")      def test_hierarchic_search(self):          ope = self.operations[1] @@ -2216,6 +2236,15 @@ class OperationSearchTest(TestCase, OperationInitTest):          self.assertEqual(json.loads(response.content.decode())['recordsTotal'],                           1) +        # test on text search +        period_key = str(pgettext_lazy("key for text search", 'period')) +        result = [ +            ('{}="{}"'.format(period_key, str(final_neo)), 1), +            ('{}="{}"'.format(period_key, str(recent_neo)), 0), +            ('{}="{}"'.format(period_key, str(neo)), 1), +        ] +        self._test_search(c, result, context="Text period search") +      def test_town_search(self):          c = Client()          c.login(username=self.username, password=self.password) | 
