Skip to content

Commit

Permalink
fix: exam start time reset (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacharis278 committed Sep 3, 2024
1 parent 01b8d56 commit 908be84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions edx_exams/apps/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ def update_attempt_status(attempt_id, to_status):
if not allowed_to_start:
raise ExamIllegalStatusTransition(error_msg)

attempt_obj.start_time = datetime.now(pytz.UTC)
attempt_obj.allowed_time_limit_mins = _calculate_allowed_mins(attempt_obj.user, attempt_obj.exam)
# Once start time, and end time by extension, has been set further transitions to started
# must not update this value
if not attempt_obj.start_time:
attempt_obj.start_time = datetime.now(pytz.UTC)
attempt_obj.allowed_time_limit_mins = _calculate_allowed_mins(attempt_obj.user, attempt_obj.exam)

course_key = CourseKey.from_string(attempt_obj.exam.course_id)
usage_key = UsageKey.from_string(attempt_obj.exam.content_id)
Expand Down
15 changes: 15 additions & 0 deletions edx_exams/apps/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,21 @@ def test_cannot_start_if_other_attempts_active(self):
update_attempt_status(self.exam_attempt.id, ExamAttemptStatus.started)
self.assertIn('another exam attempt is currently active!', str(exc.exception))

def test_ready_to_submit_to_started(self):
"""
Test transition to started after initial start time has been set. This should not
alter the existing start time.
"""
with freeze_time(timezone.now()):
self.exam_attempt.status = ExamAttemptStatus.ready_to_submit
self.exam_attempt.start_time = timezone.now()-timedelta(minutes=10)
self.exam_attempt.allowed_time_limit_mins = 30
self.exam_attempt.save()

update_attempt_status(self.exam_attempt.id, ExamAttemptStatus.started)
self.exam_attempt.refresh_from_db()
self.assertEqual(self.exam_attempt.start_time, timezone.now()-timedelta(minutes=10))


class TestGetAttemptById(ExamsAPITestCase):
"""
Expand Down

0 comments on commit 908be84

Please sign in to comment.