diff options
author | maheshgudi | 2018-07-12 20:08:20 +0530 |
---|---|---|
committer | maheshgudi | 2018-07-12 20:40:50 +0530 |
commit | 714eeb188c67a6b61dfd132f0869e7679d91c8bf (patch) | |
tree | aa9d3467d8d92e3135c106557893a2a113c7bb12 /yaksh | |
parent | 0b2980148288b44571820e1176dea0e2dffcec81 (diff) | |
download | online_test-714eeb188c67a6b61dfd132f0869e7679d91c8bf.tar.gz online_test-714eeb188c67a6b61dfd132f0869e7679d91c8bf.tar.bz2 online_test-714eeb188c67a6b61dfd132f0869e7679d91c8bf.zip |
Fix multiple testcase error
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 12 | ||||
-rw-r--r-- | yaksh/test_models.py | 18 |
2 files changed, 26 insertions, 4 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 5d17dba..12bada8 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1360,9 +1360,12 @@ class QuestionPaper(models.Model): random.shuffle(testcases) testcases_ids = ",".join([str(tc.id) for tc in testcases] ) - TestCaseOrder.objects.create( - answer_paper=ans_paper, question=question, - order=testcases_ids) + if not TestCaseOrder.objects.filter( + answer_paper=ans_paper, question=question + ).exists(): + TestCaseOrder.objects.create( + answer_paper=ans_paper, question=question, + order=testcases_ids) ans_paper.questions_order = ",".join(question_ids) ans_paper.save() @@ -2200,4 +2203,7 @@ class TestCaseOrder(models.Model): order = models.TextField() + class Meta: + unique_together = ("answer_paper", "question", "order") + ############################################################################## diff --git a/yaksh/test_models.py b/yaksh/test_models.py index eaf5bbc..7bb7e52 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -2,7 +2,8 @@ import unittest from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload,\ - LearningModule, LearningUnit, Lesson, LessonFile, CourseStatus + LearningModule, LearningUnit, Lesson, LessonFile, CourseStatus, \ + TestCaseOrder from yaksh.code_server import ( ServerPool, get_result as get_result_from_code_server ) @@ -1270,6 +1271,21 @@ class AnswerPaperTestCases(unittest.TestCase): self.assertEqual(self.answer.marks, 0) self.assertFalse(self.answer.correct) + def test_testcase_order(self): + testcase_ids = ",".join([str(ids) for ids in + self.question2.get_test_cases() + ]) + testcase_order = TestCaseOrder.objects.create( + answer_paper=self.answerpaper, + question=self.question2, + order=testcase_ids) + with self.assertRaises(IntegrityError): + TestCaseOrder.objects.create(answer_paper=self.answerpaper, + question=self.question2, + order=testcase_ids + ) + testcase_order.delete() + def test_validate_and_regrade_mcq_correct_answer(self): # Given mcq_answer = str(self.mcq_based_testcase.id) |