From b8d6116cd59f68888aca8f2acceecc9b85ebf7de Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 22 Feb 2017 15:01:24 +0530 Subject: Change models and views test to get fixed questions --- yaksh/test_models.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index cd66aed..efd5fd3 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1,7 +1,7 @@ import unittest from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ - StdIOBasedTestCase, FileUpload, McqTestCase + StdIOBasedTestCase, FileUpload, McqTestCase, FixedQuestions import json from datetime import datetime, timedelta from django.utils import timezone @@ -325,8 +325,10 @@ class QuestionPaperTestCases(unittest.TestCase): ) # add fixed set of questions to the question paper - self.question_paper.fixed_questions.add(self.questions[3], - self.questions[5]) + fixed_ques = FixedQuestions() + fixed_ques.add_fixed_questions(self.question_paper, self.questions[3]) + fixed_ques.add_fixed_questions(self.question_paper, self.questions[5]) + # create two QuestionSet for random questions # QuestionSet 1 self.question_set_1 = QuestionSet.objects.create(marks=2, @@ -374,8 +376,9 @@ class QuestionPaperTestCases(unittest.TestCase): 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]]) + fixed_ques = FixedQuestions() + ques = fixed_ques.get_fixed_questions(self.question_paper) + self.assertSequenceEqual(ques, [self.questions[3], self.questions[5]]) self.assertTrue(self.question_paper.shuffle_questions) def test_update_total_marks(self): @@ -415,7 +418,8 @@ class QuestionPaperTestCases(unittest.TestCase): self.assertIsInstance(answerpaper, AnswerPaper) paper_questions = answerpaper.questions.all() self.assertEqual(len(paper_questions), 7) - fixed_questions = set(self.question_paper.fixed_questions.all()) + fixed_ques = FixedQuestions() + fixed_questions = set(fixed_ques.get_fixed_questions(self.question_paper)) self.assertTrue(fixed_questions.issubset(set(paper_questions))) answerpaper.passed = True answerpaper.save() @@ -429,8 +433,8 @@ class QuestionPaperTestCases(unittest.TestCase): 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(fixed_ques.get_fixed_questions(trial_paper), + fixed_ques.get_fixed_questions(self.question_paper) ) self.assertEqual(trial_paper.random_questions.all(), self.question_paper.random_questions.all() @@ -442,10 +446,10 @@ class QuestionPaperTestCases(unittest.TestCase): 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) - ) + fixed_q = FixedQuestions.objects.filter( + questionpaper=self.question_paper).values_list( + 'question_id', flat=True) + self.assertEqual(self.questions_list, fixed_q) ############################################################################### -- cgit