예제 #1
0
    def _ping_webhook(client):
        from models.notifications.ping import PingNotification
        notification = PingNotification()

        from models.notifications.requests.webhook_request import WebhookRequest
        webhook_request = WebhookRequest(notification, client.messaging_id, client.secret)
        logging.info('Ping - {}'.format(str(webhook_request)))

        success = webhook_request.send()
        logging.info('Ping Sent')

        return success
예제 #2
0
    def _ping_client(client):
        client_type = client.client_type
        if client_type in ClientType.FCM_CLIENTS:
            from models.notifications.ping import PingNotification
            notification = PingNotification()

            from models.notifications.requests.fcm_request import FCMRequest
            fcm_request = FCMRequest(firebase_app,
                                     notification,
                                     tokens=[client.messaging_id])
            logging.info('Ping - {}'.format(str(fcm_request)))

            batch_response = fcm_request.send()
            if batch_response.failure_count > 0:
                response = batch_response.responses[0]
                logging.info('Error Sending Ping - {}'.format(
                    response.exception))
                return False
            else:
                logging.info('Ping Sent')
        elif client_type == ClientType.OS_ANDROID:
            # Send old notifications to Android
            from notifications.ping import PingNotification
            notification = PingNotification()
            notification.send({client_type: [client.messaging_id]})
        else:
            raise Exception(
                'Unsupported FCM client type: {}'.format(client_type))

        return True
예제 #3
0
 def test_type(self):
     self.assertEqual(PingNotification._type(), NotificationType.PING)
예제 #4
0
 def test_webhook_message_data(self):
     notification = PingNotification()
     self.assertEqual(notification.webhook_message_data, {
         'title': notification._title,
         'desc': notification._body
     })
예제 #5
0
 def test_data_payload(self):
     notification = PingNotification()
     self.assertIsNone(notification.data_payload)
예제 #6
0
 def test_notification_payload(self):
     notification = PingNotification()
     self.assertIsNotNone(notification.fcm_notification)
     fcm_notification = notification.fcm_notification
     self.assertEqual(fcm_notification.title, notification._title)
     self.assertEqual(fcm_notification.body, notification._body)