Commit 5f86df09 by Chris Dodge

allow to turn off prerequisite enforcement

parent e724f625
...@@ -1108,31 +1108,28 @@ def get_student_view(user_id, course_id, content_id, ...@@ -1108,31 +1108,28 @@ def get_student_view(user_id, course_id, content_id,
credit_state = context['credit_state'] credit_state = context['credit_state']
has_mode = _check_eligibility_of_enrollment_mode(credit_state) has_mode = _check_eligibility_of_enrollment_mode(credit_state)
has_prerequisites = False if not has_mode:
if has_mode: return None
has_prerequisites = _check_eligibility_of_prerequisites(credit_state)
has_prerequisites = _check_eligibility_of_prerequisites(credit_state)
# see if the user has passed all pre-requisite credit eligibility # see if the user has passed all pre-requisite credit eligibility
# checks, otherwise just show the user the exam unproctored # checks, otherwise just show the user the exam unproctored
if not has_mode or not has_prerequisites: if not has_prerequisites and constants.ENFORCE_PREREQUISITES:
# if we are in the right mode and if we don't have # if we are in the right mode and if we don't have
# pre-requisites, then we implicitly decline the exam # pre-requisites, then we implicitly decline the exam
if has_mode: attempt = get_exam_attempt(exam_id, user_id)
attempt = get_exam_attempt(exam_id, user_id) if not attempt:
if not attempt: # user hasn't a record of attempt, create one now
# user hasn't a record of attempt, create one now # so we can mark it as declined
# so we can mark it as declined create_exam_attempt(exam_id, user_id)
create_exam_attempt(exam_id, user_id)
update_attempt_status(
update_attempt_status( exam_id,
exam_id, user_id,
user_id, ProctoredExamStudentAttemptStatus.declined,
ProctoredExamStudentAttemptStatus.declined, raise_if_not_found=False
raise_if_not_found=False )
)
# don't override context, let the courseware show
return None
attempt = get_exam_attempt(exam_id, user_id) attempt = get_exam_attempt(exam_id, user_id)
......
...@@ -41,3 +41,9 @@ REQUIRE_FAILURE_SECOND_REVIEWS = ( ...@@ -41,3 +41,9 @@ REQUIRE_FAILURE_SECOND_REVIEWS = (
'REQUIRE_FAILURE_SECOND_REVIEWS' in settings.PROCTORING_SETTINGS 'REQUIRE_FAILURE_SECOND_REVIEWS' in settings.PROCTORING_SETTINGS
else getattr(settings, 'REQUIRE_FAILURE_SECOND_REVIEWS', True) else getattr(settings, 'REQUIRE_FAILURE_SECOND_REVIEWS', True)
) )
ENFORCE_PREREQUISITES = (
settings.PROCTORING_SETTINGS['ENFORCE_PREREQUISITES'] if
'ENFORCE_PREREQUISITES' in settings.PROCTORING_SETTINGS
else False
)
...@@ -724,14 +724,19 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -724,14 +724,19 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.assertIsNone(rendered_response) self.assertIsNone(rendered_response)
@ddt.data( @ddt.data(
('reverification', None, True, True, False), (True, 'reverification', None, True, True, False),
('reverification', 'failed', False, False, True), (True, 'reverification', 'failed', False, False, True),
('reverification', 'failed', False, True, False), (True, 'reverification', 'failed', True, True, False),
('reverification', 'satisfied', True, True, False), (True, 'reverification', 'satisfied', True, True, False),
('grade', 'failed', True, False, False) (True, 'grade', 'failed', True, False, False),
(False, 'reverification', None, True, True, False),
(False, 'reverification', 'failed', True, False, False),
(False, 'reverification', 'failed', True, True, False),
(False, 'reverification', 'satisfied', True, True, False),
(False, 'grade', 'failed', True, False, False),
) )
@ddt.unpack @ddt.unpack
def test_prereq_scenarios(self, namespace, req_status, show_proctored, def test_prereq_scenarios(self, enforce_prereq, namespace, req_status, show_proctored,
pre_create_attempt, mark_as_declined): pre_create_attempt, mark_as_declined):
""" """
This test asserts that proctoring will not be displayed under the following This test asserts that proctoring will not be displayed under the following
...@@ -740,46 +745,47 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -740,46 +745,47 @@ class ProctoredExamApiTests(LoggedInTestCase):
- Verified student has not completed all 'reverification' requirements - Verified student has not completed all 'reverification' requirements
""" """
exam = get_exam_by_id(self.proctored_exam_id) with patch('edx_proctoring.constants.ENFORCE_PREREQUISITES', enforce_prereq):
exam = get_exam_by_id(self.proctored_exam_id)
if pre_create_attempt: if pre_create_attempt:
create_exam_attempt(self.proctored_exam_id, self.user_id) create_exam_attempt(self.proctored_exam_id, self.user_id)
# user hasn't attempted reverifications # user hasn't attempted reverifications
rendered_response = get_student_view( rendered_response = get_student_view(
user_id=self.user_id, user_id=self.user_id,
course_id=exam['course_id'], course_id=exam['course_id'],
content_id=exam['content_id'], content_id=exam['content_id'],
context={ context={
'is_proctored': True, 'is_proctored': True,
'display_name': self.exam_name, 'display_name': self.exam_name,
'default_time_limit_mins': 90, 'default_time_limit_mins': 90,
'is_practice_exam': False, 'is_practice_exam': False,
'credit_state': { 'credit_state': {
'enrollment_mode': 'verified', 'enrollment_mode': 'verified',
'credit_requirement_status': [ 'credit_requirement_status': [
{ {
'namespace': namespace, 'namespace': namespace,
'status': req_status, 'status': req_status,
} }
] ]
}
} }
} )
) if show_proctored:
if show_proctored: self.assertIsNotNone(rendered_response)
self.assertIsNotNone(rendered_response) else:
else: self.assertIsNone(rendered_response)
self.assertIsNone(rendered_response)
# also the user should have been marked as declined in certain
# also the user should have been marked as declined in certain # cases
# cases if mark_as_declined:
if mark_as_declined: attempt = get_exam_attempt(self.proctored_exam_id, self.user_id)
attempt = get_exam_attempt(self.proctored_exam_id, self.user_id) self.assertEqual(attempt['status'], ProctoredExamStudentAttemptStatus.declined)
self.assertEqual(attempt['status'], ProctoredExamStudentAttemptStatus.declined) else:
else: attempt = get_exam_attempt(self.proctored_exam_id, self.user_id)
attempt = get_exam_attempt(self.proctored_exam_id, self.user_id) if attempt:
if attempt: self.assertNotEqual(attempt['status'], ProctoredExamStudentAttemptStatus.declined)
self.assertNotEqual(attempt['status'], ProctoredExamStudentAttemptStatus.declined)
def test_student_view_non_student(self): def test_student_view_non_student(self):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment