Commit f6750c1e by Muhammad Shoaib

Fixed the bug when the attempt has not been started and it polls for the attempt…

Fixed the bug when the attempt has not been started and it polls for the attempt to get the remaining time, which leads to the error, when there is no start_date for the attempt

added the test for the bug fix

added the changes suggested by afzal walli
parent 81722c3b
...@@ -502,6 +502,37 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -502,6 +502,37 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
self.assertIsNotNone(response_data['started_at']) self.assertIsNotNone(response_data['started_at'])
self.assertIsNone(response_data['completed_at']) self.assertIsNone(response_data['completed_at'])
def test_attempt_ready_to_start(self):
"""
Test to get an attempt with ready_to_start status
and will return the response_data with time time_remaining_seconds to 0
"""
# Create an exam.
proctored_exam = ProctoredExam.objects.create(
course_id='a/b/c',
content_id='test_content',
exam_name='Test Exam',
external_id='123aXqe3',
time_limit_mins=90
)
attempt = ProctoredExamStudentAttempt.create_exam_attempt(
proctored_exam.id, self.user.id, 'test_user', 1,
'test_attempt_code', True, False, 'test_external_id'
)
attempt.status = ProctoredExamStudentAttemptStatus.ready_to_start
attempt.save()
response = self.client.get(
reverse('edx_proctoring.proctored_exam.attempt', args=[attempt.id])
)
self.assertEqual(response.status_code, 200)
response_data = json.loads(response.content)
self.assertEqual(response_data['id'], attempt.id)
self.assertEqual(response_data['proctored_exam']['id'], proctored_exam.id)
self.assertIsNone(response_data['started_at'])
self.assertIsNone(response_data['completed_at'])
self.assertEqual(response_data['time_remaining_seconds'], 0)
def test_attempt_status_error(self): def test_attempt_status_error(self):
""" """
Test to confirm that attempt status is marked as error, because client Test to confirm that attempt status is marked as error, because client
......
...@@ -24,6 +24,10 @@ def get_time_remaining_for_attempt(attempt): ...@@ -24,6 +24,10 @@ def get_time_remaining_for_attempt(attempt):
Returns the remaining time (in seconds) on an attempt Returns the remaining time (in seconds) on an attempt
""" """
# returns 0 if the attempt has not been started yet.
if attempt['started_at'] is None:
return 0
# need to adjust for allowances # need to adjust for allowances
expires_at = attempt['started_at'] + timedelta(minutes=attempt['allowed_time_limit_mins']) expires_at = attempt['started_at'] + timedelta(minutes=attempt['allowed_time_limit_mins'])
now_utc = datetime.now(pytz.UTC) now_utc = datetime.now(pytz.UTC)
......
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