diff --git a/edx_proctoring/api.py b/edx_proctoring/api.py index d33958d260b..0f63361509f 100644 --- a/edx_proctoring/api.py +++ b/edx_proctoring/api.py @@ -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) # 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 diff --git a/edx_proctoring/tests/test_views.py b/edx_proctoring/tests/test_views.py index 7ad7c982f18..11312295030 100644 --- a/edx_proctoring/tests/test_views.py +++ b/edx_proctoring/tests/test_views.py @@ -29,6 +29,7 @@ create_exam_attempt, get_exam_attempt_by_id, update_attempt_status, + _calculate_allowed_mins ) from .utils import ( @@ -674,11 +675,33 @@ def test_timer_remaining_time(self): self.assertEqual(response_data['proctored_exam']['id'], proctored_exam.id) self.assertIsNotNone(response_data['started_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) # check that humanized time 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): """ Test to get an attempt with ready_to_start status diff --git a/edx_proctoring/utils.py b/edx_proctoring/utils.py index 1ccc7b1ac18..8148611b8e6 100644 --- a/edx_proctoring/utils.py +++ b/edx_proctoring/utils.py @@ -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 # event occured (e.g. "time to complete exam") 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 )