From 6ef2d78904ea7327a22b280d156b452334cd0128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Larchev=C3=AAque?= Date: Sun, 11 Aug 2013 00:43:02 -0400 Subject: [PATCH] tests --- secretquestions/tests/use.py | 29 +++++++++++++++++++++++++++++ secretquestions/views.py | 4 +++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/secretquestions/tests/use.py b/secretquestions/tests/use.py index 62b0eac..955dcf4 100644 --- a/secretquestions/tests/use.py +++ b/secretquestions/tests/use.py @@ -147,3 +147,32 @@ class UseTest(SecretQuestionTest): self.assertEqual(response.status_code, 302) self.assertTrue(url in response['location']) self.assertTrue(SQ_SESSION_KEY in response['location']) + + response = self.client.get(response['location']) + self.assertTrue('OK' in response.content) + + def test_inconsistent_data(self): + """ + Test inconsistent data between steps + wizard toolkit redirect on step with corrupted data + """ + self.create_answers() + url = reverse('sq_test_private') + response = self.client.get(url) + data = {'wizard_step': 0, + '0-username': self.username, } + response = self.client.post(url, data) + self.assertTrue('1-raw_answer' in response.content) + data = {'wizard_step': 1, + '0-username': self.username, + '1-raw_answer': 'one', } + data.update(self._get_hashs(response)) + response = self.client.post(url, data) + self.assertTrue('2-raw_answer' in response.content) + data = {'wizard_step': 2, + '0-username': self.username, + '1-raw_answer': 'xxx', + '2-raw_answer': 'two', } + data.update(self._get_hashs(response)) + response = self.client.post(url, data) + self.assertTrue('1-raw_answer' in response.content) diff --git a/secretquestions/views.py b/secretquestions/views.py index 0584c71..e638095 100644 --- a/secretquestions/views.py +++ b/secretquestions/views.py @@ -77,9 +77,11 @@ class SecretQuestionWizard(FormWizard): return 'secretquestions/step.html' def done(self, request, form_list): + # double check validation, it's already done + # by wizard and redirect on the step with corrupted data for form in form_list: if not form.is_valid(): - return self.redirect + raise Exception('SQ corrupted data') # pragma: no cover token = _get_new_csrf_key() path = urlparse(self.redirect).path