Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: course name missing from ORA notification context #2220

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions openassessment/xblock/test/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Unit test for notification util
"""
import unittest
from unittest.mock import patch
from unittest.mock import patch, MagicMock

from openassessment.xblock.utils.notifications import send_staff_notification

Expand All @@ -11,8 +11,9 @@ class TestSendStaffNotification(unittest.TestCase):
"""
Test for send_staff_notification function
"""
@patch('openassessment.xblock.utils.notifications.modulestore')
@patch('openassessment.xblock.utils.notifications.COURSE_NOTIFICATION_REQUESTED.send_event')
def test_send_staff_notification(self, mock_send_event):
def test_send_staff_notification(self, mock_send_event, mocked_modulestore):
"""
Test send_staff_notification function
"""
Expand All @@ -21,6 +22,8 @@ def test_send_staff_notification(self, mock_send_event):
problem_id = 'problem_id'
ora_name = 'ora_name'

mocked_modulestore.return_value = MagicMock()

# Call the function
send_staff_notification(course_id, problem_id, ora_name)

Expand All @@ -37,9 +40,10 @@ def test_send_staff_notification(self, mock_send_event):
self.assertEqual(notification_data.app_name, "grading")
self.assertEqual(notification_data.audience_filters['course_roles'], ['staff', 'instructor'])

@patch('openassessment.xblock.utils.notifications.modulestore')
@patch('openassessment.xblock.utils.notifications.logger.error')
@patch('openassessment.xblock.utils.notifications.COURSE_NOTIFICATION_REQUESTED.send_event')
def test_send_staff_notification_error_logging(self, mock_send_event, mock_logger_error):
def test_send_staff_notification_error_logging(self, mock_send_event, mock_logger_error, mocked_modulestore):
"""
Test send_staff_notification function when an exception is raised
"""
Expand All @@ -48,6 +52,8 @@ def test_send_staff_notification_error_logging(self, mock_send_event, mock_logge
problem_id = 'problem_id'
ora_name = 'ora_name'

mocked_modulestore.return_value = MagicMock()

# Mock exception
mock_exception = Exception('Test exception')

Expand Down
5 changes: 4 additions & 1 deletion openassessment/xblock/utils/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.conf import settings
from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED
from openedx_events.learning.data import CourseNotificationData
from openassessment.runtime_imports.functions import modulestore

logger = logging.getLogger(__name__)

Expand All @@ -18,10 +19,12 @@ def send_staff_notification(course_id, problem_id, ora_name):
audience_filters = {
'course_roles': ['staff', 'instructor']
}
course = modulestore().get_course(course_id)
notification_data = CourseNotificationData(
course_key=course_id,
content_context={
'ora_name': ora_name
'ora_name': ora_name,
'course_name': course.display_name,
},
notification_type='ora_staff_notification',
content_url=f"{getattr(settings, 'ORA_GRADING_MICROFRONTEND_URL', '')}/{problem_id}",
Expand Down
Loading