diff options
Diffstat (limited to 'archaeological_context_records/tests.py')
| -rw-r--r-- | archaeological_context_records/tests.py | 39 | 
1 files changed, 36 insertions, 3 deletions
| diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 614156528..27ba0ab71 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -30,6 +30,7 @@ from ishtar_common.models import ImporterType, IshtarSiteProfile  from ishtar_common.tests import create_superuser  from archaeological_operations.tests import OperationInitTest, \      ImportOperationTest +from archaeological_operations import models as models_ope  from archaeological_context_records import models  from ishtar_common import forms_common @@ -126,18 +127,18 @@ class ContextRecordTest(ContextRecordInit, TestCase):      def setUp(self):          IshtarSiteProfile.objects.create()          self.username, self.password, self.user = create_superuser() -        self.create_context_record({"label": u"CR 1"}) -        self.create_context_record({"label": u"CR 2"}) +        self.create_context_record(data={"label": u"CR 1"}) +        self.create_context_record(data={"label": u"CR 2"})          cr_1 = self.context_records[0]          cr_2 = self.context_records[1]          sym_rel_type = models.RelationType.objects.filter(              symmetrical=True).all()[0] +        self.cr_rel_type = sym_rel_type          models.RecordRelations.objects.create(              left_record=cr_1, right_record=cr_2, relation_type=sym_rel_type)      def testSearchExport(self): -        "url = reverse()get-contextrecord-full/csv?submited=1&"          c = Client()          response = c.get(reverse('get-contextrecord'))          # no result when no authentification @@ -145,6 +146,38 @@ class ContextRecordTest(ContextRecordInit, TestCase):          c.login(username=self.username, password=self.password)          response = c.get(reverse('get-contextrecord'))          self.assertTrue(json.loads(response.content)['total'] == 2) +        # test search label +        response = c.get(reverse('get-contextrecord'), +                         {'label': 'cr 1'}) +        self.assertEqual(json.loads(response.content)['total'], 1) +        # test search between relations +        response = c.get(reverse('get-contextrecord'), +                         {'label': 'cr 1', +                          'relation_types_0': self.cr_rel_type.pk}) +        self.assertEqual(json.loads(response.content)['total'], 2) +        # test search between operation relations +        first_ope = self.operations[0] +        first_ope.year = 2010 +        first_ope.save() +        cr_1 = self.context_records[0] +        cr_1.operation = first_ope +        cr_1.save() +        other_ope = self.operations[1] +        other_ope.year = 2016 +        other_ope.save() +        cr_2 = self.context_records[1] +        cr_2.operation = other_ope +        cr_2.save() +        rel_ope = models_ope.RelationType.objects.create( +            symmetrical=True, label='Linked', txt_idx='link') +        models_ope.RecordRelations.objects.create( +            left_record=other_ope, +            right_record=first_ope, +            relation_type=rel_ope) +        response = c.get(reverse('get-contextrecord'), +                         {'operation__year': 2010, +                          'ope_relation_types_0': rel_ope.pk}) +        self.assertEqual(json.loads(response.content)['total'], 2)          # export          response = c.get(reverse('get-contextrecord-full',                                   kwargs={'type': 'csv'}), {'submited': '1'}) | 
