diff options
Diffstat (limited to 'ishtar_common/tests.py')
| -rw-r--r-- | ishtar_common/tests.py | 72 | 
1 files changed, 42 insertions, 30 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 63d80d5ab..7c8b2fd5c 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2015-2016 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2015-2017 É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 @@ -288,6 +288,38 @@ class WizardTest(object):              raise ValidationError(u"Errors: {} on {}.".format(                  u" ".join(errors), current_step)) +    @classmethod +    def wizard_post(cls, client, url, current_step, form_data=None, +                    follow=True): +        if not url: +            url = reverse(cls.url_name) +        data = { +            '{}{}-current_step'.format(cls.url_name, +                                       cls.wizard_name): [current_step], +        } +        if not form_data: +            form_data = [] + +        # reconstruct a POST request +        if type(form_data) in (list, tuple):  # is a formset +            for d_idx, item in enumerate(form_data): +                for k in item: +                    data['{}-{}-{}'.format( +                        current_step, d_idx, k)] = item[k] +        else: +            for k in form_data: +                data['{}-{}'.format(current_step, k)] = form_data[k] + +        try: +            response = client.post(url, data, follow=follow) +        except ValidationError as e: +            msg = u"Errors: {} on {}. On \"ManagementForm data is " \ +                  u"missing or...\" error verify the wizard_name or " \ +                  u"step name".format(u" - ".join(e.messages), +                                      current_step) +            raise ValidationError(msg) +        return response +      def test_wizard(self):          if self.pass_test():              return @@ -301,35 +333,14 @@ class WizardTest(object):                  current_step, current_form = step                  if current_step in ignored:                      continue -                data = { -                    '{}{}-current_step'.format(self.url_name, -                                               self.wizard_name): -                    [current_step], -                } - -                # reconstruct a POST request -                if current_step in form_data: -                    d = form_data[current_step] -                    if type(d) in (list, tuple):  # is a formset -                        for d_idx, item in enumerate(d): -                            for k in item: -                                data['{}-{}-{}'.format( -                                    current_step, d_idx, k)] = item[k] -                    else: -                        for k in d: -                            data['{}-{}'.format(current_step, k)] = d[k] -                  next_form_is_checked = len(self.steps) > idx + 1 and \ -                    self.steps[idx + 1][0] not in ignored -                try: -                    response = self.client.post( -                        url, data, follow=not next_form_is_checked) -                except ValidationError as e: -                    msg = u"Errors: {} on {}. On \"ManagementForm data is " \ -                          u"missing or...\" error verify the wizard_name or " \ -                          u"step name".format(u" - ".join(e.messages), -                                              current_step) -                    raise ValidationError(msg) +                                       self.steps[idx + 1][0] not in ignored +                data = [] +                if current_step in form_data: +                    data = form_data[current_step] +                response = self.wizard_post( +                    self.client, url, current_step, data, +                    not next_form_is_checked)                  self.check_response(response, current_step)                  if next_form_is_checked:                      next_form = self.steps[idx + 1][0] @@ -402,7 +413,8 @@ class AdminGenTypeTest(TestCase):      gen_models = [          models.OrganizationType, models.PersonType, models.TitleType,          models.AuthorType, models.SourceType, models.OperationType, -        models.SpatialReferenceSystem, models.Format, models.SupportType] +        models.SpatialReferenceSystem, models.Format, models.SupportType, +    ]      models_with_data = gen_models + [models.ImporterModel]      models = models_with_data      module_name = 'ishtar_common' | 
