fix: allow exam_type change when exam do not have external_id specified (#30032)

Co-authored-by: Simon Chen <schen@edX-C02FW0GUML85.local>
This commit is contained in:
Simon Chen
2022-03-09 15:08:33 -05:00
committed by GitHub
parent dcb7ef8821
commit 60cf4d7ded
3 changed files with 21 additions and 23 deletions

View File

@@ -1308,7 +1308,7 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
xblock_info.update({
'is_proctored_exam': xblock.is_proctored_exam,
'was_ever_proctored_exam': _was_xblock_ever_proctored_exam(
'was_exam_ever_linked_with_external': _was_xblock_ever_exam_linked_with_external(
course, xblock
),
'online_proctoring_rules': rules_url,
@@ -1364,16 +1364,16 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
return xblock_info
def _was_xblock_ever_proctored_exam(course, xblock):
def _was_xblock_ever_exam_linked_with_external(course, xblock):
"""
Determine whether this XBlock is or was ever configured as a proctored exam.
Determine whether this XBlock is or was ever configured as an external proctored exam.
If this block is *not* currently a proctored exam, the best way for us to tell
whether it was was *ever* configured as a proctored exam is by checking whether
If this block is *not* currently an externally linked proctored exam, the best way for us to tell
whether it was was *ever* such is by checking whether
edx-proctoring has an exam record associated with the block's ID,
and the exam record is proctored.
and the exam record has external_id.
If an exception is not raised, then we know that such a record exists,
indicating that this *was* once a special exam.
indicating that this *was* once an externally linked proctored exam.
Arguments:
course (CourseBlock)
@@ -1381,13 +1381,12 @@ def _was_xblock_ever_proctored_exam(course, xblock):
Returns: bool
"""
if xblock.is_proctored_enabled:
return True
try:
exam = get_exam_by_content_id(course.id, xblock.location)
return 'is_proctored' in exam and exam['is_proctored']
return bool('external_id' in exam and exam['external_id'])
except ProctoredExamNotFoundException:
return False
pass
return False
def add_container_page_publishing_info(xblock, xblock_info):

View File

@@ -2855,7 +2855,7 @@ class TestSpecialExamXBlockInfo(ItemTest):
item_module, 'does_backend_support_onboarding', return_value=True
)
patch_get_exam_by_content_id_success = patch.object(
item_module, 'get_exam_by_content_id', return_value={'is_proctored': True}
item_module, 'get_exam_by_content_id', return_value={'external_id': 'test_external_id'}
)
patch_get_exam_by_content_id_not_found = patch.object(
item_module, 'get_exam_by_content_id', side_effect=ProctoredExamNotFoundException
@@ -2909,26 +2909,25 @@ class TestSpecialExamXBlockInfo(ItemTest):
)
# exam proctoring should be enabled and time limited.
assert xblock_info['is_proctored_exam'] is True
assert xblock_info['was_ever_proctored_exam'] is True
assert xblock_info['was_exam_ever_linked_with_external'] is True
assert xblock_info['is_time_limited'] is True
assert xblock_info['default_time_limit_minutes'] == 100
assert xblock_info['proctoring_exam_configuration_link'] == 'test_url'
assert xblock_info['supports_onboarding'] is True
assert xblock_info['is_onboarding_exam'] is False
mock_get_exam_configuration_dashboard_url.assert_called_with(self.course.id, xblock_info['id'])
assert mock_get_exam_by_content_id.call_count == 0
@patch_get_exam_configuration_dashboard_url
@patch_does_backend_support_onboarding
@patch_get_exam_by_content_id_success
@ddt.data(
(True, True),
(False, False),
('test_external_id', True),
(None, False),
)
@ddt.unpack
def test_xblock_was_ever_proctored_exam(
def test_xblock_was_ever_proctortrack_proctored_exam(
self,
is_proctored,
external_id,
expected_value,
mock_get_exam_by_content_id,
_mock_does_backend_support_onboarding_patch,
@@ -2943,20 +2942,20 @@ class TestSpecialExamXBlockInfo(ItemTest):
is_time_limited=False,
is_onboarding_exam=False,
)
mock_get_exam_by_content_id.return_value = {'is_proctored': is_proctored}
mock_get_exam_by_content_id.return_value = {'external_id': external_id}
sequential = modulestore().get_item(sequential.location)
xblock_info = create_xblock_info(
sequential,
include_child_info=True,
include_children_predicate=ALWAYS,
)
assert xblock_info['was_ever_proctored_exam'] is expected_value
assert xblock_info['was_exam_ever_linked_with_external'] is expected_value
assert mock_get_exam_by_content_id.call_count == 1
@patch_get_exam_configuration_dashboard_url
@patch_does_backend_support_onboarding
@patch_get_exam_by_content_id_not_found
def test_xblock_was_never_proctored_exam(
def test_xblock_was_never_proctortrack_proctored_exam(
self,
mock_get_exam_by_content_id,
_mock_does_backend_support_onboarding_patch,
@@ -2977,7 +2976,7 @@ class TestSpecialExamXBlockInfo(ItemTest):
include_child_info=True,
include_children_predicate=ALWAYS,
)
assert xblock_info['was_ever_proctored_exam'] is False
assert xblock_info['was_exam_ever_linked_with_external'] is False
assert mock_get_exam_by_content_id.call_count == 1

View File

@@ -326,7 +326,7 @@ define(['jquery', 'backbone', 'underscore', 'gettext', 'js/views/baseview',
isProctoredExam || isPracticeExam || isOnboardingExam
),
proctoredExamLockedIn: (
xblockInfo.get('released_to_students') && xblockInfo.get('was_ever_proctored_exam')
xblockInfo.get('released_to_students') && xblockInfo.get('was_exam_ever_linked_with_external')
)
}, this.getContext()));