Commit e71f7188 by Chris Dodge

update the attempt status to timeout if appropriate when reading the attempt

parent 7c13841d
......@@ -590,20 +590,10 @@ def get_student_view(user_id, course_id, content_id,
attempt = get_exam_attempt(exam_id, user_id)
has_started_exam = attempt and attempt.get('started_at')
has_time_expired = False
if has_started_exam:
if attempt.get('status') == 'error':
student_view_template = 'proctoring/seq_proctored_exam_error.html'
else:
now_utc = datetime.now(pytz.UTC)
expires_at = attempt['started_at'] + timedelta(minutes=attempt['allowed_time_limit_mins'])
has_time_expired = now_utc > expires_at
# make sure the attempt has been marked as timed_out, if need be
if has_time_expired and attempt['status'] == ProctoredExamStudentAttemptStatus.started:
mark_exam_attempt_timeout(exam_id, user_id)
# refetch since we are transitioning state
attempt = get_exam_attempt(exam_id, user_id)
if not has_started_exam:
# determine whether to show a timed exam only entrance screen
......
"""
All tests for the models.py
"""
from datetime import datetime
from datetime import datetime, timedelta
from mock import patch
import pytz
from freezegun import freeze_time
from edx_proctoring.api import (
create_exam,
......@@ -703,6 +703,30 @@ class ProctoredExamApiTests(LoggedInTestCase):
)
self.assertIsNone(rendered_response)
def test_get_studentview_timedout(self):
"""
Verifies that if we call get_studentview when the timer has expired
it will automatically state transition into timed_out
"""
attempt_obj = self._create_started_exam_attempt()
reset_time = datetime.now(pytz.UTC) + timedelta(days=1)
with freeze_time(reset_time):
get_student_view(
user_id=self.user_id,
course_id=self.course_id,
content_id=self.content_id,
context={
'is_proctored': True,
'display_name': self.exam_name,
'default_time_limit_mins': 90
}
)
attempt = get_exam_attempt_by_id(attempt_obj.id)
self.assertEqual(attempt['status'], 'timed_out')
def test_get_studentview_submitted_status(self): # pylint: disable=invalid-name
"""
Test for get_student_view proctored exam which has been submitted.
......
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