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...'))
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))
"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.")
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."),)
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)
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))
{'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))