test questions form
This commit is contained in:
parent
ca107e025c
commit
5d257ea70f
|
@ -28,9 +28,6 @@ class SecretQuestionTest(TestCase):
|
|||
self.question1.save()
|
||||
self.question2 = Question.objects.create(text="question2")
|
||||
self.question2.save()
|
||||
self.question3 = Question.objects.create(text="question3")
|
||||
self.question3.save()
|
||||
self.questions = (self.question1, self.question2, self.question3)
|
||||
|
||||
def create_answers(self):
|
||||
self.answer1 = Answer.objects.create(question=self.question1,
|
||||
|
@ -41,7 +38,3 @@ class SecretQuestionTest(TestCase):
|
|||
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)
|
||||
self.answer3.save()
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from secretquestions.tests.common import SecretQuestionTest
|
||||
|
@ -90,3 +92,58 @@ class UseTest(SecretQuestionTest):
|
|||
self.assertEqual(response.status_code, 302)
|
||||
self.assertTrue(url in response['location'])
|
||||
self.assertTrue(SQ_SESSION_KEY in response['location'])
|
||||
|
||||
def _get_hashs(self, response):
|
||||
"""
|
||||
Parse response to prepare POST according previous hash
|
||||
"""
|
||||
regex_hash = 'name="(hash_[0-9])+" value="([a-z0-9]+)"'
|
||||
found = re.findall(regex_hash, response.content)
|
||||
hashs = {}
|
||||
for k, v in found:
|
||||
hashs.update({k: v})
|
||||
return hashs
|
||||
|
||||
def test_question_form(self):
|
||||
"""
|
||||
Test form submission
|
||||
"""
|
||||
self.create_answers()
|
||||
url = reverse('sq_test_private')
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
data = {'wizard_step': 0,
|
||||
'0-username': self.username, }
|
||||
response = self.client.post(url, data)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTrue(self.question1.text in response.content)
|
||||
|
||||
# wrong response
|
||||
data = {'wizard_step': 1,
|
||||
'0-username': self.username,
|
||||
'1-raw_answer': 'wrong answer', }
|
||||
data.update(self._get_hashs(response))
|
||||
response = self.client.post(url, data)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFalse('2-raw_answer' in response.content)
|
||||
|
||||
# good response
|
||||
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.assertEqual(response.status_code, 200)
|
||||
self.assertTrue('2-raw_answer' in response.content)
|
||||
|
||||
# good response
|
||||
data = {'wizard_step': 2,
|
||||
'0-username': self.username,
|
||||
'1-raw_answer': 'one',
|
||||
'2-raw_answer': 'two', }
|
||||
data.update(self._get_hashs(response))
|
||||
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'])
|
||||
|
|
Reference in New Issue