コード例 #1
0
 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
     })
コード例 #2
0
 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)
コード例 #3
0
 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)
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
 def setUp(self):
     self.notification = BroadcastNotification('Title Here',
                                               'Some body message ya dig')
コード例 #7
0
 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'})
コード例 #8
0
 def test_type(self):
     self.assertEqual(BroadcastNotification._type(),
                      NotificationType.BROADCAST)