diff options
| -rw-r--r-- | archaeological_operations/tests.py | 42 | ||||
| -rw-r--r-- | archaeological_operations/views.py | 14 | ||||
| -rw-r--r-- | archaeological_operations/wizards.py | 2 | ||||
| -rw-r--r-- | ishtar_common/tests.py | 21 | 
4 files changed, 71 insertions, 8 deletions
| 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  <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 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)) | 
