Skip to content

Commit

Permalink
fix: handle case where backend provider no longer exists for timed exams
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Oct 2, 2024
1 parent f4d81e5 commit 6151238
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ Change Log
Unreleased
~~~~~~~~~~
* fix timed exam bug for provider that no longer exists
* fix timed exam reset bug for provider that no longer exists
* fix instructor dashboard view for provider that no longer exists

[4.17.0]
~~~~~~~~~~~~~~~~~~~~~
* Add support for Python 3.11 & 3.12

[4.16.1] - 2023-08-8
~~~~~~~~~~~~~~~~~~~~~
* Updated django-simple-history package to 3.3.0
* Updated django-simple-history package to 3.3.0
* Created no-op migrations needed for new django-simple-history package version

[4.16.0] - 2023-06-22
Expand Down
15 changes: 12 additions & 3 deletions edx_proctoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2943,7 +2943,7 @@ def get_student_view(user_id, course_id, content_id,
is_proctored_exam = exam['is_proctored'] and not exam['is_practice_exam']
is_timed_exam = not exam['is_proctored'] and not exam['is_practice_exam']

exam_backend = get_backend_provider(name=exam['backend'])
exam_backend = get_backend_provider(exam=exam)

sub_view_func = None
if is_timed_exam:
Expand Down Expand Up @@ -3019,8 +3019,17 @@ def is_backend_dashboard_available(course_id):
active_only=True
)
for exam in exams:
if get_backend_provider(name=exam.backend).has_dashboard:
return True
try:
if get_backend_provider(name=exam.backend).has_dashboard:
return True
except NotImplementedError:
log.exception(

Check warning on line 3026 in edx_proctoring/api.py

View check run for this annotation

Codecov / codecov/patch

edx_proctoring/api.py#L3025-L3026

Added lines #L3025 - L3026 were not covered by tests
'No proctoring backend configured for backend=%(backend)s',
{
'backend': exam.backend,
}
)

return False


Expand Down
19 changes: 10 additions & 9 deletions edx_proctoring/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ def on_attempt_changed(sender, instance, signal, **kwargs):
else:
# remove the attempt on the backend
# timed exams have no backend
backend = get_backend_provider(name=instance.proctored_exam.backend)
if backend:
result = backend.remove_exam_attempt(instance.proctored_exam.external_id, instance.external_id)
if not result:
log.error(
'Failed to remove attempt_id=%s from backend=%s',
instance.id,
instance.proctored_exam.backend,
)
if instance.proctored_exam.is_proctored:
backend = get_backend_provider(name=instance.proctored_exam.backend)
if backend:
result = backend.remove_exam_attempt(instance.proctored_exam.external_id, instance.external_id)
if not result:
log.error(
'Failed to remove attempt_id=%s from backend=%s',
instance.id,
instance.proctored_exam.backend,
)


@receiver(post_delete, sender=models.ProctoredExamStudentAttempt)
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setUp(self):
self.proctored_exam = ProctoredExam.objects.create(
course_id='x/y/z', content_id=self.content_id, exam_name=self.exam_name,
time_limit_mins=self.default_time_limit, external_id=self.external_id,
backend=self.backend_name
backend=self.backend_name, is_proctored=True,
)
self.attempt = ProctoredExamStudentAttempt.objects.create(
proctored_exam=self.proctored_exam, user=self.user, attempt_code='12345',
Expand Down

0 comments on commit 6151238

Please sign in to comment.