summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/tests.py53
-rw-r--r--archaeological_finds/views.py8
-rw-r--r--archaeological_finds/wizards.py5
-rw-r--r--archaeological_operations/tests.py6
-rw-r--r--archaeological_warehouse/models.py4
-rw-r--r--ishtar_common/tests.py27
6 files changed, 83 insertions, 20 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index b5096ae01..4153a79ad 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -17,6 +17,8 @@
# See the file COPYING for details.
+import datetime
+
from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
@@ -24,6 +26,7 @@ from ishtar_common.models import ImporterType, IshtarUser, ImporterColumn,\
FormaterType, ImportTarget
from ishtar_common.models import Person
+from archaeological_context_records.models import ContextRecord
from archaeological_finds import models, views
from archaeological_warehouse.models import Warehouse, WarehouseType
@@ -80,6 +83,56 @@ class FindInit(ContextRecordInit):
self.base_find = []
+class AFindWizardCreationTest(WizardTest, FindInit, TestCase):
+ # TODO: first to be run because of strange init things...
+ 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',
+ settings.ROOT_PATH +
+ '../archaeological_finds/fixtures/initial_data-fr.json',
+ settings.ROOT_PATH +
+ '../archaeological_warehouse/fixtures/initial_data-fr.json',
+ ]
+ url_name = 'find_creation'
+ wizard_name = 'find_wizard'
+ steps = views.find_creation_steps
+ form_datas = [
+ FormData(
+ 'Find creation',
+ form_datas={
+ 'selecrecord-find_creation': {'pk': 1},
+ 'find-find_creation': {
+ 'label': 'hop',
+ 'checked': 'NC',
+ 'check_date': '2016-01-01'
+ },
+ 'dating-find_creation': []
+ },
+ )
+ ]
+
+ def pre_wizard(self):
+ q = ContextRecord.objects.filter(pk=1)
+ if not q.count():
+ cr = self.create_context_record()[0]
+ cr.pk = 1
+ cr.save()
+ self.find_number = models.Find.objects.count()
+ self.basefind_number = models.BaseFind.objects.count()
+ super(AFindWizardCreationTest, self).pre_wizard()
+
+ def post_wizard(self):
+ self.assertEqual(models.BaseFind.objects.count(),
+ self.basefind_number + 1)
+ self.assertEqual(models.Find.objects.count(),
+ self.find_number + 1)
+
+
class ATreatmentWizardCreationTest(WizardTest, FindInit, TestCase):
# TODO: first to be run because of strange init things...
fixtures = [settings.ROOT_PATH +
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index 52144cadd..ef8dfb16b 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -112,11 +112,15 @@ revert_find = revert_item(models.Find)
show_findbasket = show_item(models.FindBasket, 'findbasket')
-find_creation_wizard = FindWizard.as_view([
+find_creation_steps = [
('selecrecord-find_creation', RecordFormSelectionTable),
('find-find_creation', FindForm),
('dating-find_creation', DatingFormSet),
- ('final-find_creation', FinalForm)],
+ ('final-find_creation', FinalForm)
+]
+
+find_creation_wizard = FindWizard.as_view(
+ find_creation_steps,
label=_(u"New find"),
url_name='find_creation',)
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index c9d492329..d7e3dbac0 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -25,6 +25,7 @@ from ishtar_common.wizards import Wizard, DeletionWizard, SourceWizard
from archaeological_operations.wizards import OperationAdministrativeActWizard
from archaeological_operations.models import AdministrativeAct
+from archaeological_context_records.models import ContextRecord
import models
@@ -40,7 +41,7 @@ class FindWizard(Wizard):
main_form_key = 'selecrecord-' + self.url_name
try:
idx = int(self.session_get_value(main_form_key, 'pk'))
- current_cr = models.ContextRecord.objects.get(pk=idx)
+ current_cr = ContextRecord.objects.get(pk=idx)
return current_cr
except(TypeError, ValueError, ObjectDoesNotExist):
pass
@@ -66,7 +67,7 @@ class FindWizard(Wizard):
def get_extra_model(self, dct, form_list):
dct = super(FindWizard, self).get_extra_model(dct, form_list)
dct['order'] = 1
- if 'pk' in dct and type(dct['pk']) == models.ContextRecord:
+ if 'pk' in dct and type(dct['pk']) == ContextRecord:
dct['base_finds__context_record'] = dct.pop('pk')
return dct
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 80569fb1b..93c4fbe92 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -673,9 +673,9 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase):
FormData(
"Create a preventive diag",
form_datas={
- 'general-operation_creation': {
- 'operation_type': 1, # preventive diag
- 'year': 2016}
+ 'general-operation_creation': {
+ 'operation_type': 1, # preventive diag
+ 'year': 2016}
},
ignored=('filechoice-operation_creation',
'preventive-operation_creation',
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 0872df220..0eb19814d 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -149,8 +149,8 @@ class Container(LightHistorizedItem):
def precise_location(self):
location = unicode(self.location)
locas = [
- u"{} {}".format(loca.division.division, loca.reference)
- for loca in ContainerLocalisation.objects.filter(
+ u"{} {}".format(loca.division.division, loca.reference)
+ for loca in ContainerLocalisation.objects.filter(
container=self)
]
return location + u" - " + u", ".join(locas)
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index dbe3df4a5..095956090 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -118,6 +118,18 @@ class WizardTest(object):
def post_wizard(self):
pass
+ def check_response(self, response, current_step):
+ if "errorlist" in response.content:
+ soup = Soup(response.content)
+ errorlist = soup.findAll(
+ "ul", {"class": "errorlist"})
+ errors = []
+ for li in errorlist:
+ lbl = li.findParent().findParent().findChild().text
+ errors.append(u"{} - {}".format(lbl, li.text))
+ raise ValidationError(u"Errors: {} on {}.".format(
+ u" ".join(errors), current_step))
+
def test_wizard(self):
url = reverse(self.url_name)
self.pre_wizard()
@@ -144,28 +156,21 @@ class WizardTest(object):
next_form = self.steps[idx + 1][0]
break
next_idx = next_idx + 1
-
if next_form:
try:
response = self.client.post(url, data)
except ValidationError as e:
+ # on ManagementForm data is missing or has been tampered
+ # error verify the wizard_name or step name
raise ValidationError(u"Errors: {} on {}.".format(
u" - ".join(e.messages), current_step))
- if "errorlist" in response.content:
- soup = Soup(response.content)
- errorlist = soup.findAll(
- "ul", {"class": "errorlist"})
- errors = []
- for li in errorlist:
- lbl = li.findParent().findParent().findChild().text
- errors.append(u"{} - {}".format(lbl, li.text))
- raise ValidationError(u"Errors: {} on {}.".format(
- u" ".join(errors), current_step))
+ self.check_response(response, current_step)
self.assertRedirects(
response,
'/{}/{}'.format(self.url_name, next_form))
else:
response = self.client.post(url, data, follow=True)
+ self.check_response(response, current_step)
test_form_data.tests(self, response)
self.post_wizard()