Skip to content

Commit

Permalink
Merge pull request #469 from edx/dcs/timed-exam-test
Browse files Browse the repository at this point in the history
Ensure that timed exams do not attempt to update the backend
  • Loading branch information
davestgermain committed Nov 29, 2018
2 parents 59de704 + 19add1b commit a54f0c6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
11 changes: 7 additions & 4 deletions edx_proctoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,10 +1069,13 @@ def update_attempt_status(exam_id, user_id, to_status,

# call back to the backend to register the end of the exam, if necessary
backend = get_backend_provider(exam)
if to_status == ProctoredExamStudentAttemptStatus.started:
backend.start_exam_attempt(exam['external_id'], attempt['external_id'])
if to_status == ProctoredExamStudentAttemptStatus.submitted:
backend.stop_exam_attempt(exam['external_id'], attempt['external_id'])
if backend:
# only proctored exams have a backend
# timed exams have no backend
if to_status == ProctoredExamStudentAttemptStatus.started:
backend.start_exam_attempt(exam['external_id'], attempt['external_id'])
if to_status == ProctoredExamStudentAttemptStatus.submitted:
backend.stop_exam_attempt(exam['external_id'], attempt['external_id'])
# we user the 'status' field as the name of the event 'verb'
emit_event(exam, attempt['status'], attempt=attempt)

Expand Down
8 changes: 6 additions & 2 deletions edx_proctoring/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def get_backend_provider(exam=None):
Returns an instance of the configured backend provider
"""
backend_name = None
if exam and exam['backend']:
backend_name = exam['backend']
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)
11 changes: 11 additions & 0 deletions edx_proctoring/backends/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ def test_backend_choices(self):
]
self.assertEqual(choices, expected)

def test_no_backend_for_timed_exams(self):
"""
Timed exams should not return a backend, even if one has accidentally been set
"""
exam = {
'is_proctored': False,
'backend': 'test'
}
backend = get_backend_provider(exam)
self.assertIsNone(backend)

def test_invalid_configurations(self):
"""
Test that invalid backends throw the right exceptions
Expand Down
4 changes: 4 additions & 0 deletions edx_proctoring/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,7 @@ def test_launch_for_course(self):
external_id='123aXqe3',
time_limit_mins=90,
is_active=True,
is_proctored=True,
)

expected_url = '/instructor/%s/' % course_id
Expand All @@ -2521,6 +2522,7 @@ def test_launch_for_exam(self):
external_id='123aXqe3',
time_limit_mins=90,
is_active=True,
is_proctored=True,
)
exam_id = proctored_exam.id

Expand All @@ -2540,6 +2542,7 @@ def test_error_with_multiple_backends(self):
external_id='123aXqe3',
time_limit_mins=90,
is_active=True,
is_proctored=True,
backend='test',
)
ProctoredExam.objects.create(
Expand All @@ -2549,6 +2552,7 @@ def test_error_with_multiple_backends(self):
external_id='123aXqe4',
time_limit_mins=90,
is_active=True,
is_proctored=True,
backend='null',
)
response = self.client.get(
Expand Down

0 comments on commit a54f0c6

Please sign in to comment.