summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-03-20 18:51:47 +0530
committerGitHub2017-03-20 18:51:47 +0530
commit6a09816d66f9f24c0dba275d0dd3aaf7289eb73b (patch)
treeca1bbe5db8a96c7444a11f26400612601cde4757 /yaksh/test_models.py
parent23ecd8fa33e7fa2e953aa9715ae45a2869a044a0 (diff)
parent81a70c486823149b009627eb0194618ceeeb2369 (diff)
downloadonline_test-6a09816d66f9f24c0dba275d0dd3aaf7289eb73b.tar.gz
online_test-6a09816d66f9f24c0dba275d0dd3aaf7289eb73b.tar.bz2
online_test-6a09816d66f9f24c0dba275d0dd3aaf7289eb73b.zip
Merge pull request #228 from adityacp/fixes
Ordering Questions while creating Question Paper
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r--yaksh/test_models.py71
1 files changed, 44 insertions, 27 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index cd66aed..6812212 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -324,9 +324,13 @@ class QuestionPaperTestCases(unittest.TestCase):
shuffle_questions=True
)
+ self.question_paper.fixed_question_order = "{0}, {1}".format(
+ self.questions[3].id, self.questions[5].id
+ )
# add fixed set of questions to the question paper
self.question_paper.fixed_questions.add(self.questions[3],
- self.questions[5])
+ self.questions[5]
+ )
# create two QuestionSet for random questions
# QuestionSet 1
self.question_set_1 = QuestionSet.objects.create(marks=2,
@@ -368,14 +372,15 @@ class QuestionPaperTestCases(unittest.TestCase):
# For Trial case
self.questions_list = [self.questions[3].id, self.questions[5].id]
- trial_course = Course.objects.create_trial_course(self.user)
- trial_quiz = Quiz.objects.create_trial_quiz(trial_course, self.user)
+ self.trial_course = Course.objects.create_trial_course(self.user)
+ self.trial_quiz = Quiz.objects.create_trial_quiz(self.trial_course, self.user)
def test_questionpaper(self):
""" Test question paper"""
self.assertEqual(self.question_paper.quiz.description, 'demo quiz')
self.assertSequenceEqual(self.question_paper.fixed_questions.all(),
- [self.questions[3], self.questions[5]])
+ [self.questions[3], self.questions[5]]
+ )
self.assertTrue(self.question_paper.shuffle_questions)
def test_update_total_marks(self):
@@ -423,29 +428,41 @@ class QuestionPaperTestCases(unittest.TestCase):
# test can_attempt_now(self):
self.assertFalse(self.question_paper.can_attempt_now(self.user))
- def test_create_trial_paper_to_test_quiz(self):
- trial_paper = QuestionPaper.objects.create_trial_paper_to_test_quiz\
- (trial_quiz,
- self.question_paper.id
- )
- self.assertEqual(trial_paper.quiz, trial_quiz)
- self.assertEqual(trial_paper.fixed_questions.all(),
- self.question_paper.fixed_questions.all()
- )
- self.assertEqual(trial_paper.random_questions.all(),
- self.question_paper.random_questions.all()
- )
-
- def test_create_trial_paper_to_test_questions(self):
- trial_paper = QuestionPaper.objects.\
- create_trial_paper_to_test_questions(
- trial_quiz, self.questions_list
- )
- self.assertEqual(trial_paper.quiz, trial_quiz)
- self.assertEqual(self.questions_list,
- self.question_paper.fixed_questions
- .values_list("id", flat=True)
- )
+ def test_create_trial_paper_to_test_quiz(self):
+ qu_list = [str(self.questions_list[0]), str(self.questions_list[1])]
+ trial_paper = QuestionPaper.objects.create_trial_paper_to_test_quiz\
+ (self.trial_quiz,
+ self.quiz.id
+ )
+ trial_paper.random_questions.add(self.question_set_1)
+ trial_paper.random_questions.add(self.question_set_2)
+ trial_paper.fixed_question_order = ",".join(qu_list)
+ self.assertEqual(trial_paper.quiz, self.trial_quiz)
+ self.assertSequenceEqual(trial_paper.get_ordered_questions(),
+ self.question_paper.get_ordered_questions()
+ )
+ trial_paper_ran = [q_set.id for q_set in
+ trial_paper.random_questions.all()]
+ qp_ran = [q_set.id for q_set in
+ self.question_paper.random_questions.all()]
+
+ self.assertSequenceEqual(trial_paper_ran, qp_ran)
+
+ def test_create_trial_paper_to_test_questions(self):
+ qu_list = [str(self.questions_list[0]), str(self.questions_list[1])]
+ trial_paper = QuestionPaper.objects.\
+ create_trial_paper_to_test_questions(
+ self.trial_quiz, qu_list
+ )
+ self.assertEqual(trial_paper.quiz, self.trial_quiz)
+ fixed_q = self.question_paper.fixed_questions.values_list(
+ 'id', flat=True)
+ self.assertSequenceEqual(self.questions_list, fixed_q)
+
+ def test_fixed_order_questions(self):
+ fixed_ques = self.question_paper.get_ordered_questions()
+ actual_ques = [self.questions[3], self.questions[5]]
+ self.assertSequenceEqual(fixed_ques, actual_ques)
###############################################################################