Skip to content

Commit

Permalink
Fetch correct remaining seconds from proctoring - TNL-4175
Browse files Browse the repository at this point in the history
  • Loading branch information
Mushtaq Ali committed Mar 3, 2016
1 parent 5e1cd81 commit 5cebdb1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Chris Dodge <cdodge@edx.org>
Muhammad Shoaib <mshoaib@edx.org>
Afzal Wali <afzal@edx.org>
Mushtaq Ali <mushtaak@gmail.com>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if (secondsLeft < 0)
secondsLeft = 0;

var hours = parseInt(secondsLeft / 3600) % 24;
var hours = parseInt(secondsLeft / 3600);
var minutes = parseInt(secondsLeft / 60) % 60;
var seconds = Math.floor(secondsLeft % 60);

Expand Down
41 changes: 41 additions & 0 deletions edx_proctoring/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,47 @@ def test_attempt_readback(self):

self.assertEqual(response_data['accessibility_time_string'], 'you have less than a minute remaining')

def test_timer_remaining_time(self):
"""
Test that remaining time is calculated correctly
"""
# Create an exam with 30 hours ( 30 * 60) total time
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
)
attempt_data = {
'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id,
'start_clock': True,
}
response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'),
attempt_data
)

self.assertEqual(response.status_code, 200)
response_data = json.loads(response.content)
attempt_id = response_data['exam_attempt_id']
self.assertGreater(attempt_id, 0)

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.assertIsNotNone(response_data['started_at'])
self.assertIsNone(response_data['completed_at'])
# check that we get timer arround 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_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 @@ -47,7 +47,7 @@ def get_time_remaining_for_attempt(attempt):
now_utc = datetime.now(pytz.UTC)

if expires_at > now_utc:
time_remaining_seconds = (expires_at - now_utc).seconds
time_remaining_seconds = (expires_at - now_utc).total_seconds()
else:
time_remaining_seconds = 0

Expand Down

0 comments on commit 5cebdb1

Please sign in to comment.