def test_data_payload_url(self): notification = BroadcastNotification('T', 'B', 'https://thebluealliance.com/') self.assertEqual(notification.data_payload, { 'url': 'https://thebluealliance.com/', 'app_version': None })
def test_webhook_message_data_app_version(self): notification = BroadcastNotification('T', 'B', None, '1.0.0') payload = { 'title': 'T', 'desc': 'B', 'url': None, 'app_version': '1.0.0' } self.assertEqual(notification.webhook_message_data, payload)
def test_webhook_message_data_url_app_version(self): notification = BroadcastNotification('T', 'B', 'https://thebluealliance.com/', '1.0.0') payload = { 'title': 'T', 'desc': 'B', 'url': 'https://thebluealliance.com/' } self.assertEqual(notification.webhook_message_data, payload)
def broadcast(cls, client_types, title, message, url=None, app_version=None): from models.notifications.broadcast import BroadcastNotification notification = BroadcastNotification(title, message, url, app_version) # Send to FCM clients fcm_client_types = [ct for ct in client_types if ct in ClientType.FCM_CLIENTS] if fcm_client_types: clients = MobileClient.query(MobileClient.client_type.IN(fcm_client_types)).fetch() if clients: cls._defer_fcm(clients, notification) # Send to webhooks if ClientType.WEBHOOK in client_types: clients = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch() if clients: cls._defer_webhook(clients, notification) if ClientType.OS_ANDROID in client_types: clients = MobileClient.query(MobileClient.client_type == ClientType.OS_ANDROID).fetch() from helpers.push_helper import PushHelper keys = PushHelper.get_client_ids_for_clients(clients) from notifications.broadcast import BroadcastNotification notification = BroadcastNotification(title, message, url, app_version) notification.send(keys)
def broadcast(cls, client_types, title, message, url=None, app_version=None): from models.notifications.broadcast import BroadcastNotification notification = BroadcastNotification(title, message, url, app_version) # Send to FCM clients fcm_client_types = [ct for ct in client_types if ct in ClientType.FCM_CLIENTS] if fcm_client_types: clients = MobileClient.query(MobileClient.client_type.IN(fcm_client_types)).fetch() if clients: deferred.defer( cls._send_fcm, clients, notification, _queue="push-notifications", _url='/_ah/queue/deferred_notification_send' ) # Send to webhooks if ClientType.WEBHOOK in client_types: clients = MobileClient.query(MobileClient.client_type == ClientType.WEBHOOK).fetch() if clients: deferred.defer( cls._send_webhook, clients, notification, _queue="push-notifications", _url='/_ah/queue/deferred_notification_send' ) if ClientType.OS_ANDROID in client_types: from helpers.push_helper import PushHelper users = PushHelper.get_all_mobile_clients([ClientType.OS_ANDROID]) keys = PushHelper.get_client_ids_for_users(users) from notifications.broadcast import BroadcastNotification notification = BroadcastNotification(title, message, url, app_version) notification.send(keys)
def setUp(self): self.notification = BroadcastNotification('Title Here', 'Some body message ya dig')
def test_data_payload_url_app_version(self): notification = BroadcastNotification('T', 'B', None, '1.0.0') self.assertEqual(notification.data_payload, {'app_version': '1.0.0'})
def test_type(self): self.assertEqual(BroadcastNotification._type(), NotificationType.BROADCAST)