diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-24 17:15:39 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-24 17:15:39 +0100 |
commit | 0a280ab1b2a3623780b74528d67debddd891fc6c (patch) | |
tree | 656c573a9fe6bcba550d0d87d1290779b8fb93f8 /archaeological_operations/tests.py | |
parent | d3145603feb093f4b6f7c3b0a64cfff547a683fa (diff) | |
download | Ishtar-0a280ab1b2a3623780b74528d67debddd891fc6c.tar.bz2 Ishtar-0a280ab1b2a3623780b74528d67debddd891fc6c.zip |
Wizard tests improvements. Test inappropriate parcel deletion.
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r-- | archaeological_operations/tests.py | 165 |
1 files changed, 163 insertions, 2 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 9cdeb67e6..a9fdf38cc 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -619,7 +619,11 @@ class OperationInitTest(object): def get_default_parcel(self, force=False): if force: return self.create_parcel()[-1] - return self.create_parcel()[0] + parcel = self.create_parcel()[0] + if models.Parcel.objects.filter(pk=parcel.pk).count(): + return parcel + self.parcels.pop(0) + return self.create_operation()[-1] def create_operation(self, user=None, orga=None): if not orga: @@ -634,7 +638,12 @@ class OperationInitTest(object): def get_default_operation(self, force=False): if force: return self.create_operation()[-1] - return self.create_operation()[0] + ope = self.create_operation()[0] + if models.Operation.objects.filter(pk=ope.pk).count(): + return ope + self.operations.pop(0) + return self.create_operation()[-1] + def tearDown(self): # cleanup for further test @@ -976,6 +985,158 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): self.parcel_number + 2) +class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): + fixtures = OperationWizardCreationTest.fixtures + url_name = 'operation_modification' + wizard_name = url_name + '_wizard' + steps = views.operation_modif_wizard_steps + base_ignored_steps = ( + 'archaeologicalsite-operation_modification', + 'preventive-operation_modification', + 'preventivediag-operation_modification', + 'towns-operation_modification', + 'parcels-operation_modification', + 'remains-operation_modification', + 'periods-operation_modification', + 'relations-operation_modification', + 'abstract-operation_modification',) + form_datas = [ + FormData( + "Update an operation", + form_datas={ + 'selec-operation_modification': {}, + 'general-operation_modification': { + 'operation_type': 2, + 'year': 2017}, + 'townsgeneral-operation_modification': [], + 'parcelsgeneral-operation_modification': [], + }, + ignored=base_ignored_steps + ), + FormData( + "Operation: try to remove a parcel with attached context record", + form_datas={ + 'selec-operation_modification': {}, + 'general-operation_modification': { + 'operation_type': 2, + 'year': 2017}, + 'townsgeneral-operation_modification': [], + 'parcelsgeneral-operation_modification': [], + }, + ignored=base_ignored_steps + ), + FormData( + "Operation: remove a parcel with no attached context record", + form_datas={ + 'selec-operation_modification': {}, + 'general-operation_modification': { + 'operation_type': 2, + 'year': 2017}, + 'townsgeneral-operation_modification': [], + 'parcelsgeneral-operation_modification': [], + }, + ignored=base_ignored_steps + ), + ] + + def pre_wizard(self): + self.create_operation() + operation = self.operations[0] + init_town = self.create_towns()[0] + operation.towns.add(init_town) + init_parcel = self.create_parcel()[0] + operation.parcels.add(init_parcel) + + from archaeological_context_records.models import ContextRecord + cr_data = {'label': "Context record", "operation": operation, + 'parcel': init_parcel, + 'history_modifier': self.get_default_user()} + self.cr = ContextRecord.objects.create(**cr_data) + + data = self.form_datas[0].form_datas + data2 = self.form_datas[1].form_datas + data3 = self.form_datas[2].form_datas + + data['selec-operation_modification']['pk'] = operation.pk + data2['selec-operation_modification']['pk'] = operation.pk + data3['selec-operation_modification']['pk'] = operation.pk + + town = self.create_towns( + datas={'numero_insee': '67890', 'name': 'Twin Peaks'})[-1] + towns = [{'town': town.pk}, {'town': init_town.pk}] + data['townsgeneral-operation_modification'] = towns + data2['townsgeneral-operation_modification'] = towns + data3['townsgeneral-operation_modification'] = towns + + parcel_data = { + 'town': town.pk, 'year': 2017, 'section': 'S', + 'parcel_number': '42'} + data['parcelsgeneral-operation_modification'].append(parcel_data) + data2['parcelsgeneral-operation_modification'].append(parcel_data) + data3['parcelsgeneral-operation_modification'].append(parcel_data) + + parcel_data_2 = { + 'town': init_parcel.town.pk, 'year': init_parcel.year or '', + 'section': init_parcel.section, + 'parcel_number': init_parcel.parcel_number} + data['parcelsgeneral-operation_modification'].append(parcel_data_2) + # no init parcel for data2 and data3 + + self.operation_number = models.Operation.objects.count() + self.parcel_number = models.Parcel.objects.count() + + def post_first_wizard(test_object, final_step_response): + test_object.assertEqual(models.Operation.objects.count(), + test_object.operation_number) + operation = models.Operation.objects.get( + pk=test_object.operations[0].pk) + test_object.assertEqual(operation.operation_type.pk, 2) + test_object.assertEqual(operation.year, 2017) + test_object.assertEqual(models.Parcel.objects.count(), + test_object.parcel_number + 1) + test_object.assertEqual(operation.parcels.count(), + test_object.parcel_number + 1) + + def post_second_wizard(test_object, final_step_response): + test_object.assertEqual(models.Operation.objects.count(), + test_object.operation_number) + operation = models.Operation.objects.get( + pk=test_object.operations[0].pk) + test_object.assertEqual(operation.operation_type.pk, 2) + test_object.assertEqual(operation.year, 2017) + test_object.assertEqual(models.Parcel.objects.count(), + test_object.parcel_number + 1) + # the init parcel is not submited but have a context record + # the init parcel is not detached from the operation + test_object.assertEqual(operation.parcels.count(), + test_object.parcel_number + 1) + + def pre_third_wizard(test_object): + parcel_nb = models.Parcel.objects.count() + test_object.cr.delete() + test_object.assertEqual( + parcel_nb, models.Parcel.objects.count()) + + def post_third_wizard(test_object, final_step_response): + test_object.assertEqual(models.Operation.objects.count(), + test_object.operation_number) + operation = models.Operation.objects.get( + pk=test_object.operations[0].pk) + test_object.assertEqual(operation.operation_type.pk, 2) + test_object.assertEqual(operation.year, 2017) + # with no attach the parcel is deleted + test_object.assertEqual(operation.parcels.count(), + test_object.parcel_number) + test_object.assertEqual(models.Parcel.objects.count(), + test_object.parcel_number) + + self.form_datas[0].extra_tests = [post_first_wizard] + self.form_datas[1].extra_tests = [post_second_wizard] + self.form_datas[2].pre_tests = [pre_third_wizard] + self.form_datas[2].extra_tests = [post_third_wizard] + super(OperationWizardModifTest, self).pre_wizard() + + class OperationWizardDeleteTest(OperationWizardCreationTest): fixtures = OperationWizardCreationTest.fixtures url_name = 'operation_deletion' |