diff options
author | mahesh | 2018-02-01 15:05:47 +0530 |
---|---|---|
committer | maheshgudi | 2018-03-16 15:17:20 +0530 |
commit | 009d6fb6e373ec9e24bb13924372ad77b4e3ccc5 (patch) | |
tree | 20d73afde753f20300f4ff91d9cfa1bffc1d4c2b /yaksh | |
parent | 3b37015f3e9d94b831a5eec8771b833118e6443b (diff) | |
download | online_test-009d6fb6e373ec9e24bb13924372ad77b4e3ccc5.tar.gz online_test-009d6fb6e373ec9e24bb13924372ad77b4e3ccc5.tar.bz2 online_test-009d6fb6e373ec9e24bb13924372ad77b4e3ccc5.zip |
Change TestcaseOrder to TestCaseOrder
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/evaluator_tests/test_simple_question_types.py | 25 | ||||
-rw-r--r-- | yaksh/models.py | 16 | ||||
-rw-r--r-- | yaksh/test_models.py | 48 |
3 files changed, 37 insertions, 52 deletions
diff --git a/yaksh/evaluator_tests/test_simple_question_types.py b/yaksh/evaluator_tests/test_simple_question_types.py index 3fe27d4..d2996e4 100644 --- a/yaksh/evaluator_tests/test_simple_question_types.py +++ b/yaksh/evaluator_tests/test_simple_question_types.py @@ -574,28 +574,3 @@ class MCQQuestionTestCases(unittest.TestCase): # Then self.assertNotEqual(order1, order2) - - # def test_not_shuffle_test_cases(self): - # # Given - # self.question1.shuffle_testcases = False - # self.question1.save() - # answerpaper = self.question_paper.make_answerpaper( - # user=self.user, ip=self.user_ip, - # attempt_num=1, - # course_id=self.course.id - # ) - - # # Answerpaper for user 2 - # answerpaper2 = self.question_paper.make_answerpaper( - # user=self.user2, ip=self.user_ip, - # attempt_num=1, - # course_id=self.course.id - # ) - - # user_testcase = self.question1.get_ordered_test_cases(answerpaper) - # order1 = [tc.id for tc in user_testcase] - - # user2_testcase = self.question1.get_ordered_test_cases(answerpaper2) - # order2 = [tc.id for tc in user2_testcase] - # print(order2, order1) - # self.assertNotEqual(order1, order2)
\ No newline at end of file diff --git a/yaksh/models.py b/yaksh/models.py index 6ba4589..f823cda 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -936,13 +936,13 @@ class Question(models.Model): def get_ordered_test_cases(self, answerpaper): try: - order = TestcaseOrder.objects.get(answer_paper=answerpaper, + order = TestCaseOrder.objects.get(answer_paper=answerpaper, question = self - ).testcase_order.split(",") + ).order.split(",") return [self.get_test_cases(id=int(tc_id))[0]\ for tc_id in order ] - except TestcaseOrder.DoesNotExist: + except TestCaseOrder.DoesNotExist: return self.get_test_cases() def get_maximum_test_case_weight(self, **kwargs): @@ -1221,10 +1221,10 @@ class QuestionPaper(models.Model): if question.shuffle_testcases: random.shuffle(testcases) testcases_ids = ",".join([str(tc.id) for tc in testcases]) - testcases_order = TestcaseOrder.objects.create( + testcases_order = TestCaseOrder.objects.create( answer_paper=ans_paper, question=question, - testcase_order=testcases_ids) + order=testcases_ids) ans_paper.questions_order = ",".join(question_ids) ans_paper.save() ans_paper.questions_unanswered.add(*questions) @@ -2008,16 +2008,16 @@ class FloatTestCase(TestCase): ############################################################################## -class TestcaseOrder(models.Model): +class TestCaseOrder(models.Model): """Testcase order contains a set of ordered test cases for a given question for each user. """ # Answerpaper of the user. - answer_paper= models.ForeignKey(AnswerPaper,related_name="answer_paper") + answer_paper = models.ForeignKey(AnswerPaper, related_name="answer_paper") # Question in an answerpaper. question = models.ForeignKey(Question) #Order of the test case for a question. - testcase_order = models.TextField() + order = models.TextField() diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 381a2f3..a0ccd49 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -626,8 +626,9 @@ class QuestionPaperTestCases(unittest.TestCase): @classmethod def setUpClass(self): self.course = Course.objects.get(name="Python Course") + self.user= User.objects.get(username='creator') # All active questions - self.questions = Question.objects.filter(active=True) + self.questions = Question.objects.filter(active=True, user=self.user) self.quiz = Quiz.objects.get(description="demo quiz 1") # create question paper with only fixed questions @@ -849,7 +850,7 @@ class AnswerPaperTestCases(unittest.TestCase): ) self.qtn_paper_with_single_question.save() - all_questions = Question.objects.filter(user=self.user) + all_questions = Question.objects.filter(user=self.user).order_by("id") self.questions = all_questions[0:3] self.start_time = timezone.now() self.end_time = self.start_time + timedelta(minutes=20) @@ -875,6 +876,9 @@ class AnswerPaperTestCases(unittest.TestCase): self.answerpaper.attempt_number = already_attempted + 1 self.answerpaper.save() self.answerpaper.questions.add(*self.questions) + self.answerpaper.questions_order = ",".join( + [str(q.id) for q in self.questions] + ) self.answerpaper.questions_unanswered.add(*self.questions) self.answerpaper.save() # answers for the Answer Paper @@ -929,17 +933,17 @@ class AnswerPaperTestCases(unittest.TestCase): self.question1.language = 'python' self.question1.test_case_type = 'standardtestcase' - self.question1.summary = "Question1" + self.question1.summary = "Q1" self.question1.save() self.question2.language = 'python' self.question2.type = 'mcq' self.question2.test_case_type = 'mcqtestcase' - self.question2.summary = "Question2" + self.question2.summary = "Q2" self.question2.save() self.question3.language = 'python' self.question3.type = 'mcc' self.question3.test_case_type = 'mcqtestcase' - self.question3.summary = "Question3" + self.question3.summary = "Q3" self.question3.save() self.assertion_testcase = StandardTestCase( question=self.question1, @@ -1098,7 +1102,8 @@ class AnswerPaperTestCases(unittest.TestCase): details = self.answerpaper.regrade(self.question3.id) # Then - self.answer = self.answerpaper.answers.filter(question=self.question3).last() + self.answer = self.answerpaper.answers.filter( + question=self.question3).last() self.assertTrue(details[0]) self.assertEqual(self.answer.marks, 0) self.assertFalse(self.answer.correct) @@ -1238,9 +1243,9 @@ class AnswerPaperTestCases(unittest.TestCase): """ Test Answer Paper""" self.assertEqual(self.answerpaper.user.username, 'creator') self.assertEqual(self.answerpaper.user_ip, self.ip) - questions = self.answerpaper.get_questions() + questions = [q.id for q in self.answerpaper.get_questions()] num_questions = len(questions) - self.assertSequenceEqual(list(questions), list(self.questions)) + self.assertEqual(set(questions), set([q.id for q in self.questions])) self.assertEqual(num_questions, 3) self.assertEqual(self.answerpaper.question_paper, self.question_paper) self.assertEqual(self.answerpaper.start_time, self.start_time) @@ -1251,7 +1256,7 @@ class AnswerPaperTestCases(unittest.TestCase): self.assertEqual(self.answerpaper.questions_left(), 3) # Test current_question() method of Answer Paper current_question = self.answerpaper.current_question() - self.assertEqual(current_question.summary, "Question1") + self.assertEqual(current_question.summary, "Q1") # Test completed_question() method of Answer Paper question = self.answerpaper.add_completed_question(self.question1.id) @@ -1260,14 +1265,14 @@ class AnswerPaperTestCases(unittest.TestCase): # Test next_question() method of Answer Paper current_question = self.answerpaper.current_question() - self.assertEqual(current_question.summary, "Question2") + self.assertEqual(current_question.summary, "Q2") # When next_question_id = self.answerpaper.next_question(current_question.id) # Then self.assertTrue(next_question_id is not None) - self.assertEqual(next_question_id.summary, "Question3") + self.assertEqual(next_question_id.summary, "Q3") # Given, here question is already answered current_question_id = self.question1.id @@ -1277,7 +1282,7 @@ class AnswerPaperTestCases(unittest.TestCase): # Then self.assertTrue(next_question_id is not None) - self.assertEqual(next_question_id.summary, "Question2") + self.assertEqual(next_question_id.summary, "Q2") # Given, wrong question id current_question_id = 12 @@ -1287,7 +1292,7 @@ class AnswerPaperTestCases(unittest.TestCase): # Then self.assertTrue(next_question_id is not None) - self.assertEqual(next_question_id.summary, "Question1") + self.assertEqual(next_question_id.summary, "Q1") # Given, last question in the list current_question_id = self.question3.id @@ -1298,7 +1303,7 @@ class AnswerPaperTestCases(unittest.TestCase): # Then self.assertTrue(next_question_id is not None) - self.assertEqual(next_question_id.summary, "Question1") + self.assertEqual(next_question_id.summary, "Q1") # Test get_questions_answered() method # When @@ -1313,8 +1318,11 @@ class AnswerPaperTestCases(unittest.TestCase): # Then self.assertEqual(questions_unanswered.count(), 2) - self.assertSequenceEqual(questions_unanswered, - [self.questions[1], self.questions[2]]) + self.assertEqual(set([q.id for q in questions_unanswered]), + set([self.questions[1].id, + self.questions[2].id] + ) + ) # Test completed_question and next_question # When all questions are answered @@ -1326,7 +1334,7 @@ class AnswerPaperTestCases(unittest.TestCase): # Then self.assertEqual(self.answerpaper.questions_left(), 1) self.assertIsNotNone(current_question) - self.assertEqual(current_question.summary, "Question3") + self.assertEqual(current_question.summary, "Q3") # When current_question = self.answerpaper.add_completed_question( @@ -1336,7 +1344,7 @@ class AnswerPaperTestCases(unittest.TestCase): # Then self.assertEqual(self.answerpaper.questions_left(), 0) self.assertIsNotNone(current_question) - self.assertTrue(current_question == self.answerpaper.questions.all()[0]) + self.assertTrue(current_question == self.answerpaper.get_all_ordered_questions()[0]) # When next_question_id = self.answerpaper.next_question(current_question_id) @@ -1427,7 +1435,9 @@ class CourseTestCases(unittest.TestCase): self.student2 = User.objects.get(username="demo_user3") self.quiz1 = Quiz.objects.get(description='demo quiz 1') self.quiz2 = Quiz.objects.get(description='demo quiz 2') - self.questions = Question.objects.filter(active=True) + self.questions = Question.objects.filter(active=True, + user=self.creator + ) self.modules = LearningModule.objects.filter(creator=self.creator) # create courses with disabled enrollment |