Skip to content

Commit

Permalink
fix: pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eemaanamir committed Sep 14, 2024
1 parent 48d1cbf commit 175640c
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 58 deletions.
2 changes: 2 additions & 0 deletions openassessment/assessment/test/test_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
from unittest.mock import MagicMock
import openassessment.workflow.models as workflow_models


def setUpModule():
"""
This method is run once for the entire test module.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
workflow_models.send_grade_assigned_notification = MagicMock()


STUDENT_ITEM = {
"student_id": "Tim",
"course_id": "Demo_Course",
Expand Down
2 changes: 2 additions & 0 deletions openassessment/assessment/test/test_staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
from unittest.mock import MagicMock
import openassessment.workflow.models as workflow_models


def setUpModule():
"""
This method is run once for the entire test module.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
workflow_models.send_grade_assigned_notification = MagicMock()


@ddt
class TestStaffAssessment(CacheResetTest):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
from unittest.mock import MagicMock
import openassessment.workflow.models as workflow_models


def setUpModule():
"""
This method is run once for the entire test module.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
workflow_models.send_grade_assigned_notification = MagicMock()


USERNAME_1 = 'user1'
USERNAME_2 = 'user2'
STAFF_USER_1 = 'staffuser1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions openassessment/staffgrader/tests/test_list_staff_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
from unittest.mock import MagicMock
import openassessment.workflow.models as workflow_models


def setUpModule():
"""
This method is run once for the entire test module.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
workflow_models.send_grade_assigned_notification = MagicMock()


EXPECTED_ANNOTATED_WORKFLOW_FIELDS = [
'submission_uuid',
'identifying_uuid',
Expand Down
1 change: 1 addition & 0 deletions openassessment/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions openassessment/xblock/test/test_grade.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
from unittest.mock import MagicMock
import openassessment.workflow.models as workflow_models


def setUpModule():
"""
This method is run once for the entire test module.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
workflow_models.send_grade_assigned_notification = MagicMock()


@ddt.ddt
class TestGrade(XBlockHandlerTestCase, SubmitAssessmentsMixin, SubmissionTestMixin):
"""
Expand Down
9 changes: 6 additions & 3 deletions openassessment/xblock/test/test_grade_explanation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@
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.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
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):
"""
Expand Down
103 changes: 48 additions & 55 deletions openassessment/xblock/test/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
@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}")
1 change: 1 addition & 0 deletions openassessment/xblock/test/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions openassessment/xblock/test/test_staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions openassessment/xblock/test/test_staff_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
from unittest.mock import MagicMock
import openassessment.workflow.models as workflow_models


def setUpModule():
"""
This method is run once for the entire test module.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
workflow_models.send_grade_assigned_notification = MagicMock()


FILE_URL = 'www.fileurl.com'
SAVED_FILES_DESCRIPTIONS = ['file1', 'file2']
SAVED_FILES_NAMES = ['file1.txt', 'file2.txt']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
from unittest.mock import MagicMock
import openassessment.workflow.models as workflow_models


def setUpModule():
"""
This method is run once for the entire test module.
We use it to globally replace send_grade_assigned_notification with a mock.
"""
workflow_models.send_grade_assigned_notification = MagicMock()


@ddt.ddt
class TestPageContextSerializer(XBlockHandlerTestCase, SubmitAssessmentsMixin):

Expand Down

0 comments on commit 175640c

Please sign in to comment.