def ping(self, request): """ Immediately dispatch a Ping to either FCM or a webhook """ self._validate_authentication() if request.fcm and request.webhook: return self._application_error('Cannot ping both FCM and webhook') from tbans.models.notifications.ping import PingNotification notification = PingNotification() if request.fcm: from tbans.models.requests.notifications.fcm_request import FCMRequest fcm_request = FCMRequest(notification, token=request.fcm.token, topic=request.fcm.topic, condition=request.fcm.condition) logging.info('Ping - {}'.format(str(fcm_request))) response = fcm_request.send() logging.info('Ping Response - {}'.format(str(response))) return TBANSResponse(code=response.status_code, message=response.content) elif request.webhook: from tbans.models.requests.notifications.webhook_request import WebhookRequest webhook_request = WebhookRequest(notification, request.webhook.url, request.webhook.secret) logging.info('Ping - {}'.format(str(webhook_request))) response = webhook_request.send() logging.info('Ping Response - {}'.format(str(response))) return TBANSResponse(code=response.status_code, message=response.content) else: return self._application_error( 'Did not specify FCM or webhook to ping')
def ping(self, request): """ Immediately dispatch a Ping to either FCM or a webhook """ if not self._authenticated: raise remote.ApplicationError('Unauthenticated') if request.fcm and request.webhook: return TBANSResponse(code=400, message='Cannot ping both FCM and webhook') from tbans.models.notifications.ping import PingNotification notification = PingNotification() if request.fcm: from tbans.models.messages.fcm_message import FCMMessage message = FCMMessage(notification, token=request.fcm.token, topic=request.fcm.topic, condition=request.fcm.condition) logging.info('Ping - {}'.format(str(message))) response = message.send() logging.info('Ping Response - {}'.format(str(response))) return TBANSResponse(code=response.status_code, message=response.content) elif request.webhook: from tbans.models.messages.webhook_message import WebhookMessage message = WebhookMessage(notification, request.webhook.url, request.webhook.secret) logging.info('Ping - {}'.format(str(message))) response = message.send() logging.info('Ping Response - {}'.format(str(response))) return TBANSResponse(code=response.status_code, message=response.content) else: return TBANSResponse(code=400, message='Did not specify FCM or webhook to ping')
def ping(self, request): """ Immediately dispatch a Ping to either FCM or a webhook """ self._validate_authentication() if request.fcm and request.webhook: return self._application_error('Cannot ping both FCM and webhook') from tbans.models.notifications.ping import PingNotification notification = PingNotification() if request.fcm: # An FCM request can still exist, I believe. It can take some notification and delivery options from tbans.requests.fcm_request import FCMRequest fcm_request = FCMRequest(self._firebase_app, notification, token=request.fcm.token, topic=request.fcm.topic, condition=request.fcm.condition) logging.info('Ping - {}'.format(str(fcm_request))) message_id = fcm_request.send() logging.info('Ping Sent - {}'.format(str(message_id))) return TBANSResponse(code=200, message=message_id) elif request.webhook: from tbans.requests.webhook_request import WebhookRequest webhook_request = WebhookRequest(notification, request.webhook.url, request.webhook.secret) logging.info('Ping - {}'.format(str(webhook_request))) webhook_request.send() logging.info('Ping Sent') return TBANSResponse(code=200) else: return self._application_error('Did not specify FCM or webhook to ping')
def test_notification_payload(self): notification = PingNotification() self.assertIsNotNone(notification.notification_payload) notification_payload = notification.notification_payload self.assertEqual(notification_payload.payload_dict, { 'title': notification._title, 'body': notification._body })
def test_type(self): self.assertEqual(PingNotification._type(), NotificationType.PING)
def test_webhook_payload(self): notification = PingNotification() self.assertEqual(notification.webhook_payload, { 'title': notification._title, 'desc': notification._body })
def test_data_payload(self): notification = PingNotification() self.assertIsNone(notification.data_payload)
def test_webhook_message_data(self): notification = PingNotification() self.assertEqual(notification.webhook_message_data, { 'title': notification._title, 'desc': notification._body })
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)