summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorankitjavalkar2017-04-28 15:01:18 +0530
committerankitjavalkar2017-04-28 17:16:45 +0530
commit3597ee5fa814b0c7c737e72797d9e9911ca5e0dd (patch)
tree0935e7b5cdbb5d72d2c106ca7234520c985d4291 /yaksh
parent976713c1cd2f7a74aaa6893ade275190c385198a (diff)
downloadonline_test-3597ee5fa814b0c7c737e72797d9e9911ca5e0dd.tar.gz
online_test-3597ee5fa814b0c7c737e72797d9e9911ca5e0dd.tar.bz2
online_test-3597ee5fa814b0c7c737e72797d9e9911ca5e0dd.zip
- Fix bug that prevents addition of a prerequisite to foreignkey field
- Fix test cases to ensure fails if prerequisite is not set
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py3
-rw-r--r--yaksh/test_models.py77
2 files changed, 79 insertions, 1 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 018a0dd..ad64f2a 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -182,7 +182,8 @@ class Course(models.Model):
duplicate_prerequisite = Quiz.objects.get(
id=duplicate_prereq_id
)
- duplicate_quiz.prerequisite.add(duplicate_prerequisite)
+ duplicate_quiz.prerequisite = duplicate_prerequisite
+ duplicate_quiz.save()
return new_course
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 8e8865b..5a61c0f 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -914,6 +914,32 @@ class CourseTestCases(unittest.TestCase):
self.questions[3]
)
+ self.template_quiz2 = Quiz.objects.create(
+ start_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc),
+ end_date_time=datetime(2199, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc),
+ duration=30,
+ active=True,
+ attempts_allowed=1,
+ time_between_attempts=0,
+ description='template quiz 2',
+ pass_criteria=0,
+ language='Python',
+ prerequisite=self.template_quiz,
+ course=self.template_course,
+ instructions="Demo Instructions"
+ )
+
+ self.template_question_paper2 = QuestionPaper.objects.create(
+ quiz=self.template_quiz2,
+ total_marks=0.0,
+ shuffle_questions=True
+ )
+
+ self.template_question_paper2.fixed_questions.add(self.questions[1],
+ self.questions[2],
+ self.questions[3]
+ )
+
def test_create_duplicate_course(self):
""" Test create_duplicate_course method of course """
# create a duplicate course
@@ -986,6 +1012,57 @@ class CourseTestCases(unittest.TestCase):
for q in cloned_qp.fixed_questions.all():
self.assertIn(q, self.template_question_paper.fixed_questions.all())
+ # get second duplicate quiz associated with duplicate course
+ cloned_quiz = cloned_course.quiz_set.all()[1]
+
+ self.assertEqual(cloned_quiz.start_date_time,
+ self.template_quiz2.start_date_time
+ )
+ self.assertEqual(cloned_quiz.end_date_time,
+ self.template_quiz2.end_date_time
+ )
+ self.assertEqual(cloned_quiz.duration,
+ self.template_quiz2.duration
+ )
+ self.assertEqual(cloned_quiz.active,
+ self.template_quiz2.active
+ )
+ self.assertEqual(cloned_quiz.attempts_allowed,
+ self.template_quiz2.attempts_allowed
+ )
+ self.assertEqual(cloned_quiz.time_between_attempts,
+ self.template_quiz2.time_between_attempts
+ )
+ self.assertEqual(cloned_quiz.description,
+ 'Copy Of template quiz 2'
+ )
+ self.assertEqual(cloned_quiz.pass_criteria,
+ self.template_quiz2.pass_criteria
+ )
+ self.assertEqual(cloned_quiz.language,
+ self.template_quiz2.language
+ )
+ self.assertEqual(cloned_quiz.course,
+ cloned_course
+ )
+ self.assertEqual(cloned_quiz.instructions,
+ self.template_quiz2.instructions
+ )
+
+ # Get second duplicate questionpaper associated with duplicate quiz
+ cloned_qp = cloned_quiz.questionpaper_set.all()[0]
+
+ self.assertEqual(cloned_qp.quiz, cloned_quiz)
+ self.assertEqual(cloned_qp.total_marks,
+ self.template_question_paper2.total_marks
+ )
+ self.assertEqual(cloned_qp.shuffle_questions,
+ self.template_question_paper2.shuffle_questions
+ )
+
+ for q in cloned_qp.fixed_questions.all():
+ self.assertIn(q, self.template_question_paper2.fixed_questions.all())
+
def test_is_creator(self):
""" Test is_creator method of Course"""