Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions openedx/core/djangoapps/notifications/exceptions.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions openedx/core/djangoapps/notifications/grouping_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -42,6 +44,10 @@ def decorator(grouper_class: Type[BaseNotificationGrouper]) -> Type[BaseNotifica
"""
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

Expand Down Expand Up @@ -106,7 +112,7 @@ def group(self, new_notification, old_notification):
}


@NotificationRegistry.register('ora_staff_notification')
@NotificationRegistry.register('ora_staff_notifications')
class OraStaffGrouper(BaseNotificationGrouper):
"""
Grouper for new ora staff notifications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down