summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r--yaksh/test_models.py72
1 files changed, 67 insertions, 5 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 4cea419..f97b7b2 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -210,10 +210,11 @@ class LearningModuleTestCases(unittest.TestCase):
# Given
module_status = 'not attempted'
# When
+ self.learning_module.learning_unit.remove(self.learning_unit_two)
status = self.learning_module.get_status(self.student, self.course)
# Then
self.assertEqual(status, module_status)
-
+ self.learning_module.learning_unit.add(self.learning_unit_two)
# Module in progress
# Given
@@ -630,6 +631,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 +667,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
)
@@ -708,6 +724,9 @@ class QuestionPaperTestCases(unittest.TestCase):
self.trial_course = Course.objects.create_trial_course(self.user)
self.trial_quiz = Quiz.objects.create_trial_quiz(self.user)
+ @classmethod
+ def tearDownClass(self):
+ self.quiz.questionpaper_set.all().delete()
def test_get_question_bank(self):
# Given
@@ -784,8 +803,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 +815,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])]
@@ -996,9 +1057,10 @@ class AnswerPaperTestCases(unittest.TestCase):
self.server_pool = server_pool
self.server_thread = t = Thread(target=server_pool.run)
t.start()
-
+
@classmethod
def tearDownClass(self):
+ self.quiz.questionpaper_set.all().delete()
self.server_pool.stop()
self.server_thread.join()
settings.code_evaluators['python']['standardtestcase'] = \
@@ -1670,7 +1732,7 @@ class CourseTestCases(unittest.TestCase):
modules = self.course.get_learning_modules()
percent = self.course.percent_completed(self.student1, modules)
self.assertEqual(percent, 0)
-
+ self.quiz1.questionpaper_set.all().delete()
# for course with module but zero percent completed
percent = self.course.percent_completed(self.student1, modules)
self.assertEqual(percent, 0)