diff options
Diffstat (limited to 'yaksh/tests.py')
-rw-r--r-- | yaksh/tests.py | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/yaksh/tests.py b/yaksh/tests.py index e71a78f..441f0f6 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -8,6 +8,7 @@ from django.utils import timezone import pytz from django.contrib.auth.models import Group + def setUpModule(): # create user profile user = User.objects.create_user(username='demo_user', @@ -156,11 +157,15 @@ class QuestionTestCases(unittest.TestCase): self.assertTrue(question_data.active) self.assertEqual(question_data.snippet, 'def fact()') + ############################################################################### class QuizTestCases(unittest.TestCase): def setUp(self): + self.creator = User.objects.get(pk=1) + self.teacher = User.objects.get(pk=2) self.quiz1 = Quiz.objects.get(pk=1) self.quiz2 = Quiz.objects.get(pk=2) + self.trial_course = Course.objects.create_trial_course(self.creator) def test_quiz(self): """ Test Quiz""" @@ -188,6 +193,50 @@ class QuizTestCases(unittest.TestCase): for quiz in quizzes: self.assertTrue(quiz.active) + def test_create_trial_quiz(self): + """Test to check if trial quiz is created""" + trial_quiz = Quiz.objects.create_trial_quiz(self.trial_course, + self.creator + ) + self.assertEqual(trial_quiz.course, self.trial_course) + self.assertEqual(trial_quiz.duration, 1000) + self.assertEqual(trial_quiz.description, "trial_questions") + self.assertTrue(trial_quiz.is_trial) + self.assertEqual(trial_quiz.time_between_attempts, 0) + + def test_create_trial_from_quiz_godmode(self): + """Test to check if a copy of original quiz is created in godmode""" + trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id, + self.creator, + True + ) + self.assertEqual(trial_quiz.description, "Trial_orig_id_1_godmode") + self.assertTrue(trial_quiz.is_trial) + self.assertEqual(trial_quiz.duration, 1000) + self.assertTrue(trial_quiz.active) + self.assertEqual(trial_quiz.end_date_time, + datetime(2199, 1, 1, 0, 0, 0, 0) + ) + self.assertEqual(trial_quiz.time_between_attempts, 0) + + def test_create_trial_from_quiz_usermode(self): + """Test to check if a copy of original quiz is created in usermode""" + trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz2.id, + self.creator, + False + ) + self.assertEqual(trial_quiz.description, "Trial_orig_id_2_usermode") + self.assertTrue(trial_quiz.is_trial) + self.assertEqual(trial_quiz.duration, self.quiz2.duration) + self.assertEqual(trial_quiz.active, self.quiz2.active) + self.assertEqual(trial_quiz.start_date_time, + self.quiz2.start_date_time + ) + self.assertEqual(trial_quiz.end_date_time, + self.quiz2.end_date_time + ) + self.assertEqual(trial_quiz.time_between_attempts, 0) + ############################################################################### class QuestionPaperTestCases(unittest.TestCase): @@ -245,6 +294,11 @@ class QuestionPaperTestCases(unittest.TestCase): user=self.user ) + # 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) + def test_questionpaper(self): """ Test question paper""" self.assertEqual(self.question_paper.quiz.description, 'demo quiz') @@ -297,6 +351,30 @@ 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) + ) + ############################################################################### class AnswerPaperTestCases(unittest.TestCase): @@ -433,6 +511,7 @@ class CourseTestCases(unittest.TestCase): self.quiz1 = Quiz.objects.get(pk=1) self.quiz2 = Quiz.objects.get(pk=2) + def test_is_creator(self): """ Test is_creator method of Course""" self.assertTrue(self.course.is_creator(self.creator)) @@ -505,6 +584,18 @@ class CourseTestCases(unittest.TestCase): result = self.course.is_teacher(self.student2) self.assertTrue(result) + def test_create_trial_course(self): + """Test to check if trial course is created""" + # Test for manager method create_trial_course + trial_course = Course.objects.create_trial_course(self.creator) + self.assertEqual(trial_course.name, "trial_course") + self.assertEqual(trial_course.enrollment, "open") + self.assertTrue(trial_course.active) + self.assertEqual(trial_course.students.get(user=self.creator.id), + self.creator + ) + self.assertTrue(trial_course.is_trial) + ############################################################################### class TestCaseTestCases(unittest.TestCase): @@ -567,4 +658,4 @@ class TestCaseTestCases(unittest.TestCase): result = self.question1.consolidate_answer_data( user_answer="demo_answer" ) - self.assertEqual(result, self.answer_data_json)
\ No newline at end of file + self.assertEqual(result, self.answer_data_json) |