From f7a1535c60663cd99da62b59de939628502e953d Mon Sep 17 00:00:00 2001 From: adityacp Date: Sat, 7 Oct 2017 20:15:04 +0530 Subject: Add test to get current question for AnswerPaper --- yaksh/test_models.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 03af521..00506cd 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -525,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() @@ -598,8 +599,8 @@ class AnswerPaperTestCases(unittest.TestCase): quiz=self.quiz2, total_marks=3, shuffle_questions=True) self.question_paper2.save() summary_list = ['Q%d' % (i) for i in range(1, 21)] - que_list = Question.objects.filter(summary__in=summary_list) - self.question_paper2.fixed_questions.add(*que_list) + 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( @@ -609,6 +610,10 @@ class AnswerPaperTestCases(unittest.TestCase): 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 = [str(self.mcc_based_testcase.id)] @@ -881,6 +886,11 @@ class AnswerPaperTestCases(unittest.TestCase): 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) + ############################################################################### class CourseTestCases(unittest.TestCase): -- cgit From bb5d9e665f5d523a85f31a50bc9c4c73033e4f0f Mon Sep 17 00:00:00 2001 From: adityacp Date: Sat, 7 Oct 2017 20:30:11 +0530 Subject: Fix quiz failure on trying to revisit after attempting all questions --- yaksh/models.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index eb14e06..787daa6 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1187,9 +1187,9 @@ class AnswerPaper(models.Model): def current_question(self): """Returns the current active question to display.""" - questions = self.questions_unanswered.all() - if questions.exists(): - cur_question = self.get_current_question(questions) + unanswered_questions = self.questions_unanswered.all() + if unanswered_questions.exists(): + cur_question = self.get_current_question(unanswered_questions) else: cur_question = self.get_current_question(self.questions.all()) return cur_question @@ -1197,7 +1197,7 @@ class AnswerPaper(models.Model): def get_current_question(self, questions): if self.questions_order: question_id = int(self.questions_order.split(',')[0]) - question = self.questions_unanswered.get(id=question_id) + question = questions.get(id=question_id) else: question = questions.first() return question -- cgit