fix: Update ORA notification type for grouper (#36517)

This commit is contained in:
Hassan Raza
2025-04-14 15:02:25 +05:00
committed by GitHub
parent b893b23ce9
commit b14ff9ea8d
3 changed files with 19 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
""" Notification-related exceptions. """
class InvalidNotificationTypeError(Exception):
""" Exception raised when an invalid notification type is passed. """
pass # lint-amnesty, pylint: disable=unnecessary-pass

View File

@@ -2,14 +2,16 @@
Notification grouping utilities for notifications
"""
import datetime
from abc import ABC, abstractmethod
from typing import Dict, Type, Union
from pytz import utc
from abc import ABC, abstractmethod
from openedx.core.djangoapps.notifications.base_notification import COURSE_NOTIFICATION_TYPES
from openedx.core.djangoapps.notifications.models import Notification
from .exceptions import InvalidNotificationTypeError
class BaseNotificationGrouper(ABC):
"""
@@ -42,6 +44,10 @@ class NotificationRegistry:
"""
Registers the grouper class for the given notification type.
"""
if notification_type not in COURSE_NOTIFICATION_TYPES:
raise InvalidNotificationTypeError(
f"'{notification_type}' is not a valid notification type."
)
cls._groupers[notification_type] = grouper_class
return grouper_class
@@ -106,7 +112,7 @@ class NewPostGrouper(BaseNotificationGrouper):
}
@NotificationRegistry.register('ora_staff_notification')
@NotificationRegistry.register('ora_staff_notifications')
class OraStaffGrouper(BaseNotificationGrouper):
"""
Grouper for new ora staff notifications.

View File

@@ -26,6 +26,10 @@ class TestNotificationRegistry(unittest.TestCase):
Tests for the NotificationRegistry class
"""
@patch.dict(
'openedx.core.djangoapps.notifications.base_notification.COURSE_NOTIFICATION_TYPES',
{'test_notification': 'Test Notification'}
)
def test_register_and_get_grouper(self):
"""
Test that the register and get_grouper methods work as expected