diff --git a/edx_proctoring/backends/__init__.py b/edx_proctoring/backends/__init__.py index d37388bb3f7..99eead980bd 100644 --- a/edx_proctoring/backends/__init__.py +++ b/edx_proctoring/backends/__init__.py @@ -4,15 +4,16 @@ from django.apps import apps -def get_backend_provider(exam=None): +def get_backend_provider(exam=None, name=None): """ Returns an instance of the configured backend provider + Passing in an exam will return the backend for that exam + Passing in a name will return the named backend """ - backend_name = None if exam: if 'is_proctored' in exam and not exam['is_proctored']: # timed exams don't have a backend return None elif exam['backend']: - backend_name = exam['backend'] - return apps.get_app_config('edx_proctoring').get_backend(name=backend_name) + name = exam['backend'] + return apps.get_app_config('edx_proctoring').get_backend(name=name) diff --git a/edx_proctoring/backends/tests/test_backend.py b/edx_proctoring/backends/tests/test_backend.py index 742a6c74ac2..97cedf73c6f 100644 --- a/edx_proctoring/backends/tests/test_backend.py +++ b/edx_proctoring/backends/tests/test_backend.py @@ -212,6 +212,8 @@ def test_get_different_backend(self): """ backend = get_backend_provider({'backend': 'null'}) self.assertIsInstance(backend, NullBackendProvider) + backend = get_backend_provider(name='test') + self.assertIsInstance(backend, TestBackendProvider) def test_backend_choices(self): """ diff --git a/edx_proctoring/signals.py b/edx_proctoring/signals.py index 235d3d68a0c..764940e9ad6 100644 --- a/edx_proctoring/signals.py +++ b/edx_proctoring/signals.py @@ -15,11 +15,9 @@ def check_for_category_switch(sender, instance, **kwargs): # pylint: disable=un if original.is_proctored and instance.is_proctored != original.is_proctored: from edx_proctoring.serializers import ProctoredExamSerializer exam = ProctoredExamSerializer(instance).data + # from the perspective of the backend, the exam is now inactive. exam['is_active'] = False - exam['is_proctored'] = True - # we have to pretend that the exam is still proctored - # or else we get_backend_provider will return None - backend = get_backend_provider(exam) + backend = get_backend_provider(name=exam['backend']) backend.on_exam_saved(exam)