diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/tests.py | 60 | ||||
| -rw-r--r-- | archaeological_operations/views.py | 38 | 
2 files changed, 61 insertions, 37 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index c22cf4b37..29a7fdb00 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,39 @@ 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) diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 14160266b..90f71abfe 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([ | 
