diff options
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r-- | archaeological_context_records/tests.py | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 2bd144c5e..07da79c8a 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.tests import create_superuser from archaeological_operations.tests import OperationInitTest, \ ImportOperationTest from archaeological_context_records import models @@ -109,15 +110,40 @@ class ContextRecordInit(OperationInitTest): return self.create_context_record()[0] +class ContextRecordTest(TestCase, ContextRecordInit): + fixtures = ImportContextRecordTest.fixtures + + def setUp(self): + 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) + + 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'] + fixtures = ImportOperationTest.fixtures model = models.ContextRecord def setUp(self): |