tests
authorOlivier Larchevêque <olivier.larcheveque@gmail.com>
Sun, 11 Aug 2013 04:43:02 +0000 (00:43 -0400)
committerOlivier Larchevêque <olivier.larcheveque@gmail.com>
Sun, 11 Aug 2013 04:43:02 +0000 (00:43 -0400)
secretquestions/tests/use.py
secretquestions/views.py

index 62b0eac..955dcf4 100644 (file)
@@ -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)
index 0584c71..e638095 100644 (file)
@@ -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