Test username form
authorOlivier Larchevêque <olivier.larcheveque@gmail.com>
Sun, 11 Aug 2013 02:40:11 +0000 (22:40 -0400)
committerOlivier Larchevêque <olivier.larcheveque@gmail.com>
Sun, 11 Aug 2013 02:40:11 +0000 (22:40 -0400)
secretquestions/tests/common.py
secretquestions/tests/use.py
secretquestions/views.py

index 1e3685b..34dacc0 100644 (file)
@@ -34,11 +34,14 @@ class SecretQuestionTest(TestCase):
 
     def create_answers(self):
         self.answer1 = Answer.objects.create(question=self.question1,
-                secret=crypt_answer('one'), user=self.user)
+                                             secret=crypt_answer('one'),
+                                             user=self.user)
         self.answer1.save()
         self.answer2 = Answer.objects.create(question=self.question2,
-                secret=crypt_answer('two'), user=self.user)
+                                             secret=crypt_answer('two'),
+                                             user=self.user)
         self.answer2.save()
         self.answer3 = Answer.objects.create(question=self.question3,
-                secret=crypt_answer('three'), user=self.user)
+                                             secret=crypt_answer('three'),
+                                             user=self.user)
         self.answer3.save()
index 6f9b1d9..b3015d1 100644 (file)
@@ -3,6 +3,7 @@
 from django.core.urlresolvers import reverse
 
 from secretquestions.tests.common import SecretQuestionTest
+from secretquestions.conf import SQ_SESSION_KEY
 
 
 class UseTest(SecretQuestionTest):
@@ -68,3 +69,24 @@ class UseTest(SecretQuestionTest):
         self.assertEqual(response.status_code, 302)
         self.assertFalse('OK' in response.content)
         self.assertFalse('username' in response.content)
+        self.assertTrue(url in response['location'])
+        self.assertTrue(SQ_SESSION_KEY in response['location'])
+
+    def test_username_form(self):
+        """
+        Test form submission
+        """
+        url = reverse('sq_test_private')
+        response = self.client.get(url)
+        self.assertEqual(response.status_code, 200)
+        data = {'0-username': '', }
+        response = self.client.post(url, data)
+        self.assertTrue('This field is required' in response.content)
+        data = {'0-username': 'fake', }
+        response = self.client.post(url, data)
+        self.assertTrue('Username not found' in response.content)
+        data = {'0-username': self.username, }
+        response = self.client.post(url, data)
+        self.assertEqual(response.status_code, 302)
+        self.assertTrue(url in response['location'])
+        self.assertTrue(SQ_SESSION_KEY in response['location'])
index a2524a6..0584c71 100644 (file)
@@ -63,7 +63,7 @@ class SecretQuestionWizard(FormWizard):
             for answer in self.user.secret_answers.all():
                 self.step_mapping[len(form_list)] = answer
                 form_list.append(QuestionForm)
-        
+
         super(SecretQuestionWizard, self).__init__(form_list)
 
     def get_form(self, step, data=None):
@@ -95,4 +95,5 @@ class SecretQuestionWizard(FormWizard):
     def __call__(self, request, *args, **kwargs):
         if len(self.form_list) == 0:
             return self.done(request, self.form_list)
-        return super(SecretQuestionWizard, self).__call__(request, *args, **kwargs)
+        return super(SecretQuestionWizard, self).\
+            __call__(request, *args, **kwargs)