diff options
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index b2f38801a..230a66beb 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -19,12 +19,15 @@ import json import datetime +import StringIO +import zipfile from django.conf import settings from django.core.files.uploadedfile import SimpleUploadedFile from django.core.urlresolvers import reverse from django.test.client import Client +from django.contrib.auth.models import User from django.contrib.auth.models import Permission import models @@ -32,7 +35,7 @@ from archaeological_operations import views from ishtar_common.models import OrganizationType, Organization, ItemKey, \ ImporterType, IshtarUser, TargetKey, ImporterModel, IshtarSiteProfile, \ - Town, ImporterColumn, Person, Author, SourceType, AuthorType + Town, ImporterColumn, Person, Author, SourceType, AuthorType, DocumentTemplate from archaeological_context_records.models import Unit from ishtar_common import forms_common @@ -244,7 +247,8 @@ class ImportOperationTest(ImportTest, TestCase): self.assertEqual(len(impt.errors), 2) self.assertTrue( "Importer configuration error" in impt.errors[0]['error'] or - "Erreur de configuration de l\'importeur" in impt.errors[0]['error'] + "Erreur de configuration de l\'importeur" in + impt.errors[0]['error'] ) def test_model_limitation(self): @@ -593,11 +597,13 @@ def create_operation(user, orga=None, values={}): class OperationInitTest(object): def create_user(self): username, password, self.user = create_user() + return self.user def get_default_user(self): - if not hasattr(self, 'user') or not self.user: - self.create_user() - return self.user + q = User.objects.filter(is_superuser=False) + if q.count(): + return q.all()[0] + return self.create_user() def create_orgas(self, user=None): if not user: @@ -987,7 +993,7 @@ class OperationSearchTest(TestCase, OperationInitTest): def create_administrativact(user, operation): act_type, created = models.ActType.objects.get_or_create( - txt_idx='act_type') + txt_idx='act_type_O', intented_to='O') dct = {'history_modifier': user, 'act_type': act_type, 'operation': operation, @@ -1008,7 +1014,7 @@ class RegisterTest(TestCase, OperationInitTest): def setUp(self): self.username, self.password, self.user = create_superuser() self.operations = self.create_operation(self.user) - self.act_types, self.operations = create_administrativact( + self.act_types, self.admin_acts = create_administrativact( self.user, self.operations[0]) def testSearch(self): @@ -1022,6 +1028,38 @@ class RegisterTest(TestCase, OperationInitTest): response = c.get(reverse('get-administrativeact'), {'indexed': '2'}) self.assertTrue(json.loads(response.content)['total'] == 1) + def test_document_generation(self): + tpl = open( + settings.ROOT_PATH + + '../archaeological_operations/tests/document_reference.odt', + 'rb') + template = SimpleUploadedFile(tpl.name, tpl.read()) + doc = DocumentTemplate.objects.create( + name="Test", + associated_object_name=DocumentTemplate.CLASSNAMES[0][0], + available=True, + template=template + ) + self.act_types[0].associated_template.add(doc) + + c = Client() + data = {'pk': self.admin_acts[0].pk, 'document_template': doc.pk} + response = c.post(reverse('operation-administrativeact-document'), data) + # no result when no authentication + self.assertEqual(response.content, "") + c.login(username=self.username, password=self.password) + response = c.post(reverse('operation-administrativeact-document'), data) + try: + f = StringIO.StringIO(response.content) + z = zipfile.ZipFile(f) + self.assertIsNone(z.testzip()) + content = z.open('content.xml') + self.assertIn('2014-05-12', content.read()) + finally: + content.close() + z.close() + f.close() + class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): fixtures = [settings.ROOT_PATH + @@ -1266,7 +1304,7 @@ class OperationWizardDeleteTest(OperationWizardCreationTest): ] def pass_test(self): - if not settings.SOUTH_TESTS_MIGRATE: + if not settings.TEST_VIEWS: # with no migration the views are not created return True @@ -1404,4 +1442,4 @@ class OperationSourceWizardModificationTest(WizardTest, OperationInitTest, def post_wizard(self): source = models.OperationSource.objects.get(pk=self.source.pk) - self.assertEqual(source.authors.count(), 0)
\ No newline at end of file + self.assertEqual(source.authors.count(), 0) |