diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-07-04 15:03:04 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-07-04 15:03:04 +0200 |
commit | 131a0ff3b009a879ebc0119396b8ee5e8e38a807 (patch) | |
tree | d0a09ef3861b093b055c73b9cad30f8bf2be5b06 | |
parent | 415c9e56882b1ab78afed0376ce643dc079ea0b8 (diff) | |
download | Ishtar-131a0ff3b009a879ebc0119396b8ee5e8e38a807.tar.bz2 Ishtar-131a0ff3b009a879ebc0119396b8ee5e8e38a807.zip |
Test wizard
-rw-r--r-- | archaeological_operations/tests.py | 60 | ||||
-rw-r--r-- | archaeological_operations/views.py | 38 | ||||
-rw-r--r-- | ishtar_common/tests.py | 69 |
3 files changed, 130 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([ diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 82ab009e0..63bf73eb7 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -54,6 +54,75 @@ class OOOGenerationTest(TestCase): """ +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 + + +class WizardTest(object): + url = None + wizard_name = '' + steps = None + condition_dict = None + form_datas = [] + + def setUp(self): + self.username, self.password, self.user = create_superuser() + + def pre_wizard(self): + self.client.login(**{'username': self.username, + 'password': self.password}) + + def post_wizard(self): + pass + + def test_wizard(self): + url = reverse(self.url_name) + self.pre_wizard() + for form_data, ignored in self.form_datas: + for idx, step in enumerate(self.steps): + current_step, current_form = step + if current_step in ignored: + continue + data = { + '{}{}-current_step'.format(self.url_name, + self.wizard_name): + [current_step], + } + if current_step in form_data: + d = form_data[current_step] + for k in d: + data['{}-{}'.format(current_step, k)] = d[k] + + next_idx, next_form = idx + 1, None + while len(self.steps) > next_idx: + if self.steps[idx + 1][0] not in ignored: + next_form = self.steps[idx + 1][0] + break + next_idx = next_idx + 1 + + if next_form: + response = self.client.post(url, data) + self.assertRedirects( + response, + '/{}/{}'.format(self.url_name, next_form)) + else: + response = self.client.post(url, data, follow=True) + self.post_wizard() + + class MergeTest(TestCase): def setUp(self): self.user, created = User.objects.get_or_create(username='username') |