diff options
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r-- | yaksh/test_models.py | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index bc7f114..00506cd 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -502,6 +502,7 @@ class AnswerPaperTestCases(unittest.TestCase): def setUpClass(self): self.ip = '101.0.0.1' self.user = User.objects.get(username='demo_user') + self.user2 = User.objects.get(username='demo_user2') self.profile = self.user.profile self.quiz = Quiz.objects.get(description='demo quiz 1') self.question_paper = QuestionPaper(quiz=self.quiz, total_marks=3) @@ -524,6 +525,7 @@ class AnswerPaperTestCases(unittest.TestCase): question_paper=self.question_paper, user=self.user ) + self.question_paper.fixed_questions.add(*self.questions) already_attempted = self.attempted_papers.count() self.answerpaper.attempt_number = already_attempted + 1 self.answerpaper.save() @@ -547,6 +549,12 @@ class AnswerPaperTestCases(unittest.TestCase): self.answerpaper.answers.add(self.answer_right) self.answerpaper.answers.add(self.answer_wrong) + self.answer1 = Answer.objects.create( + question=self.question1, + answer="answer1", correct=False, error=json.dumps([]) + ) + self.answerpaper.answers.add(self.answer1) + self.question1.language = 'python' self.question1.test_case_type = 'standardtestcase' self.question1.summary = "Question1" @@ -584,9 +592,31 @@ class AnswerPaperTestCases(unittest.TestCase): ) self.mcc_based_testcase.save() + # Setup quiz where questions are shuffled + # Create Quiz and Question Paper + self.quiz2 = Quiz.objects.get(description="demo quiz 2") + self.question_paper2 = QuestionPaper( + quiz=self.quiz2, total_marks=3, shuffle_questions=True) + self.question_paper2.save() + summary_list = ['Q%d' % (i) for i in range(1, 21)] + self.que_list = Question.objects.filter(summary__in=summary_list) + self.question_paper2.fixed_questions.add(*self.que_list) + + # Create AnswerPaper for user1 and user2 + self.user1_answerpaper = self.question_paper2.make_answerpaper( + self.user, self.ip, 1 + ) + self.user2_answerpaper = self.question_paper2.make_answerpaper( + self.user2, self.ip, 1 + ) + + self.user2_answerpaper2 = self.question_paper.make_answerpaper( + self.user2, self.ip, 1 + ) + def test_validate_and_regrade_mcc_correct_answer(self): # Given - mcc_answer = ['a'] + mcc_answer = [str(self.mcc_based_testcase.id)] self.answer = Answer(question=self.question3, answer=mcc_answer, ) @@ -623,7 +653,7 @@ class AnswerPaperTestCases(unittest.TestCase): def test_validate_and_regrade_mcq_correct_answer(self): # Given - mcq_answer = 'a' + mcq_answer = str(self.mcq_based_testcase.id) self.answer = Answer(question=self.question2, answer=mcq_answer, ) @@ -657,7 +687,6 @@ class AnswerPaperTestCases(unittest.TestCase): self.assertEqual(self.answer.marks, 0) self.assertFalse(self.answer.correct) - def test_mcq_incorrect_answer(self): # Given mcq_answer = 'b' @@ -794,13 +823,14 @@ class AnswerPaperTestCases(unittest.TestCase): # Then self.assertEqual(self.answerpaper.questions_left(), 0) - self.assertTrue(current_question is None) + self.assertTrue(current_question == self.answerpaper.questions.all()[0]) # When next_question_id = self.answerpaper.next_question(current_question_id) # Then - self.assertTrue(next_question_id is None) + all_questions = self.questions.all() + self.assertTrue(next_question_id == all_questions[0]) def test_update_marks(self): """ Test update_marks method of AnswerPaper""" @@ -834,17 +864,32 @@ class AnswerPaperTestCases(unittest.TestCase): def test_get_previous_answers(self): answers = self.answerpaper.get_previous_answers(self.questions[0]) - self.assertEqual(answers.count(), 1) + self.assertEqual(answers.count(), 2) self.assertTrue(answers[0], self.answer_right) answers = self.answerpaper.get_previous_answers(self.questions[1]) self.assertEqual(answers.count(), 1) self.assertTrue(answers[0], self.answer_wrong) - def test_set_marks (self): + def test_set_marks(self): self.answer_wrong.set_marks(0.5) self.assertEqual(self.answer_wrong.marks, 0.5) self.answer_wrong.set_marks(10.0) - self.assertEqual(self.answer_wrong.marks,1.0) + self.assertEqual(self.answer_wrong.marks, 1.0) + + def test_get_latest_answer(self): + latest_answer = self.answerpaper.get_latest_answer(self.question1.id) + self.assertEqual(latest_answer.id, self.answer1.id) + self.assertEqual(latest_answer.answer, "answer1") + + def test_shuffle_questions(self): + ques_set_1 = self.user1_answerpaper.get_all_ordered_questions() + ques_set_2 = self.user2_answerpaper.get_all_ordered_questions() + self.assertFalse(ques_set_1 == ques_set_2) + + def test_validate_current_question(self): + self.user2_answerpaper2.questions_unanswered.remove(*self.questions) + self.assertEqual(self.user2_answerpaper2.current_question(), + self.question1) ############################################################################### |