Skip to content

Commit

Permalink
Addressed feedback by allowing one to pass in the name to get_backend…
Browse files Browse the repository at this point in the history
…_provider
  • Loading branch information
Dave St.Germain committed Jan 4, 2019
1 parent 6a60af4 commit 255470c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions edx_proctoring/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions edx_proctoring/backends/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
6 changes: 2 additions & 4 deletions edx_proctoring/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 255470c

Please sign in to comment.