summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
authormahesh2018-02-01 15:05:47 +0530
committermaheshgudi2018-03-16 15:17:20 +0530
commit009d6fb6e373ec9e24bb13924372ad77b4e3ccc5 (patch)
tree20d73afde753f20300f4ff91d9cfa1bffc1d4c2b /yaksh/test_models.py
parent3b37015f3e9d94b831a5eec8771b833118e6443b (diff)
downloadonline_test-009d6fb6e373ec9e24bb13924372ad77b4e3ccc5.tar.gz
online_test-009d6fb6e373ec9e24bb13924372ad77b4e3ccc5.tar.bz2
online_test-009d6fb6e373ec9e24bb13924372ad77b4e3ccc5.zip
Change TestcaseOrder to TestCaseOrder
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r--yaksh/test_models.py48
1 files changed, 29 insertions, 19 deletions
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