Commit 43845af0 by Afzal Wali

Updated the scenario where a student can take multiple attempts of the practice…

Updated the scenario where a student can take multiple attempts of the practice exam. The older attempts will be archived.
parent be001340
...@@ -87,7 +87,7 @@ def update_exam(exam_id, exam_name=None, time_limit_mins=None, ...@@ -87,7 +87,7 @@ def update_exam(exam_id, exam_name=None, time_limit_mins=None,
if is_proctored is not None: if is_proctored is not None:
proctored_exam.is_proctored = is_proctored proctored_exam.is_proctored = is_proctored
if is_practice_exam is not None: if is_practice_exam is not None:
proctored_exam.is_practice_exam=is_practice_exam, proctored_exam.is_practice_exam = is_practice_exam,
if external_id is not None: if external_id is not None:
proctored_exam.external_id = external_id proctored_exam.external_id = external_id
if is_active is not None: if is_active is not None:
...@@ -210,19 +210,25 @@ def get_exam_attempt_by_code(attempt_code): ...@@ -210,19 +210,25 @@ def get_exam_attempt_by_code(attempt_code):
def create_exam_attempt(exam_id, user_id, taking_as_proctored=False): def create_exam_attempt(exam_id, user_id, taking_as_proctored=False):
""" """
Creates an exam attempt for user_id against exam_id. There should only be Creates an exam attempt for user_id against exam_id. There should only be
one exam_attempt per user per exam. Multiple attempts by user will be archived one exam_attempt per user per exam except for the practice exams where multiple
attempts are allowed. Multiple attempts by user will be archived
in a separate table in a separate table
""" """
if ProctoredExamStudentAttempt.objects.get_exam_attempt(exam_id, user_id):
err_msg = (
'Cannot create new exam attempt for exam_id = {exam_id} and '
'user_id = {user_id} because it already exists!'
).format(exam_id=exam_id, user_id=user_id)
raise StudentExamAttemptAlreadyExistsException(err_msg)
# for now the student is allowed the exam default
exam = get_exam_by_id(exam_id) exam = get_exam_by_id(exam_id)
existing_attempt = ProctoredExamStudentAttempt.objects.get_exam_attempt(exam_id, user_id)
if existing_attempt:
if exam['is_practice_exam']:
# Archive the existing attempt by deleting it.
existing_attempt.delete_exam_attempt()
else:
err_msg = (
'Cannot create new exam attempt for exam_id = {exam_id} and '
'user_id = {user_id} because it already exists!'
).format(exam_id=exam_id, user_id=user_id)
raise StudentExamAttemptAlreadyExistsException(err_msg)
allowed_time_limit_mins = exam['time_limit_mins'] allowed_time_limit_mins = exam['time_limit_mins']
# add in the allowed additional time # add in the allowed additional time
......
...@@ -269,7 +269,7 @@ class ProctoredExamStudentAttempt(TimeStampedModel): ...@@ -269,7 +269,7 @@ class ProctoredExamStudentAttempt(TimeStampedModel):
def delete_exam_attempt(self): def delete_exam_attempt(self):
""" """
deletes the exam attempt object. deletes the exam attempt object and archives it to the ProctoredExamStudentAttemptHistory table.
""" """
self.delete() self.delete()
......
...@@ -64,6 +64,7 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -64,6 +64,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.course_id = 'test_course' self.course_id = 'test_course'
self.content_id = 'test_content_id' self.content_id = 'test_content_id'
self.content_id_timed = 'test_content_id_timed' self.content_id_timed = 'test_content_id_timed'
self.content_id_practice = 'test_content_id_practice'
self.disabled_content_id = 'test_disabled_content_id' self.disabled_content_id = 'test_disabled_content_id'
self.exam_name = 'Test Exam' self.exam_name = 'Test Exam'
self.user_id = self.user.id self.user_id = self.user.id
...@@ -72,6 +73,7 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -72,6 +73,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.external_id = 'test_external_id' self.external_id = 'test_external_id'
self.proctored_exam_id = self._create_proctored_exam() self.proctored_exam_id = self._create_proctored_exam()
self.timed_exam = self._create_timed_exam() self.timed_exam = self._create_timed_exam()
self.practice_exam_id = self._create_practice_exam()
self.disabled_exam_id = self._create_disabled_exam() self.disabled_exam_id = self._create_disabled_exam()
# Messages for get_student_view # Messages for get_student_view
...@@ -109,6 +111,19 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -109,6 +111,19 @@ class ProctoredExamApiTests(LoggedInTestCase):
is_proctored=False is_proctored=False
) )
def _create_practice_exam(self):
"""
Calls the api's create_exam to create a practice exam object.
"""
return create_exam(
course_id=self.course_id,
content_id=self.content_id_practice,
exam_name=self.exam_name,
time_limit_mins=self.default_time_limit,
is_practice_exam=True,
is_proctored=False
)
def _create_disabled_exam(self): def _create_disabled_exam(self):
""" """
Calls the api's create_exam to create an exam object. Calls the api's create_exam to create an exam object.
...@@ -173,6 +188,26 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -173,6 +188,26 @@ class ProctoredExamApiTests(LoggedInTestCase):
with self.assertRaises(ProctoredExamAlreadyExists): with self.assertRaises(ProctoredExamAlreadyExists):
self._create_proctored_exam() self._create_proctored_exam()
def test_update_practice_exam(self):
"""
test update the existing practice exam to increase the time limit.
"""
updated_practice_exam_id = update_exam(
self.practice_exam_id, time_limit_mins=31, is_practice_exam=True
)
# only those fields were updated, whose
# values are passed.
self.assertEqual(self.practice_exam_id, updated_practice_exam_id)
update_practice_exam = ProctoredExam.objects.get(id=updated_practice_exam_id)
self.assertEqual(update_practice_exam.exam_name, 'Updated Exam Name')
self.assertEqual(update_practice_exam.time_limit_mins, 30)
self.assertEqual(update_practice_exam.course_id, 'test_course')
self.assertEqual(update_practice_exam.content_id, 'test_content_id')
def test_update_proctored_exam(self): def test_update_proctored_exam(self):
""" """
test update the existing proctored exam test update the existing proctored exam
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment