summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/tests.py43
-rw-r--r--archaeological_operations/views.py4
-rw-r--r--ishtar_common/tests.py38
3 files changed, 47 insertions, 38 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 0b466c48c..a1c0781fc 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -19,6 +19,8 @@
import json
import datetime
+import StringIO
+import zipfile
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
@@ -33,7 +35,7 @@ from archaeological_operations import views
from ishtar_common.models import OrganizationType, Organization, ItemKey, \
ImporterType, IshtarUser, TargetKey, ImporterModel, IshtarSiteProfile, \
- Town, ImporterColumn, Person
+ Town, ImporterColumn, Person, DocumentTemplate
from archaeological_context_records.models import Unit
from ishtar_common import forms_common
@@ -245,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):
@@ -990,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,
@@ -1011,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):
@@ -1025,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 +
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 545f42b89..7f77eb694 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -449,6 +449,10 @@ def administrativeactfile_document(
AdministrativeActTreatmentFileFormSelection
search_form = AdministrativeActTreatmentFileFormSelection
document_type = 'TF'
+
+ if not request.user.has_perm('view_administrativeact',
+ models.AdministrativeAct):
+ return HttpResponse(content_type='text/plain')
dct = {}
if request.POST:
dct['search_form'] = search_form(request.POST)
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 953e91b61..63b46c40c 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -27,47 +27,16 @@ from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
from django.core.exceptions import ValidationError
from django.core.files.base import File as DjangoFile
-from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management import call_command
from django.core.urlresolvers import reverse
-from django.db import connection, transaction
from django.template.defaultfilters import slugify
from django.test import TestCase as BaseTestCase
from django.test.client import Client
from django.test.runner import DiscoverRunner
from ishtar_common import models
-from ishtar_common import forms_common
from ishtar_common.utils import post_save_point
-from archaeological_context_records.models import CRBulkView
-from archaeological_finds.models import BFBulkView, FBulkView, FirstBaseFindView
-
-"""
-from django.conf import settings
-import tempfile, datetime
-from zipfile import ZipFile, ZIP_DEFLATED
-
-from oook_replace.oook_replace import oook_replace
-
-class OOOGenerationTest(TestCase):
- def testGeneration(self):
- context = {'test_var':u"Testé", 'test_var2':u"",
- "test_date":datetime.date(2015, 1, 1)}
- tmp = tempfile.TemporaryFile()
- oook_replace("../ishtar_common/tests/test-file.odt", tmp, context)
- inzip = ZipFile(tmp, 'r', ZIP_DEFLATED)
- value = inzip.read('content.xml')
- self.assertTrue(u"Testé" in value or "Testé" in value)
- self.assertTrue("testé 2" not in value and "testé 2" not in value)
- self.assertTrue("2015" in value)
- lg, ct = settings.LANGUAGE_CODE.split('-')
- if lg == 'fr':
- self.assertTrue('janvier' in value)
- if lg == 'en':
- self.assertTrue('january' in value)
-"""
-
def create_superuser():
username = 'username4277'
@@ -237,8 +206,8 @@ class WizardTest(object):
next_form_is_checked = len(self.steps) > idx + 1 and \
self.steps[idx + 1][0] not in ignored
try:
- response = self.client.post(url, data,
- follow=not next_form_is_checked)
+ response = self.client.post(
+ url, data, follow=not next_form_is_checked)
except ValidationError as e:
# on ManagementForm data is missing or has been tampered
# error verify the wizard_name or step name
@@ -710,7 +679,8 @@ class ShortMenuTest(TestCase):
def test_treatment_file(self):
c = Client()
c.login(username=self.username, password=self.password)
- from archaeological_finds.models import TreatmentFile, TreatmentFileType
+ from archaeological_finds.models import TreatmentFile, \
+ TreatmentFileType
tf = TreatmentFile.objects.create(
type=TreatmentFileType.objects.create(),
year=2050