From 3e3a3c7147310980874307a96db500af677a4377 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 4 Jul 2016 15:03:04 +0200 Subject: Test wizard --- archaeological_operations/tests.py | 60 ++++++++++++++++++++++++++------------ archaeological_operations/views.py | 38 ++++++++++++------------ 2 files changed, 61 insertions(+), 37 deletions(-) (limited to 'archaeological_operations') 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 +# Copyright (C) 2012-2016 Étienne Loks # 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([ -- cgit v1.2.3 From d3577c944b73dd80a30c74f0da33d65f33c72cd9 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 16 Jul 2016 14:56:15 +0200 Subject: Test administrativ act creation - improve test wizard --- archaeological_operations/tests.py | 42 ++++++++++++++++++++++++++++++++++++ archaeological_operations/views.py | 14 +++++++----- archaeological_operations/wizards.py | 2 +- ishtar_common/tests.py | 21 ++++++++++++++++-- 4 files changed, 71 insertions(+), 8 deletions(-) (limited to 'archaeological_operations') diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 29a7fdb00..5b7f71e1b 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -648,3 +648,45 @@ class OperationWizardCreationTest(WizardTest, OperationInitTest, TestCase): 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.operation_number = models.Operation.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.Operation.objects.count(), + self.operation_number + 1) diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index 90f71abfe..d9baa4b7a 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -384,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..0cc336cc8 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 +# Copyright (C) 2012-2016 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 63bf73eb7..1b8601dfb 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -17,10 +17,13 @@ # See the file COPYING for details. +from BeautifulSoup import BeautifulSoup as Soup + from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.core.cache import cache +from django.core.exceptions import ValidationError from django.core.urlresolvers import reverse from django.template.defaultfilters import slugify from django.test import TestCase @@ -72,7 +75,7 @@ def create_user(): class WizardTest(object): - url = None + url_name = None wizard_name = '' steps = None condition_dict = None @@ -114,7 +117,21 @@ class WizardTest(object): next_idx = next_idx + 1 if next_form: - response = self.client.post(url, data) + try: + response = self.client.post(url, data) + except ValidationError as e: + raise ValidationError(u"Errors: {} on {}.".format( + u" - ".join(e.messages), current_step)) + if "errorlist" in response.content: + soup = Soup(response.content) + errorlist = soup.findAll( + "ul", {"class": "errorlist"}) + errors = [] + for li in errorlist: + lbl = li.findParent().findParent().findChild().text + errors.append(u"{} - {}".format(lbl, li.text)) + raise ValidationError(u"Errors: {} on {}.".format( + u" ".join(errors), current_step)) self.assertRedirects( response, '/{}/{}'.format(self.url_name, next_form)) -- cgit v1.2.3 From b13bff8a000d693cd16b8246f1b06cda240c2141 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 16 Jul 2016 16:22:20 +0200 Subject: Admin Act: fix redir when no document exists --- archaeological_operations/tests.py | 8 +++++--- archaeological_operations/wizards.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'archaeological_operations') diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 5b7f71e1b..5eeeb1808 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -678,7 +678,9 @@ class OperationAdminActWizardCreationTest(WizardTest, OperationInitTest, def pre_wizard(self): ope = self.get_default_operation() - self.operation_number = models.Operation.objects.count() + + 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 @@ -688,5 +690,5 @@ class OperationAdminActWizardCreationTest(WizardTest, OperationInitTest, super(OperationAdminActWizardCreationTest, self).pre_wizard() def post_wizard(self): - self.assertEqual(models.Operation.objects.count(), - self.operation_number + 1) + self.assertEqual(models.AdministrativeAct.objects.count(), + self.number + 1) diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 0cc336cc8..ee8acd9c1 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -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 -- cgit v1.2.3