Commit a7a00907 by Mushtaq Ali

Fix timer time difference issue. TNL-4216

parent eaf8a896
...@@ -1522,7 +1522,7 @@ def _calculate_allowed_mins(due_datetime, allowed_mins): ...@@ -1522,7 +1522,7 @@ def _calculate_allowed_mins(due_datetime, allowed_mins):
# e.g current_datetime=09:00, due_datetime=10:00 and allowed_mins=120(2hours) # e.g current_datetime=09:00, due_datetime=10:00 and allowed_mins=120(2hours)
# then allowed_mins should be 60(1hour) # then allowed_mins should be 60(1hour)
actual_allowed_mins = int((due_datetime - current_datetime).seconds / 60) actual_allowed_mins = int((due_datetime - current_datetime).total_seconds() / 60)
return actual_allowed_mins, is_exam_past_due_date return actual_allowed_mins, is_exam_past_due_date
......
...@@ -29,6 +29,7 @@ from edx_proctoring.api import ( ...@@ -29,6 +29,7 @@ from edx_proctoring.api import (
create_exam_attempt, create_exam_attempt,
get_exam_attempt_by_id, get_exam_attempt_by_id,
update_attempt_status, update_attempt_status,
_calculate_allowed_mins
) )
from .utils import ( from .utils import (
...@@ -674,11 +675,33 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -674,11 +675,33 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
self.assertEqual(response_data['proctored_exam']['id'], proctored_exam.id) self.assertEqual(response_data['proctored_exam']['id'], proctored_exam.id)
self.assertIsNotNone(response_data['started_at']) self.assertIsNotNone(response_data['started_at'])
self.assertIsNone(response_data['completed_at']) self.assertIsNone(response_data['completed_at'])
# check that we get timer arround 30 hours minus some seconds # check that we get timer around 30 hours minus some seconds
self.assertTrue(107990 <= response_data['time_remaining_seconds'] <= 108000) self.assertTrue(107990 <= response_data['time_remaining_seconds'] <= 108000)
# check that humanized time # check that humanized time
self.assertEqual(response_data['accessibility_time_string'], 'you have 30 hours remaining') self.assertEqual(response_data['accessibility_time_string'], 'you have 30 hours remaining')
def test_time_due_date_between_two_days(self):
"""
Test that we get correct total time left to attempt if due date is 24+ hours from now and we have set 24+ hours
time_limit_mins ( 27 hours ) i.e it is like 1 day and 3 hours total time left to attempt the exam.
"""
# Create an exam with 30 hours ( 1800 minutes ) total time with expected 27 hours time left to attempt.
expected_total_minutes = 27 * 60
proctored_exam = ProctoredExam.objects.create(
course_id='a/b/c',
content_id='test_content',
exam_name='Test Exam',
external_id='123aXqe3',
time_limit_mins=1800,
due_date=datetime.now(pytz.UTC) + timedelta(minutes=expected_total_minutes),
)
total_minutes, __ = _calculate_allowed_mins(proctored_exam.due_date, proctored_exam.time_limit_mins)
# Check that timer has > 24 hours
self.assertTrue(total_minutes / 60 > 24)
# Get total_minutes around 27 hours. We are checking range here because while testing some seconds have passed.
self.assertTrue(expected_total_minutes - 1 <= total_minutes <= expected_total_minutes)
def test_attempt_ready_to_start(self): def test_attempt_ready_to_start(self):
""" """
Test to get an attempt with ready_to_start status Test to get an attempt with ready_to_start status
......
...@@ -170,7 +170,7 @@ def emit_event(exam, event_short_name, attempt=None, override_data=None): ...@@ -170,7 +170,7 @@ def emit_event(exam, event_short_name, attempt=None, override_data=None):
# This can be used to determine how far into an attempt a given # This can be used to determine how far into an attempt a given
# event occured (e.g. "time to complete exam") # event occured (e.g. "time to complete exam")
attempt_event_elapsed_time_secs = ( attempt_event_elapsed_time_secs = (
(datetime.now(pytz.UTC) - attempt['started_at']).seconds if attempt['started_at'] else (datetime.now(pytz.UTC) - attempt['started_at']).total_seconds() if attempt['started_at'] else
None None
) )
......
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