From 175640ca7d5f67da439449d45c7e8efabb766349 Mon Sep 17 00:00:00 2001 From: eemaanamir Date: Sat, 14 Sep 2024 23:28:33 +0500 Subject: [PATCH] fix: pylint errors --- openassessment/assessment/test/test_peer.py | 2 + openassessment/assessment/test/test_staff.py | 2 + .../test_create_oa_submissions_from_file.py | 2 + .../tests/test_get_submission_info.py | 1 + .../tests/test_list_staff_workflows.py | 2 + openassessment/tests/test_data.py | 1 + openassessment/xblock/test/test_grade.py | 2 + .../xblock/test/test_grade_explanation.py | 9 +- .../xblock/test/test_notifications.py | 103 ++++++++---------- openassessment/xblock/test/test_self.py | 1 + openassessment/xblock/test/test_staff.py | 1 + openassessment/xblock/test/test_staff_area.py | 2 + .../mfe/test_assessment_serializers.py | 1 + .../mfe/test_page_context_serializer.py | 2 + 14 files changed, 73 insertions(+), 58 deletions(-) diff --git a/openassessment/assessment/test/test_peer.py b/openassessment/assessment/test/test_peer.py index bb279646ff..60d1b978db 100644 --- a/openassessment/assessment/test/test_peer.py +++ b/openassessment/assessment/test/test_peer.py @@ -32,6 +32,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -39,6 +40,7 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + STUDENT_ITEM = { "student_id": "Tim", "course_id": "Demo_Course", diff --git a/openassessment/assessment/test/test_staff.py b/openassessment/assessment/test/test_staff.py index 2ed90ab582..3572d5e138 100644 --- a/openassessment/assessment/test/test_staff.py +++ b/openassessment/assessment/test/test_staff.py @@ -28,6 +28,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -35,6 +36,7 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + @ddt class TestStaffAssessment(CacheResetTest): """ diff --git a/openassessment/management/tests/test_create_oa_submissions_from_file.py b/openassessment/management/tests/test_create_oa_submissions_from_file.py index c0e0aff945..38c31c1435 100644 --- a/openassessment/management/tests/test_create_oa_submissions_from_file.py +++ b/openassessment/management/tests/test_create_oa_submissions_from_file.py @@ -19,6 +19,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -26,6 +27,7 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + USERNAME_1 = 'user1' USERNAME_2 = 'user2' STAFF_USER_1 = 'staffuser1' diff --git a/openassessment/staffgrader/tests/test_get_submission_info.py b/openassessment/staffgrader/tests/test_get_submission_info.py index 35b890963b..03be42002e 100644 --- a/openassessment/staffgrader/tests/test_get_submission_info.py +++ b/openassessment/staffgrader/tests/test_get_submission_info.py @@ -12,6 +12,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. diff --git a/openassessment/staffgrader/tests/test_list_staff_workflows.py b/openassessment/staffgrader/tests/test_list_staff_workflows.py index a8053fd519..4791d6c49e 100644 --- a/openassessment/staffgrader/tests/test_list_staff_workflows.py +++ b/openassessment/staffgrader/tests/test_list_staff_workflows.py @@ -27,6 +27,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -34,6 +35,7 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + EXPECTED_ANNOTATED_WORKFLOW_FIELDS = [ 'submission_uuid', 'identifying_uuid', diff --git a/openassessment/tests/test_data.py b/openassessment/tests/test_data.py index 3937ac088c..cde364ff40 100644 --- a/openassessment/tests/test_data.py +++ b/openassessment/tests/test_data.py @@ -33,6 +33,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. diff --git a/openassessment/xblock/test/test_grade.py b/openassessment/xblock/test/test_grade.py index 921293f17a..b240d660ea 100644 --- a/openassessment/xblock/test/test_grade.py +++ b/openassessment/xblock/test/test_grade.py @@ -24,6 +24,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -31,6 +32,7 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + @ddt.ddt class TestGrade(XBlockHandlerTestCase, SubmitAssessmentsMixin, SubmissionTestMixin): """ diff --git a/openassessment/xblock/test/test_grade_explanation.py b/openassessment/xblock/test/test_grade_explanation.py index b76f19618e..0e2816d3bc 100644 --- a/openassessment/xblock/test/test_grade_explanation.py +++ b/openassessment/xblock/test/test_grade_explanation.py @@ -21,12 +21,10 @@ scenario ) -FEATURES_WITH_GRADING_STRATEGY_ON = settings.FEATURES.copy() -FEATURES_WITH_GRADING_STRATEGY_ON['ENABLE_ORA_PEER_CONFIGURABLE_GRADING'] = True - from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -34,6 +32,11 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + +FEATURES_WITH_GRADING_STRATEGY_ON = settings.FEATURES.copy() +FEATURES_WITH_GRADING_STRATEGY_ON['ENABLE_ORA_PEER_CONFIGURABLE_GRADING'] = True + + @ddt class TestGradeExplanation(XBlockHandlerTestCase, SubmitAssessmentsMixin, SubmissionTestMixin): """ diff --git a/openassessment/xblock/test/test_notifications.py b/openassessment/xblock/test/test_notifications.py index b6039ea193..7a7cdb2c59 100644 --- a/openassessment/xblock/test/test_notifications.py +++ b/openassessment/xblock/test/test_notifications.py @@ -107,58 +107,51 @@ def test_send_notification_success(self, mock_map_to_username, mock_send_event, self.assertEqual(notification_data.context['points_possible'], 20) self.assertEqual(notification_data.notification_type, "ora_grade_assigned") - @patch('openassessment.xblock.utils.notifications.modulestore') - @patch('openassessment.xblock.utils.notifications.logger.error') - @patch('openassessment.xblock.utils.notifications.USER_NOTIFICATION_REQUESTED.send_event') - def test_invalid_key_error_logging(self, mock_logger_error, mocked_modulestore): - """ - Test error logging when InvalidKeyError is raised. - """ - # Mocked data - mocked_modulestore.return_value = MagicMock() - mock_exception = InvalidKeyError('Invalid key error') - - # Force the exception - with patch('openassessment.xblock.utils.notifications.UsageKey.from_string', side_effect=mock_exception): - send_grade_assigned_notification(self.usage_id, self.ora_user_anonymized_id, self.score) - - # Assertions - mock_logger_error.assert_called_once_with( - f"Bad ORA location provided: block-v1:TestX+TST+TST+type@problem+block@ora") - - @patch('openassessment.xblock.utils.notifications.modulestore') - @patch('openassessment.xblock.utils.notifications.logger.error') - @patch('openassessment.xblock.utils.notifications.USER_NOTIFICATION_REQUESTED.send_event') - def test_item_not_found_error_logging(self, mock_logger_error, mocked_modulestore): - """ - Test error logging when ItemNotFoundError is raised. - """ - # Mocked data - mocked_modulestore.return_value = MagicMock() - mock_exception = ItemNotFoundError('Item not found') - - # Force the exception - with patch('openassessment.xblock.utils.notifications.modulestore.get_item', side_effect=mock_exception): - send_grade_assigned_notification(self.usage_id, self.ora_user_anonymized_id, self.score) - - # Assertions - mock_logger_error.assert_called_once_with( - f"Bad ORA location provided: block-v1:TestX+TST+TST+type@problem+block@ora") - - @patch('openassessment.xblock.utils.notifications.modulestore') - @patch('openassessment.xblock.utils.notifications.logger.error') - @patch('openassessment.xblock.utils.notifications.USER_NOTIFICATION_REQUESTED.send_event') - def test_xblock_internal_error_logging(self, mock_logger_error, mocked_modulestore): - """ - Test error logging when XBlockInternalError is raised. - """ - # Mocked data - mocked_modulestore.return_value = MagicMock() - mock_exception = XBlockInternalError('XBlock error') - - # Force the exception - with patch('openassessment.xblock.utils.notifications.modulestore.get_item', side_effect=mock_exception): - send_grade_assigned_notification(self.usage_id, self.ora_user_anonymized_id, self.score) - - # Assertions - mock_logger_error.assert_called_once_with("XBlock error") \ No newline at end of file + @patch('openassessment.xblock.utils.notifications.User.objects.get') + @patch('openassessment.xblock.utils.notifications.UsageKey.from_string') + @patch('openassessment.xblock.utils.notifications.modulestore') + @patch('openassessment.xblock.utils.notifications.USER_NOTIFICATION_REQUESTED.send_event') + @patch('openassessment.xblock.utils.notifications.logger.error') + @patch('openassessment.data.map_anonymized_ids_to_usernames') + def test_invalid_key_error_logging(self, mock_map_to_username, mock_logger_error, mock_send_event, mock_modulestore, + mock_from_string, mock_get_user): + """ + Test error logging when InvalidKeyError is raised. + """ + mock_map_to_username.return_value = {self.ora_user_anonymized_id: 'student1'} + mock_get_user.return_value = MagicMock(id=2) + mock_from_string.return_value = MagicMock(course_key='course-v1:TestX+TST+TST') + mock_modulestore.return_value.get_item.return_value = MagicMock(display_name="ORA Assignment") + mock_modulestore.return_value.get_course.return_value = MagicMock(display_name="Test Course") + mock_exception = InvalidKeyError('Invalid key error', 'some_serialized_data') + + # Force the exception + with patch('openassessment.xblock.utils.notifications.UsageKey.from_string', side_effect=mock_exception): + send_grade_assigned_notification(self.usage_id, self.ora_user_anonymized_id, self.score) + + # Assertions + mock_logger_error.assert_called_once_with(f"Bad ORA location provided: {self.usage_id}") + + @patch('openassessment.xblock.utils.notifications.User.objects.get') + @patch('openassessment.xblock.utils.notifications.UsageKey.from_string') + @patch('openassessment.xblock.utils.notifications.modulestore') + @patch('openassessment.xblock.utils.notifications.USER_NOTIFICATION_REQUESTED.send_event') + @patch('openassessment.xblock.utils.notifications.logger.error') + @patch('openassessment.data.map_anonymized_ids_to_usernames') + def test_item_not_found_error_logging(self, mock_map_to_username, mock_logger_error, mock_send_event, + mock_modulestore, + mock_from_string, mock_get_user): + """ + Test error logging when ItemNotFoundError is raised. + """ + mock_map_to_username.return_value = {self.ora_user_anonymized_id: 'student1'} + mock_get_user.return_value = MagicMock(id=2) + mock_from_string.return_value = MagicMock(course_key='course-v1:TestX+TST+TST') + mock_exception = ItemNotFoundError('Item not found') + mock_modulestore.return_value.get_item.side_effect = mock_exception + mock_modulestore.return_value.get_course.return_value = MagicMock(display_name="Test Course") + + send_grade_assigned_notification(self.usage_id, self.ora_user_anonymized_id, self.score) + + # Assertions + mock_logger_error.assert_called_once_with(f"Bad ORA location provided: {self.usage_id}") diff --git a/openassessment/xblock/test/test_self.py b/openassessment/xblock/test/test_self.py index 6cbab8296e..f287893a79 100644 --- a/openassessment/xblock/test/test_self.py +++ b/openassessment/xblock/test/test_self.py @@ -19,6 +19,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. diff --git a/openassessment/xblock/test/test_staff.py b/openassessment/xblock/test/test_staff.py index 28d0305df7..900b7ade96 100644 --- a/openassessment/xblock/test/test_staff.py +++ b/openassessment/xblock/test/test_staff.py @@ -32,6 +32,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. diff --git a/openassessment/xblock/test/test_staff_area.py b/openassessment/xblock/test/test_staff_area.py index 6280ba5533..8aec1a5b44 100644 --- a/openassessment/xblock/test/test_staff_area.py +++ b/openassessment/xblock/test/test_staff_area.py @@ -38,6 +38,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -45,6 +46,7 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + FILE_URL = 'www.fileurl.com' SAVED_FILES_DESCRIPTIONS = ['file1', 'file2'] SAVED_FILES_NAMES = ['file1.txt', 'file2.txt'] diff --git a/openassessment/xblock/ui_mixins/mfe/test_assessment_serializers.py b/openassessment/xblock/ui_mixins/mfe/test_assessment_serializers.py index d8a420e4bd..e9c06f0a47 100644 --- a/openassessment/xblock/ui_mixins/mfe/test_assessment_serializers.py +++ b/openassessment/xblock/ui_mixins/mfe/test_assessment_serializers.py @@ -27,6 +27,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. diff --git a/openassessment/xblock/ui_mixins/mfe/test_page_context_serializer.py b/openassessment/xblock/ui_mixins/mfe/test_page_context_serializer.py index 08de4dc9d4..c5cee6050c 100644 --- a/openassessment/xblock/ui_mixins/mfe/test_page_context_serializer.py +++ b/openassessment/xblock/ui_mixins/mfe/test_page_context_serializer.py @@ -34,6 +34,7 @@ from unittest.mock import MagicMock import openassessment.workflow.models as workflow_models + def setUpModule(): """ This method is run once for the entire test module. @@ -41,6 +42,7 @@ def setUpModule(): """ workflow_models.send_grade_assigned_notification = MagicMock() + @ddt.ddt class TestPageContextSerializer(XBlockHandlerTestCase, SubmitAssessmentsMixin):