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_send(self): request = FCMRequest(self._app, notification=MockNotification(), token='abc') message_id = request.send() self.assertEqual(message_id, 'message-id')