diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-24 17:15:39 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-24 17:15:39 +0100 | 
| commit | 930a01ef1ca7061a45486e6fc2373c7f2d10647f (patch) | |
| tree | 656c573a9fe6bcba550d0d87d1290779b8fb93f8 /ishtar_common | |
| parent | b9ae69e4a58f21baf942ce4e4901d5d973b85bbd (diff) | |
| download | Ishtar-930a01ef1ca7061a45486e6fc2373c7f2d10647f.tar.bz2 Ishtar-930a01ef1ca7061a45486e6fc2373c7f2d10647f.zip | |
Wizard tests improvements. Test inappropriate parcel deletion.
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/tests.py | 49 | 
1 files changed, 30 insertions, 19 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 42bb1860e..44d7f8275 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -102,20 +102,30 @@ class WizardTestFormData(object):      """      Test set to simulate wizard steps      """ -    def __init__(self, name, form_datas, ignored=[], extra_tests=[]): +    def __init__(self, name, form_datas, ignored=[], pre_tests=[], +                 extra_tests=[]):          """          :param name: explicit name of the test          :param form_datas: dict with data for each step - dict key are wizard          step name          :param ignored: steps to be ignored in wizard processing +        :param pre_tests: list of function to be executed before the wizard          :param extra_tests: list of extra tests. Theses tests must be functions          accepting two parameters: the current test object and the final step          response          """          self.form_datas = form_datas          self.ignored = ignored[:] +        self.pre_tests = pre_tests          self.extra_tests = extra_tests +    def inits(self, test_object): +        """ +        Initialisations before the wizard. +        """ +        for pre in self.pre_tests: +            pre(test_object) +      def tests(self, test_object, final_step_response):          """          Specific tests for theses datas. Raise Exception if not OK. @@ -185,6 +195,7 @@ class WizardTest(object):          url = reverse(self.url_name)          self.pre_wizard()          for test_form_data in self.form_datas: +            test_form_data.inits(self)              form_data = test_form_data.form_datas              ignored = test_form_data.ignored              for idx, step in enumerate(self.steps): @@ -207,27 +218,27 @@ class WizardTest(object):                          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 += 1 -                if next_form: -                    try: -                        response = self.client.post(url, data) -                    except ValidationError as e: -                        # on ManagementForm data is missing or has been tampered -                        # error verify the wizard_name or step name -                        raise ValidationError(u"Errors: {} on {}.".format( -                            u" - ".join(e.messages), current_step)) -                    self.check_response(response, current_step) +                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: +                    # on ManagementForm data is missing or has been tampered +                    # error verify the wizard_name or step name +                    raise ValidationError(u"Errors: {} on {}.".format( +                        u" - ".join(e.messages), current_step)) +                self.check_response(response, current_step) +                if next_form_is_checked: +                    next_form = self.steps[idx + 1][0]                      self.assertRedirects(                          response,                          '/{}/{}'.format(self.url_name, next_form)) -                else: -                    response = self.client.post(url, data, follow=True) -                    self.check_response(response, current_step) +                if idx == len(self.steps) - 1: +                    #  last form +                    self.assertRedirects( +                        response, +                        '/{}/done'.format(self.url_name))              test_form_data.tests(self, response)          self.post_wizard() | 
