From 3e3a3c7147310980874307a96db500af677a4377 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 4 Jul 2016 15:03:04 +0200 Subject: Test wizard --- ishtar_common/tests.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'ishtar_common') 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') -- 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 'ishtar_common') 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 ef0995c8045e432df3e578c3142381100a244a25 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 16 Jul 2016 19:52:57 +0200 Subject: Fixtures: fix persontype rights --- ishtar_common/fixtures/initial_data-fr.json | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/fixtures/initial_data-fr.json b/ishtar_common/fixtures/initial_data-fr.json index 48793410f..24a0d7a6c 100644 --- a/ishtar_common/fixtures/initial_data-fr.json +++ b/ishtar_common/fixtures/initial_data-fr.json @@ -59,16 +59,13 @@ "available": true, "txt_idx": "sra_agent", "groups": [ - 30, - 31, - 32, - 2, 1, - 4, + 2, 3, + 4, 5, - 7, 6, + 7, 8, 9, 10, @@ -86,7 +83,13 @@ 26, 27, 28, - 29 + 29, + 30, + 31, + 32, + 33, + 34, + 35 ], "label": "Agent SRA (prescripteur)" } @@ -131,7 +134,19 @@ "comment": "Article 13 D\u00e9cret 2004\r\n\r\nLe pr\u00e9fet de r\u00e9gion \u00e9dicte les prescriptions arch\u00e9ologiques, d\u00e9livre l'autorisation de fouille et d\u00e9signe le responsable scientifique de toute op\u00e9ration d'arch\u00e9ologie pr\u00e9ventive.\r\n\r\nLe responsable scientifique est l'interlocuteur du pr\u00e9fet de r\u00e9gion et le garant de la qualit\u00e9 scientifique de l'op\u00e9ration arch\u00e9ologique. A ce titre, il prend, dans le cadre de la mise en oeuvre du projet d'intervention de l'op\u00e9rateur, les d\u00e9cisions relatives \u00e0 la conduite scientifique de l'op\u00e9ration et \u00e0 l'\u00e9laboration du rapport dont il dirige la r\u00e9daction. Il peut \u00eatre diff\u00e9rent pour la r\u00e9alisation du diagnostic et pour la r\u00e9alisation de la fouille.", "available": true, "txt_idx": "head_scientist", - "groups": [], + "groups": [ + 30, + 32, + 1, + 4, + 6, + 15, + 21, + 25, + 33, + 34, + 35 + ], "label": "Responsable scientifique" } }, @@ -165,7 +180,7 @@ ], "label": "Secr\u00e9tariat SRA" } - }, + }, { "pk": 5, "model": "ishtar_common.organizationtype", -- cgit v1.2.3