diff options
author | ankitjavalkar | 2018-03-20 16:14:34 +0530 |
---|---|---|
committer | ankitjavalkar | 2018-04-18 15:45:27 +0530 |
commit | f5fa97802447808744cfc591cc3855a9b57e6d32 (patch) | |
tree | 7ad6bca66e23ab3c18ea41bfa68e128c38936cbc /yaksh/test_models.py | |
parent | e97249a733a8d915bc50228867ae6ad633d77ae6 (diff) | |
download | online_test-f5fa97802447808744cfc591cc3855a9b57e6d32.tar.gz online_test-f5fa97802447808744cfc591cc3855a9b57e6d32.tar.bz2 online_test-f5fa97802447808744cfc591cc3855a9b57e6d32.zip |
Add test cases
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r-- | yaksh/test_models.py | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 41730c3..3bf8a00 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -630,6 +630,15 @@ class QuestionPaperTestCases(unittest.TestCase): # All active questions self.questions = Question.objects.filter(active=True, user=self.user) self.quiz = Quiz.objects.get(description="demo quiz 1") + self.quiz_with_time_between_attempts = Quiz.objects.create( + description="demo quiz with time between attempts", + 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=3, time_between_attempts=1.0, + pass_criteria=0, + instructions="Demo Instructions" + ) # create question paper with only fixed questions self.question_paper_fixed_questions = QuestionPaper.objects.create( @@ -657,6 +666,12 @@ class QuestionPaperTestCases(unittest.TestCase): shuffle_questions=True ) + self.question_paper_with_time_between_attempts = QuestionPaper.objects.create( + quiz=self.quiz_with_time_between_attempts, + total_marks=0.0, + shuffle_questions=True + ) + self.question_paper.fixed_question_order = "{0}, {1}".format( self.questions[3].id, self.questions[5].id ) @@ -784,8 +799,10 @@ class QuestionPaperTestCases(unittest.TestCase): answerpaper.passed = True answerpaper.save() # test can_attempt_now(self): - self.assertFalse(self.question_paper.can_attempt_now(self.user, - self.course.id)) + result = (False, u'You cannot attempt demo quiz 1 quiz more than 1 time(s)') + self.assertEquals( + self.question_paper.can_attempt_now(self.user, self.course.id), result + ) # trying to create an answerpaper with same parameters passed. answerpaper2 = self.question_paper.make_answerpaper(self.user, self.ip, attempt_num, @@ -794,6 +811,46 @@ class QuestionPaperTestCases(unittest.TestCase): self.assertEqual(answerpaper, answerpaper2) + def test_time_between_attempt(self): + """ Test make_answerpaper() method of Question Paper""" + already_attempted = self.attempted_papers.count() + attempt_num = 1 + + self.first_start_time = timezone.now() + self.first_end_time = self.first_start_time + timedelta(minutes=20) + self.second_start_time = self.first_start_time + timedelta(minutes=30) + self.second_end_time = self.second_start_time + timedelta(minutes=20) + + # create answerpaper + self.first_answerpaper = AnswerPaper( + user=self.user, + question_paper=self.question_paper_with_time_between_attempts, + start_time=self.first_start_time, + end_time=self.first_end_time, + user_ip=self.ip, + course=self.course, + attempt_number=attempt_num + ) + self.first_answerpaper.passed = True + self.first_answerpaper.save() + + self.second_answerpaper = AnswerPaper( + user=self.user, + question_paper=self.question_paper_with_time_between_attempts, + start_time=self.second_start_time, + end_time=self.second_end_time, + user_ip=self.ip, + course=self.course, + attempt_number=attempt_num + 1 + ) + self.second_answerpaper.passed = True + self.second_answerpaper.save() + + result = (False, u'You cannot start the next attempt for this quiz before 1.0 hour(s)') + self.assertEquals( + self.question_paper_with_time_between_attempts.can_attempt_now(self.user, self.course.id), result + ) + def test_create_trial_paper_to_test_quiz(self): qu_list = [str(self.questions_list[0]), str(self.questions_list[1])] |