diff --git a/secretquestions/tests/common.py b/secretquestions/tests/common.py new file mode 100644 index 0000000..2163112 --- /dev/null +++ b/secretquestions/tests/common.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +from django.test import TestCase +from django.test.client import Client + +from django.contrib.auth.models import User + +from secretquestions.models import Question + +class SecretQuestionTest(TestCase): + + client = Client() + username = 'paul' + password = 'lemay' + + def setUp(self): + self.create_user() + self.create_questions() + + def create_user(self): + self.user = User.objects.create(username=self.username) + self.user.set_password(self.password) + self.user.save() + + def create_questions(self): + self.question1 = Question.objects.create(text="question1") + self.question2 = Question.objects.create(text="question2") + self.question3 = Question.objects.create(text="question3") + self.questions = (self.question1, self.question2, self.question3) + + diff --git a/secretquestions/tests/configuration.py b/secretquestions/tests/configuration.py index 8e42c09..b7e532a 100644 --- a/secretquestions/tests/configuration.py +++ b/secretquestions/tests/configuration.py @@ -1,38 +1,22 @@ # -*- coding: utf-8 -*- -from django.test import TestCase - from django.core.urlresolvers import reverse -from django.test.client import Client from django.conf import settings -from django.contrib.auth.models import User - -from secretquestions.models import Question, Answer +from secretquestions.tests.common import SecretQuestionTest +from secretquestions.models import Answer -class ConfigurationTest(TestCase): - - client = Client() - username = 'paul' - password = 'lemay' - - def setUp(self): - self.create_user() - self.create_questions() - - def create_user(self): - self.user = User.objects.create(username=self.username) - self.user.set_password(self.password) - self.user.save() - - def create_questions(self): - self.question1 = Question.objects.create(text="question1") - self.question2 = Question.objects.create(text="question2") - self.question3 = Question.objects.create(text="question3") - self.questions = (self.question1, self.question2, self.question3) +class ConfigurationTest(SecretQuestionTest): + """ + TestCase for setting questions/answers + """ def test_access_setup_questions_for_anonymous(self): + """ + Check if you try to access setup page as anonymous, you're redirected + to login page. + """ url = reverse('sq_setup') response = self.client.get(url) self.assertEqual(response.status_code, 302) @@ -40,6 +24,9 @@ class ConfigurationTest(TestCase): self.assertEqual(settings.LOGIN_URL in response['Location'], True) def test_access_setup_questions_for_authenticated(self): + """ + Check if setup page is accessible from authenticated people + """ self.assertEqual(self.client.login(username=self.username, password=self.password), True) @@ -48,6 +35,9 @@ class ConfigurationTest(TestCase): self.assertEqual(response.status_code, 200) def test_setting_answer_for_one_question(self): + """ + Check if the answer is really stored and crypted + """ raw_password = 'xxx' self.assertEqual(self.client.login(username=self.username, password=self.password), True) @@ -68,6 +58,9 @@ class ConfigurationTest(TestCase): def test_setting_empty_answer_for_one_question(self): + """ + Check if the answer is not empty + """ raw_password = '' self.assertEqual(self.client.login(username=self.username, password=self.password), True) @@ -86,6 +79,10 @@ class ConfigurationTest(TestCase): Answer.objects.get(user=self.user, question=self.question1) def test_check_reset(self): + """ + Check if you have ever set answer, the form does not prepopulate + this one. + """ raw_password = 'xxx' self.test_setting_answer_for_one_question() url = reverse('sq_setup') diff --git a/tox.ini b/tox.ini index 9f23cea..ba79398 100644 --- a/tox.ini +++ b/tox.ini @@ -5,10 +5,12 @@ envlist = django1.3, django1.4 deps = django-registration==0.8 coverage + pep8 commands = coverage erase coverage run --source="{envsitepackagesdir}/secretquestions/" {envdir}/bin/django-admin.py test secretquestions --settings=secretquestions.tests.settings + pep8 -r --statistics --count {envsitepackagesdir}/secretquestions/ --exclude={envsitepackagesdir}/secretquestions/migrations/* coverage report [testenv:django1.3]