From: tomwalker Date: Wed, 6 Aug 2014 18:50:08 +0000 (+0100) Subject: tests for the new features X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=80bbd654510c358df02e724b9eabd86d617428be;p=django_quiz.git tests for the new features --- diff --git a/essay/tests.py b/essay/tests.py index c261a45..28d8aef 100644 --- a/essay/tests.py +++ b/essay/tests.py @@ -16,3 +16,7 @@ class TestEssayQuestionModel(TestCase): def test_returns_guess(self): guess = "To be or not to be" self.assertEqual(self.essay.answer_choice_to_string(guess), guess) + + def test_answer_to_string(self): + self.assertEqual('To be...', + self.essay.answer_choice_to_string('To be...')) diff --git a/multichoice/tests.py b/multichoice/tests.py index 131a60f..0442a47 100644 --- a/multichoice/tests.py +++ b/multichoice/tests.py @@ -48,3 +48,6 @@ class TestMCQuestionModel(TestCase): self.q.figure.save('image', ContentFile(imgfile.read())) self.assertIsInstance(self.q.figure, ImageFieldFile) + + def test_answer_to_string(self): + self.assertEqual('African', self.q.answer_choice_to_string(123)) diff --git a/quiz/models.py b/quiz/models.py index d8914ba..672cd43 100644 --- a/quiz/models.py +++ b/quiz/models.py @@ -78,7 +78,8 @@ class Quiz(models.Model): "a random order or as they " "are set?") - max_questions = models.PositiveIntegerField(blank=True, null=True, + max_questions = models.PositiveIntegerField(blank=True, + null=True, help_text="Number of questions" " to be answered on" " each attempt.") @@ -358,11 +359,12 @@ class Sitting(models.Model): user_answers = models.TextField(blank=True, default='{}') - objects = SittingManager() - start = models.DateTimeField(auto_now_add=True) + end = models.DateTimeField(null=True, blank=True) + objects = SittingManager() + class Meta: permissions = (("view_sittings", "Can see completed exams."),) diff --git a/quiz/tests.py b/quiz/tests.py index 29187dd..bc1536a 100644 --- a/quiz/tests.py +++ b/quiz/tests.py @@ -204,6 +204,18 @@ class TestSitting(TestCase): self.sitting = Sitting.objects.new_sitting(self.user, self.quiz1) + def test_max_questions_subsetting(self): + quiz2 = Quiz.objects.create(id=2, + title='test quiz 2', + description='d2', + url='tq2', + max_questions=1) + self.question1.quiz.add(quiz2) + self.question2.quiz.add(quiz2) + sub_sitting = Sitting.objects.new_sitting(self.user, quiz2) + + self.assertNotIn('2', sub_sitting.question_list) + def test_get_next_remove_first(self): self.assertEqual(self.sitting.get_first_question(), self.question1) @@ -877,3 +889,13 @@ class TestTemplateTags(TestCase): self.assertTemplateUsed('correct_answer.html') self.assertIn('bing', template.render(context)) self.assertIn('incorrectly', template.render(context)) + + def test_answer_to_string(self): + template = Template('{% load quiz_tags %}' + + '{{ question|answer_choice_to_string:answer }}') + + context = Context({'question': self.question1, + 'answer': self.answer1.id, + 'incorrect_questions': [1]}) + + self.assertIn('bing', template.render(context)) diff --git a/true_false/tests.py b/true_false/tests.py index 46d02f1..317fed3 100644 --- a/true_false/tests.py +++ b/true_false/tests.py @@ -30,3 +30,6 @@ class TestTrueFalseQuestionModel(TestCase): {'correct': False, 'content': 'False'}]) self.assertEqual(self.red.answer_choice_to_string('True'), 'True') + + def test_answer_to_string(self): + self.assertEqual('True', self.red.answer_choice_to_string(True))