Skip to content

Commit

Permalink
Fix timer time difference issue. TNL-4216
Browse files Browse the repository at this point in the history
  • Loading branch information
Mushtaq Ali committed Mar 17, 2016
1 parent eaf8a89 commit a7a0090
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion edx_proctoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
25 changes: 24 additions & 1 deletion edx_proctoring/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
create_exam_attempt,
get_exam_attempt_by_id,
update_attempt_status,
_calculate_allowed_mins
)

from .utils import (
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit a7a0090

Please sign in to comment.