From 4df00ca0e914468ba0877341a17f0e02eb114d77 Mon Sep 17 00:00:00 2001 From: Zacharis278 Date: Tue, 1 Oct 2024 10:12:04 -0400 Subject: [PATCH 1/2] fix: allow courses to render with invalid proctoring provider --- .../contentstore/views/tests/test_block.py | 36 +++++++++++++++++++ .../xblock_storage_handlers/view_handlers.py | 13 ++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index d1081a7b3c03..ded06186869e 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -3776,6 +3776,42 @@ def test_xblock_was_never_proctortrack_proctored_exam( assert xblock_info["was_exam_ever_linked_with_external"] is False 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_success + def test_special_exam_xblock_info_get_dashboard_error( + self, + mock_get_exam_by_content_id, + _mock_does_backend_support_onboarding, + mock_get_exam_configuration_dashboard_url, + ): + sequential = BlockFactory.create( + parent_location=self.chapter.location, + category="sequential", + display_name="Test Lesson 1", + user_id=self.user.id, + is_proctored_enabled=True, + is_time_limited=True, + default_time_limit_minutes=100, + is_onboarding_exam=False, + ) + sequential = modulestore().get_item(sequential.location) + mock_get_exam_configuration_dashboard_url.side_effect = Exception("proctoring error") + xblock_info = create_xblock_info( + sequential, + include_child_info=True, + include_children_predicate=ALWAYS, + ) + + # no errors should be raised and proctoring_exam_configuration_link is None + assert xblock_info["is_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"] == None + assert xblock_info["supports_onboarding"] is True + assert xblock_info["is_onboarding_exam"] is False + class TestLibraryXBlockInfo(ModuleStoreTestCase): """ diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index 9b893e94bd21..827f60cbb39f 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -1162,11 +1162,16 @@ def create_xblock_info( # lint-amnesty, pylint: disable=too-many-statements # only call get_exam_configuration_dashboard_url if not using an LTI proctoring provider if xblock.is_proctored_exam and (course.proctoring_provider != 'lti_external'): - proctoring_exam_configuration_link = ( - get_exam_configuration_dashboard_url( - course.id, xblock_info["id"] + try: + proctoring_exam_configuration_link = ( + get_exam_configuration_dashboard_url( + course.id, xblock_info["id"] + ) + ) + except Exception as e: + log.error( + f"Error while getting proctoring exam configuration link: {e}" ) - ) if course.proctoring_provider == "proctortrack": show_review_rules = SHOW_REVIEW_RULES_FLAG.is_enabled( From 9d523263274a5ccd29b84b0b52d06204e2ec8511 Mon Sep 17 00:00:00 2001 From: Zacharis278 Date: Tue, 1 Oct 2024 10:25:46 -0400 Subject: [PATCH 2/2] style: lint --- cms/djangoapps/contentstore/views/tests/test_block.py | 2 +- .../contentstore/xblock_storage_handlers/view_handlers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index ded06186869e..80a253559887 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -3808,7 +3808,7 @@ def test_special_exam_xblock_info_get_dashboard_error( 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"] == None + assert xblock_info["proctoring_exam_configuration_link"] is None assert xblock_info["supports_onboarding"] is True assert xblock_info["is_onboarding_exam"] is False diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index 827f60cbb39f..79137cfde11f 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -1168,7 +1168,7 @@ def create_xblock_info( # lint-amnesty, pylint: disable=too-many-statements course.id, xblock_info["id"] ) ) - except Exception as e: + except Exception as e: # pylint: disable=broad-except log.error( f"Error while getting proctoring exam configuration link: {e}" )