forked from openedx/edx-ora2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openedx#2201 from openedx/ahtisham/INF-1304
- Loading branch information
Showing
12 changed files
with
137 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Initialization Information for Open Assessment Module | ||
""" | ||
|
||
__version__ = '6.6.2' | ||
__version__ = '6.7.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
Unit test for notification util | ||
""" | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from openassessment.xblock.utils.notifications import send_staff_notification | ||
|
||
|
||
class TestSendStaffNotification(unittest.TestCase): | ||
""" | ||
Test for send_staff_notification function | ||
""" | ||
@patch('openassessment.xblock.utils.notifications.COURSE_NOTIFICATION_REQUESTED.send_event') | ||
def test_send_staff_notification(self, mock_send_event): | ||
""" | ||
Test send_staff_notification function | ||
""" | ||
# Mocked data | ||
course_id = 'course_id' | ||
problem_id = 'problem_id' | ||
ora_name = 'ora_name' | ||
|
||
# Call the function | ||
send_staff_notification(course_id, problem_id, ora_name) | ||
|
||
# Assertions | ||
mock_send_event.assert_called_once() | ||
args, kwargs = mock_send_event.call_args | ||
notification_data = kwargs['course_notification_data'] | ||
|
||
# Check if CourseNotificationData is properly initialized | ||
self.assertEqual(notification_data.course_key, course_id) | ||
self.assertEqual(notification_data.content_context['ora_name'], ora_name) | ||
self.assertEqual(notification_data.notification_type, 'ora_staff_notification') | ||
self.assertEqual(notification_data.content_url, f"/{problem_id}") | ||
self.assertEqual(notification_data.app_name, "ora") | ||
self.assertEqual(notification_data.audience_filters['course_roles'], ['staff', 'instructor']) | ||
|
||
@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): | ||
""" | ||
Test send_staff_notification function when an exception is raised | ||
""" | ||
# Mocked data | ||
course_id = 'course_id' | ||
problem_id = 'problem_id' | ||
ora_name = 'ora_name' | ||
|
||
# Mock exception | ||
mock_exception = Exception('Test exception') | ||
|
||
mock_send_event.side_effect = mock_exception | ||
|
||
# Call the function | ||
send_staff_notification(course_id, problem_id, ora_name) | ||
|
||
# Assertions | ||
mock_logger_error.assert_called_once_with(f"Error while sending ora staff notification: {mock_exception}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
This module contains utility functions for sending notifications. | ||
""" | ||
import logging | ||
|
||
from django.conf import settings | ||
from openedx_events.learning.signals import COURSE_NOTIFICATION_REQUESTED | ||
from openedx_events.learning.data import CourseNotificationData | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def send_staff_notification(course_id, problem_id, ora_name): | ||
""" | ||
Send a staff notification for a course | ||
""" | ||
try: | ||
audience_filters = { | ||
'course_roles': ['staff', 'instructor'] | ||
} | ||
notification_data = CourseNotificationData( | ||
course_key=course_id, | ||
content_context={ | ||
'ora_name': ora_name | ||
}, | ||
notification_type='ora_staff_notification', | ||
content_url=f"{getattr(settings, 'ORA_GRADING_MICROFRONTEND_URL', '')}/{problem_id}", | ||
app_name="ora", | ||
audience_filters=audience_filters, | ||
) | ||
COURSE_NOTIFICATION_REQUESTED.send_event(course_notification_data=notification_data) | ||
except Exception as e: | ||
logger.error(f"Error while sending ora staff notification: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ jsonfield | |
lazy | ||
loremipsum | ||
lxml | ||
openedx-events | ||
path.py | ||
python-dateutil | ||
pytz | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
|
||
# A central location for most common version constraints | ||
# (across edx repos) for pip-installation. | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters