summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/tests.py45
-rw-r--r--ishtar_common/wizards.py5
2 files changed, 45 insertions, 5 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 33199dd04..9a61d8bbb 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -705,22 +705,59 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase):
form_datas={
'general-operation_creation': {
'operation_type': 1, # preventive diag
- 'year': 2016}
+ 'year': 2016},
+ 'townsgeneral-operation_creation': [],
+ 'parcelsgeneral-operation_creation': [],
},
ignored=('filechoice-operation_creation',
- 'preventive-operation_creation',
'towns-operation_creation',
- 'parcels-operation_creation', )
+ 'parcels-operation_creation',
+ 'preventive-operation_creation',)
+ ),
+ FormData(
+ "Create another preventive diag with same parcel name",
+ form_datas={
+ 'general-operation_creation': {
+ 'operation_type': 1, # preventive diag
+ 'year': 2016},
+ 'townsgeneral-operation_creation': [],
+ 'parcelsgeneral-operation_creation': [],
+ },
+ ignored=('filechoice-operation_creation',
+ 'towns-operation_creation',
+ 'parcels-operation_creation',
+ 'preventive-operation_creation',)
)
]
def pre_wizard(self):
+ if 'townsgeneral-operation_creation' not in \
+ self.form_datas[0].form_datas:
+ return super(OperationWizardCreationTest, self).pre_wizard()
+ town = self.create_towns()[0]
+ town_data = {'town': town.pk}
+ self.form_datas[0].form_datas['townsgeneral-operation_creation'].append(
+ town_data
+ )
+ self.form_datas[1].form_datas['townsgeneral-operation_creation'].append(
+ town_data
+ )
+ parcel_data = {
+ 'town': town.pk, 'year': 2017, 'section': 'S',
+ 'parcel_number': '42'}
+ self.form_datas[0].form_datas[
+ 'parcelsgeneral-operation_creation'].append(parcel_data)
+ self.form_datas[1].form_datas[
+ 'parcelsgeneral-operation_creation'].append(parcel_data)
self.operation_number = models.Operation.objects.count()
+ self.parcel_number = models.Parcel.objects.count()
super(OperationWizardCreationTest, self).pre_wizard()
def post_wizard(self):
self.assertEqual(models.Operation.objects.count(),
- self.operation_number + 1)
+ self.operation_number + 2)
+ self.assertEqual(models.Parcel.objects.count(),
+ self.parcel_number + 2)
class OperationWizardDeleteTest(OperationWizardCreationTest):
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 735ad62fd..5105418a5 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -670,7 +670,10 @@ class Wizard(NamedUrlWizardView):
model.RELATIVE_MODELS:
value[model.RELATIVE_MODELS[
self.get_saved_model()]] = obj
- value, created = model.objects.get_or_create(**value)
+ value, created = model.objects.get_or_create(
+ **value)
+ else:
+ value = model.objects.create(**value)
value.save() # force post_save
# check that an item is not add multiple times (forged forms)
if value not in related_model.all() and\