diff options
Diffstat (limited to 'ishtar_common/tests.py')
| -rw-r--r-- | ishtar_common/tests.py | 31 | 
1 files changed, 30 insertions, 1 deletions
| diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 0c4bbda08..dbe3df4a5 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -75,6 +75,32 @@ def create_user():      return username, password, user +class WizardTestFormData(object): +    """ +    Test set to simulate wizard steps +    """ +    def __init__(self, name, form_datas, ignored=[], 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 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.extra_tests = extra_tests + +    def tests(self, test_object, final_step_response): +        """ +        Specific tests for theses datas. Raise Exception if not OK. +        """ +        for test in self.extra_tests: +            test(test_object, final_step_response) + +  class WizardTest(object):      url_name = None      wizard_name = '' @@ -95,7 +121,9 @@ class WizardTest(object):      def test_wizard(self):          url = reverse(self.url_name)          self.pre_wizard() -        for form_data, ignored in self.form_datas: +        for test_form_data in self.form_datas: +            form_data = test_form_data.form_datas +            ignored = test_form_data.ignored              for idx, step in enumerate(self.steps):                  current_step, current_form = step                  if current_step in ignored: @@ -138,6 +166,7 @@ class WizardTest(object):                          '/{}/{}'.format(self.url_name, next_form))                  else:                      response = self.client.post(url, data, follow=True) +            test_form_data.tests(self, response)          self.post_wizard() | 
