diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-09 11:22:37 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:27 +0200 |
commit | 4b37e4a16672d521cd04c3da6b48a244ce6d9ba8 (patch) | |
tree | 5ef8e8b66009dfcfd6ad9c219fec9fb66230adec | |
parent | bdf52a0d1792340fab01fbcc4f6926bfb1914168 (diff) | |
download | Ishtar-4b37e4a16672d521cd04c3da6b48a244ce6d9ba8.tar.bz2 Ishtar-4b37e4a16672d521cd04c3da6b48a244ce6d9ba8.zip |
Wizards: fix going to previous step
-rw-r--r-- | ishtar_common/tests.py | 70 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 2 |
2 files changed, 39 insertions, 33 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index f6cd3eff4..111626416 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -393,6 +393,39 @@ class WizardTest(object): raise ValidationError(msg) return response + def wizard_post_test(self, idx, data_idx, url, current_step, form_data, + test_form_data, ignored): + next_form_is_checked = len(self.steps) > idx + 1 and \ + 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) + + if current_step == test_form_data.error_expected: + with self.assertRaises(ValidationError): + self.check_response(response, current_step, data_idx) + else: + self.check_response(response, current_step, data_idx) + + if next_form_is_checked: + next_form = self.steps[idx + 1][0] + self.assertRedirects( + response, + '/{}/{}'.format(self.url_name, next_form), + msg_prefix="Dataset n{} Redirection to {} has failed - " + "Error on previous form ({})?".format( + data_idx + 1, next_form, current_step) + ) + if idx == len(self.steps) - 1: + # last form + self.assertRedirects( + response, + '/{}/done'.format(self.url_name)) + return response + def test_wizard(self): if self.pass_test(): return @@ -402,7 +435,7 @@ class WizardTest(object): test_form_data.inits(self) form_data = test_form_data.form_datas ignored = test_form_data.ignored - previous_step, back_tested = None, False + previous_step, back_tested, response = None, False, None for idx, step in enumerate(self.steps): current_step, current_form = step if current_step in ignored: @@ -413,40 +446,13 @@ class WizardTest(object): # test going back on a form response = self.wizard_post( self.client, url, current_step, None, - extra_data={"form_previous_step": previous_step} + extra_data={"form_prev_step": previous_step} ) self.assertEqual(response.status_code, 200) back_tested = True - - next_form_is_checked = len(self.steps) > idx + 1 and \ - 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) - - if current_step == test_form_data.error_expected: - with self.assertRaises(ValidationError): - self.check_response(response, current_step, data_idx) - else: - self.check_response(response, current_step, data_idx) - - if next_form_is_checked: - next_form = self.steps[idx + 1][0] - self.assertRedirects( - response, - '/{}/{}'.format(self.url_name, next_form), - msg_prefix="Dataset n{} Redirection to {} has failed -" - " Error on previous form ({})?".format( - data_idx + 1, next_form, current_step) - ) - if idx == len(self.steps) - 1: - # last form - self.assertRedirects( - response, - '/{}/done'.format(self.url_name)) + response = self.wizard_post_test( + idx, data_idx, url, current_step, form_data, test_form_data, + ignored) test_form_data.tests(self, response) self.post_wizard() diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 6e282a3fd..b5fe507b0 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1089,7 +1089,7 @@ class Wizard(IshtarWizard): try: # convert numerical step number to step name step_number = int(self.request.POST['form_prev_step']) - wizard_goto_step = self.get_form_list().keys()[step_number] + wizard_goto_step = list(self.get_form_list().keys())[step_number] except (ValueError, IndexError): return super(Wizard, self).post(*args, **kwargs) self.storage.current_step = wizard_goto_step |