diff options
| -rw-r--r-- | archaeological_finds/models_finds.py | 2 | ||||
| -rw-r--r-- | archaeological_finds/tests.py | 75 | 
2 files changed, 67 insertions, 10 deletions
| diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index a4e021d68..e38e0fe14 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -36,7 +36,7 @@ from ishtar_common.utils import cached_label_changed, post_save_point, \  from ishtar_common.alternative_configs import ALTERNATE_CONFIGS  from ishtar_common.models import Document, GeneralType, \ -    HierarchicalType, BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \ +    HierarchicalType, BaseHistorizedItem, LightHistorizedItem, \      HistoricalRecords, OwnPerms, Person, Basket, post_save_cache, \      ValueGetter, get_current_profile, IshtarSiteProfile, PRIVATE_FIELDS, \      SpatialReferenceSystem, BulkUpdatedItem, ExternalIdManager, QuickAction, \ diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 9c023ade6..c1210c598 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -28,7 +28,7 @@ from django.core.urlresolvers import reverse  from django.test.client import Client  from ishtar_common.models import ImporterType, IshtarUser, ImporterColumn,\      FormaterType, ImportTarget, IshtarSiteProfile, ProfileType -from django.utils.translation import pgettext_lazy +from django.utils.translation import pgettext_lazy, gettext_lazy as _  from ishtar_common.models import Person, get_current_profile, UserProfile, \      Town, Area, Document @@ -688,6 +688,70 @@ class FindSearchTest(FindInit, TestCase):          res = json.loads(response.content)          self.assertEqual(res['recordsTotal'], 1) +    def _test_search(self, client, result, context=""): +        for q, expected_result in result: +            search = {'search_vector': q} +            response = client.get(reverse('get-find'), search) +            self.assertEqual(response.status_code, 200) +            res = json.loads(response.content) +            msg = "{} result(s) where expected for search: {}".format( +                expected_result, q) +            if context: +                msg = context + " - " + msg +            self.assertEqual(res['recordsTotal'], expected_result, +                             msg=msg) + +    def test_search_with_callable(self): +        find = self.finds[0] +        find2 = self.finds[1] +        c = Client() +        c.login(username=self.username, password=self.password) + +        loan_key = unicode(pgettext_lazy("key for text search", 'loan')) + +        result = [ +            (u'{}="{}"'.format(loan_key , unicode(_(u"Yes"))), 0), +            (u'{}="{}"'.format(loan_key , unicode(_(u"No"))), 0), +            ] +        self._test_search(c, result, context="No container defined") + +        warehouse = Warehouse.objects.create( +            name="Lambda warehouse", +            warehouse_type=WarehouseType.objects.all()[0]) +        container = Container.objects.create( +            location=warehouse, +            responsible=warehouse, +            container_type=ContainerType.objects.all()[0] +        ) +        find.container_ref = container +        find.container = container +        find.save() +        container2 = Container.objects.create( +            location=warehouse, +            responsible=warehouse, +            container_type=ContainerType.objects.all()[0] +        ) +        find2.container_ref = container2 +        find2.container = container2 +        find2.save() + +        result = [ +            (u'{}="{}"'.format(loan_key , unicode(_(u"Yes"))), 0), +            (u'{}="{}"'.format(loan_key , unicode(_(u"No"))), 2), +        ] +        self._test_search(c, result, context="All container in their " +                                             "reference location") +        find2.container = container +        find2.save() + +        result = [ +            (u'{}="{}"'.format(loan_key , unicode(_(u"Yes"))), 1), +            (u'{}="{}"'.format(loan_key , unicode(_(u"No"))), 1), +        ] +        self._test_search(c, result, context="One container in his " +                                             "reference location") + +      def test_dynamic_field_search(self):          find = self.finds[0]          find2 = self.finds[1] @@ -750,14 +814,7 @@ class FindSearchTest(FindInit, TestCase):          ]          c.login(username=self.username, password=self.password) -        for q, expected_result in result: -            search = {'search_vector': q} -            response = c.get(reverse('get-find'), search) -            self.assertEqual(response.status_code, 200) -            res = json.loads(response.content) -            self.assertEqual(res['recordsTotal'], expected_result, -                             msg="{} result(s) where expected for search:" -                                 " {}".format(expected_result, q)) +        self._test_search(c, result)  class FindPermissionTest(FindInit, TestCase): | 
