diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/grader.py | 4 | ||||
-rw-r--r-- | yaksh/models.py | 15 | ||||
-rw-r--r-- | yaksh/test_models.py | 61 | ||||
-rw-r--r-- | yaksh/tests/test_code_server.py | 34 | ||||
-rw-r--r-- | yaksh/views.py | 5 |
5 files changed, 109 insertions, 10 deletions
diff --git a/yaksh/grader.py b/yaksh/grader.py index 38cce8d..c9dc8a2 100644 --- a/yaksh/grader.py +++ b/yaksh/grader.py @@ -131,7 +131,9 @@ class Grader(object): # Add a new signal handler for the execution of this code. prev_handler = create_signal_handler() success = False - test_case_success_status = [False] * len(test_case_instances) + test_case_success_status = [False] + if len(test_case_instances) != 0: + test_case_success_status = [False] * len(test_case_instances) error = [] weight = 0.0 diff --git a/yaksh/models.py b/yaksh/models.py index d011bb0..3010a3c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -317,7 +317,7 @@ class Quiz(models.Model): attempts_allowed = models.IntegerField(default=1, choices=attempts) time_between_attempts = models.FloatField( - "Time Between Quiz Attempts in hours" + "Time Between Quiz Attempts in hours", default=0.0 ) is_trial = models.BooleanField(default=False) @@ -1356,11 +1356,18 @@ class QuestionPaper(models.Model): ) if last_attempt: time_lag = (timezone.now() - last_attempt.start_time).total_seconds() / 3600 - return time_lag >= self.quiz.time_between_attempts + can_attempt = time_lag >= self.quiz.time_between_attempts + msg = "You cannot start the next attempt for this quiz before {0} hour(s)".format( + self.quiz.time_between_attempts + ) if not can_attempt else None + return can_attempt, msg else: - return True + return True, None else: - return False + msg = "You cannot attempt {0} quiz more than {1} time(s)".format( + self.quiz.description, self.quiz.attempts_allowed + ) + return False, msg def create_demo_quiz_ppr(self, demo_quiz, user): question_paper = QuestionPaper.objects.create(quiz=demo_quiz, 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])] diff --git a/yaksh/tests/test_code_server.py b/yaksh/tests/test_code_server.py index 1309624..e2781df 100644 --- a/yaksh/tests/test_code_server.py +++ b/yaksh/tests/test_code_server.py @@ -106,6 +106,40 @@ class TestCodeServer(unittest.TestCase): self.assertFalse(data['success']) self.assertTrue('AssertionError' in data['error'][0]['exception']) + def test_question_with_no_testcases(self): + # Given + testdata = { + 'metadata': { + 'user_answer': 'def f(): return 1', + 'language': 'python', + 'partial_grading': False + }, + 'test_case_data': [] + } + + # When + submit(self.url, '0', json.dumps(testdata), '') + result = get_result(self.url, '0', block=True) + + # Then + data = json.loads(result.get('result')) + self.assertFalse(data['success']) + + # With correct answer and test case + testdata["metadata"]["user_answer"] = 'def f(): return 2' + testdata["test_case_data"] = [{'test_case': 'assert f() == 2', + 'test_case_type': 'standardtestcase', + 'weight': 0.0 + } + ] + # When + submit(self.url, '0', json.dumps(testdata), '') + result = get_result(self.url, '0', block=True) + + # Then + data = json.loads(result.get('result')) + self.assertTrue(data['success']) + def test_multiple_simultaneous_hits(self): # Given results = Queue() diff --git a/yaksh/views.py b/yaksh/views.py index f8fd67f..e1c1889 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -521,9 +521,8 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, previous_question=last_attempt.current_question() ) # allowed to start - if not quest_paper.can_attempt_now(user, course_id): - msg = "You cannot attempt {0} quiz more than {1} time(s)".format( - quest_paper.quiz.description, quest_paper.quiz.attempts_allowed) + if not quest_paper.can_attempt_now(user, course_id)[0]: + msg = quest_paper.can_attempt_now(user, course_id)[1] if is_moderator(user): return prof_manage(request, msg=msg) return view_module(request, module_id=module_id, course_id=course_id, |