diff options
Diffstat (limited to 'archaeological_context_records/tests.py')
| -rw-r--r-- | archaeological_context_records/tests.py | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 2bd144c5e..614156528 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -17,16 +17,17 @@ # See the file COPYING for details. -""" -Unit tests -""" +import json from django.conf import settings from django.core.exceptions import ValidationError from django.core.files.uploadedfile import SimpleUploadedFile +from django.core.urlresolvers import reverse from django.test import TestCase +from django.test.client import Client -from ishtar_common.models import ImporterType +from ishtar_common.models import ImporterType, IshtarSiteProfile +from ishtar_common.tests import create_superuser from archaeological_operations.tests import OperationInitTest, \ ImportOperationTest from archaeological_context_records import models @@ -108,16 +109,58 @@ class ContextRecordInit(OperationInitTest): def get_default_context_record(self): return self.create_context_record()[0] + def tearDown(self): + if hasattr(self, 'context_records'): + for cr in self.context_records: + try: + cr.delete() + except: + pass + self.context_records = [] + super(ContextRecordInit, self).tearDown() + + +class ContextRecordTest(ContextRecordInit, TestCase): + fixtures = ImportContextRecordTest.fixtures + + 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"}) + + cr_1 = self.context_records[0] + cr_2 = self.context_records[1] + sym_rel_type = models.RelationType.objects.filter( + symmetrical=True).all()[0] + 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 + self.assertTrue(not json.loads(response.content)) + c.login(username=self.username, password=self.password) + response = c.get(reverse('get-contextrecord')) + self.assertTrue(json.loads(response.content)['total'] == 2) + # export + response = c.get(reverse('get-contextrecord-full', + kwargs={'type': 'csv'}), {'submited': '1'}) + # 2 lines + header + lines = [line for line in response.content.split('\n') if line] + self.assertEqual(len(lines), 3) + + def testZExternalID(self): + cr = self.context_records[0] + self.assertEqual( + cr.external_id, + u"{}-{}".format(cr.parcel.external_id, cr.label)) + -class RecordRelationsTest(TestCase, ContextRecordInit): - fixtures = [settings.ROOT_PATH + - '../fixtures/initial_data.json', - settings.ROOT_PATH + - '../ishtar_common/fixtures/initial_data.json', - settings.ROOT_PATH + - '../archaeological_files/fixtures/initial_data.json', - settings.ROOT_PATH + - '../archaeological_operations/fixtures/initial_data-fr.json'] +class RecordRelationsTest(ContextRecordInit, TestCase): + fixtures = ImportOperationTest.fixtures model = models.ContextRecord def setUp(self): |
