org.notification_service

Attributes

logger

_TEST_NOTIFICATION_SERVICE

Classes

NotificationService

It can't hurt to abstract this Firebase notification away.

FirebaseNotificationService

Firebase implementation of the notification service.

TestNotificationService

Test implementation that records calls.

Functions

get_notification_service(→ NotificationService)

Get the appropriate notification service.

set_test_notification_service(→ None)

Set a test notification service for testing purposes.

Module Contents

org.notification_service.logger[source]
class org.notification_service.NotificationService[source]

Bases: abc.ABC

It can’t hurt to abstract this Firebase notification away. First and foremost, this should allow for testing without mocking the wohle house

abstractmethod send_notification(topic: str, title: str, body: str, data: dict[str, Any] | None = None) str[source]

Send a notification to a specific topic.

Args:

topic: The topic to send to title: Notification title body: Notification body data: Additional data to include

Returns:

str: Message ID or response

class org.notification_service.FirebaseNotificationService(credentials_json: str)[source]

Bases: NotificationService

Firebase implementation of the notification service.

credentials_dict[source]
_firebase_app = None[source]
_get_firebase_app() Any[source]

Get or initialize the Firebase app instance.

Returns:

The Firebase app instance.

send_notification(topic: str, title: str, body: str, data: dict[str, Any] | None = None) str[source]

Send notification via Firebase.

Args:

topic: Topic to send the notification to. title: The notification title. body: The notification body text. data: Optional additional data to include.

Returns:

The message ID from Firebase.

class org.notification_service.TestNotificationService[source]

Bases: NotificationService

Test implementation that records calls.

sent_messages: list[dict[str, str | dict[str, str]]][source]
send_notification(topic: str, title: str, body: str, data: dict[str, Any] | None = None) str[source]

Record the notification without sending it.

org.notification_service._TEST_NOTIFICATION_SERVICE: NotificationService | None = None[source]
org.notification_service.get_notification_service(credentials_json: str | None = None) NotificationService[source]

Get the appropriate notification service.

In tests, returns the test service if one has been registered. In production, returns a Firebase notification service.

Args:

credentials_json: Firebase credentials JSON for production use

Returns:

NotificationService: The notification service implementation

org.notification_service.set_test_notification_service(service: NotificationService | None = None) None[source]

Set a test notification service for testing purposes.

Args:

service: The test service to use, or None to clear