diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/tests.py | 104 | ||||
| -rw-r--r-- | archaeological_operations/views.py | 52 | ||||
| -rw-r--r-- | archaeological_operations/wizards.py | 4 |
3 files changed, 116 insertions, 44 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index c22cf4b37..5eeeb1808 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2012-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -29,13 +29,16 @@ from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import Client -from django.contrib.auth.models import User, Permission +from django.contrib.auth.models import Permission import models +from archaeological_operations import views + from ishtar_common.models import OrganizationType, Organization, \ ImporterType, IshtarUser, TargetKey from ishtar_common import forms_common +from ishtar_common.tests import WizardTest, create_superuser, create_user class ImportOperationTest(TestCase): @@ -416,23 +419,6 @@ class ImportOperationTest(TestCase): "recognized in \"%s\"" % (str(not_imported), value)) -def create_superuser(): - username = 'username4277' - password = 'dcbqj756456!@%' - user = User.objects.create_superuser(username, "nomail@nomail.com", - password) - return username, password, user - - -def create_user(): - username = 'username678' - password = 'dcbqj756456!@%' - user = User.objects.create_user(username, email="nomail2@nomail.com") - user.set_password(password) - user.save() - return username, password, user - - def create_orga(user): orga_type, created = OrganizationType.objects.get_or_create( txt_idx='operator') @@ -626,3 +612,83 @@ class RegisterTest(TestCase, OperationInitTest): self.assertTrue(json.loads(response.content)['total'] == 1) response = c.get(reverse('get-administrativeact'), {'indexed': '2'}) self.assertTrue(json.loads(response.content)['total'] == 1) + + +class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): + fixtures = [settings.ROOT_PATH + + '../fixtures/initial_data-auth-fr.json', + settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_data-fr.json', + settings.ROOT_PATH + + '../archaeological_files/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_operations/fixtures/initial_data-fr.json'] + url_name = 'operation_creation' + wizard_name = 'operation_wizard' + steps = views.wizard_steps + form_datas = [( + # data + { + 'general-operation_creation': { + 'operation_type': 1, # preventive diag + 'year': 2016} + }, + # ignored + ('filechoice-operation_creation', + 'preventive-operation_creation', + 'towns-operation_creation', + 'parcels-operation_creation', + ) + )] + + def pre_wizard(self): + self.operation_number = models.Operation.objects.count() + super(OperationWizardCreationTest, self).pre_wizard() + + def post_wizard(self): + self.assertEqual(models.Operation.objects.count(), + self.operation_number + 1) + + +class OperationAdminActWizardCreationTest(WizardTest, OperationInitTest, + TestCase): + fixtures = [settings.ROOT_PATH + + '../fixtures/initial_data-auth-fr.json', + settings.ROOT_PATH + + '../ishtar_common/fixtures/initial_data-fr.json', + settings.ROOT_PATH + + '../archaeological_files/fixtures/initial_data.json', + settings.ROOT_PATH + + '../archaeological_operations/fixtures/initial_data-fr.json'] + url_name = 'operation_administrativeactop' + wizard_name = 'operation_administrative_act_wizard' + steps = views.administrativeactop_steps + form_datas = [[ + # data + { + 'selec-operation_administrativeactop': { + }, + 'administrativeact-operation_administrativeactop': { + 'signature_date': str(datetime.date.today()) + } + }, + # ignored + [] + ]] + + def pre_wizard(self): + ope = self.get_default_operation() + + self.number = models.AdministrativeAct.objects.count() + + data = self.form_datas[0][0] + data['selec-operation_administrativeactop']['pk'] = ope.pk + act = models.ActType.objects.filter(intented_to='O').all()[0].pk + + data['administrativeact-operation_administrativeactop'][ + 'act_type'] = act + super(OperationAdminActWizardCreationTest, self).pre_wizard() + + def post_wizard(self): + self.assertEqual(models.AdministrativeAct.objects.count(), + self.number + 1) diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 14160266b..d9baa4b7a 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -253,27 +253,29 @@ def check_files_for_operation(self): return False return get_current_profile().files +ope_crea_condition_dict = { + 'filechoice-operation_creation': + check_files_for_operation, + 'preventive-operation_creation': + is_preventive('general-operation_creation', models.OperationType, + 'operation_type', 'prev_excavation'), + 'preventivediag-operation_creation': + is_preventive('general-operation_creation', models.OperationType, + 'operation_type', 'arch_diagnostic'), + 'townsgeneral-operation_creation': has_associated_file( + 'filechoice-operation_creation', negate=True), + 'towns-operation_creation': has_associated_file( + 'filechoice-operation_creation'), + 'parcelsgeneral-operation_creation': has_associated_file( + 'filechoice-operation_creation', negate=True), + 'parcels-operation_creation': has_associated_file( + 'filechoice-operation_creation'), +} + operation_creation_wizard = OperationWizard.as_view( wizard_steps, label=_(u"New operation"), - condition_dict={ - 'filechoice-operation_creation': - check_files_for_operation, - 'preventive-operation_creation': - is_preventive('general-operation_creation', models.OperationType, - 'operation_type', 'prev_excavation'), - 'preventivediag-operation_creation': - is_preventive('general-operation_creation', models.OperationType, - 'operation_type', 'arch_diagnostic'), - 'townsgeneral-operation_creation': has_associated_file( - 'filechoice-operation_creation', negate=True), - 'towns-operation_creation': has_associated_file( - 'filechoice-operation_creation'), - 'parcelsgeneral-operation_creation': has_associated_file( - 'filechoice-operation_creation', negate=True), - 'parcels-operation_creation': has_associated_file( - 'filechoice-operation_creation'), - }, + condition_dict=ope_crea_condition_dict, url_name='operation_creation',) operation_modification_wizard = OperationModificationWizard.as_view([ @@ -382,12 +384,16 @@ operation_administrativeactop_search_wizard = SearchWizard.as_view([ label=_(u"Administrative act search"), url_name='operation_administrativeactop_search',) +administrativeactop_steps = [ + ('selec-operation_administrativeactop', OperationFormSelection), + ('administrativeact-operation_administrativeactop', + AdministrativeActOpeForm), + ('final-operation_administrativeactop', FinalForm)] + + operation_administrativeactop_wizard = \ - OperationAdministrativeActWizard.as_view([ - ('selec-operation_administrativeactop', OperationFormSelection), - ('administrativeact-operation_administrativeactop', - AdministrativeActOpeForm), - ('final-operation_administrativeactop', FinalForm)], + OperationAdministrativeActWizard.as_view( + administrativeactop_steps, label=_(u"Operation: new administrative act"), url_name='operation_administrativeactop',) diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index c51b88d0b..ee8acd9c1 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2012-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2012-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -411,7 +411,7 @@ class OperationAdministrativeActWizard(OperationWizard): if wizard_done_window: dct['wizard_done_window'] = wizard_done_window # redirect to the generated doc - if r and r[0]: + if r and type(r) in (tuple, list) and r[0]: dct['redirect'] = reverse('generatedoc-administrativeactop', args=[admact.pk, r[0]]) # make the new object a default |
