Example #1
0
    def setUpClass(self):
        self.ip = '101.0.0.1'
        self.user = User.objects.get(id=1)
        self.profile = self.user.profile
        self.quiz = Quiz.objects.get(pk=1)
        self.question_paper = QuestionPaper(quiz=self.quiz, total_marks=3)
        self.question_paper.save()

        # create answerpaper
        self.answerpaper = AnswerPaper(user=self.user, profile=self.profile,
                                       questions='1|2|3',
                                       question_paper=self.question_paper,
                                       start_time='2014-06-13 12:20:19.791297',
                                       end_time='2014-06-13 12:50:19.791297',
                                       user_ip=self.ip)
        self.answerpaper.questions_answered = '1'
        self.answerpaper.save()

        # answers for the Answer Paper
        self.answer_right = Answer(question=Question.objects.get(id=1),
                                   answer="Demo answer", correct=True, marks=1)
        self.answer_wrong = Answer(question=Question.objects.get(id=2),
                                   answer="My answer", correct=False, marks=0)
        self.answer_right.save()
        self.answer_wrong.save()
        self.answerpaper.answers.add(self.answer_right)
        self.answerpaper.answers.add(self.answer_wrong)
Example #2
0
class AnswerPaperTestCases(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.ip = '101.0.0.1'
        self.user = User.objects.get(id=1)
        self.profile = self.user.profile
        self.quiz = Quiz.objects.get(pk=1)
        self.question_paper = QuestionPaper(quiz=self.quiz, total_marks=3)
        self.question_paper.save()

        # create answerpaper
        self.answerpaper = AnswerPaper(user=self.user, profile=self.profile,
                                       questions='1|2|3',
                                       question_paper=self.question_paper,
                                       start_time='2014-06-13 12:20:19.791297',
                                       end_time='2014-06-13 12:50:19.791297',
                                       user_ip=self.ip)
        self.answerpaper.questions_answered = '1'
        self.answerpaper.save()

        # answers for the Answer Paper
        self.answer_right = Answer(question=Question.objects.get(id=1),
                                   answer="Demo answer", correct=True, marks=1)
        self.answer_wrong = Answer(question=Question.objects.get(id=2),
                                   answer="My answer", correct=False, marks=0)
        self.answer_right.save()
        self.answer_wrong.save()
        self.answerpaper.answers.add(self.answer_right)
        self.answerpaper.answers.add(self.answer_wrong)

    def test_answerpaper(self):
        """ Test Answer Paper"""
        self.assertEqual(self.answerpaper.user.username, 'demo_user')
        self.assertEqual(self.answerpaper.profile_id, 1)
        self.assertEqual(self.answerpaper.user_ip, self.ip)
        questions = self.answerpaper.questions
        num_questions = len(questions.split('|'))
        self.assertEqual(questions, '1|2|3')
        self.assertEqual(num_questions, 3)
        self.assertEqual(self.answerpaper.question_paper, self.question_paper)
        self.assertEqual(self.answerpaper.start_time,
                         '2014-06-13 12:20:19.791297')
        self.assertEqual(self.answerpaper.end_time,
                         '2014-06-13 12:50:19.791297')

    def test_current_question(self):
        """ Test current_question() method of Answer Paper"""
        current_question = self.answerpaper.current_question()
        self.assertEqual(current_question, '2')

    def test_completed_question(self):
        """ Test completed_question() method of Answer Paper"""
        question = self.answerpaper.completed_question(1)
        self.assertEqual(self.answerpaper.questions_left(), 2)

    def test_questions_left(self):
        """ Test questions_left() method of Answer Paper"""
        self.assertEqual(self.answerpaper.questions_left(), 2)

    def test_skip(self):
        """ Test skip() method of Answer Paper"""
        next_question_id = self.answerpaper.skip()
        self.assertTrue(next_question_id is not None)
        self.assertEqual(next_question_id, '3')

    def test_answered_str(self):
        """ Test answered_str() method of Answer Paper"""
        answered_question = self.answerpaper.get_answered_str()
        self.assertEqual(answered_question, '1')

    def test_update_marks_obtained(self):
        """ Test get_marks_obtained() method of Answer Paper"""
        self.answerpaper.update_marks_obtained()
        self.assertEqual(self.answerpaper.marks_obtained, 1.0)

    def test_update_percent(self):
        """ Test update_percent() method of Answerpaper"""
        self.answerpaper.update_percent()
        self.assertEqual(self.answerpaper.percent, 33.33)

    def test_update_passed(self):
        """ Test update_passed method of AnswerPaper"""
        self.answerpaper.update_passed()
        self.assertFalse(self.answerpaper.passed)

    def test_get_question_answer(self):
        """ Test get_question_answer() method of Answer Paper"""
        answered = self.answerpaper.get_question_answers()
        first_answer = answered.values()[0][0]
        self.assertEqual(first_answer.answer, 'Demo answer')
        self.assertTrue(first_answer.correct)
        self.assertEqual(len(answered), 2)