コード例 #1
0
 def test_fcm_message_platform_config_override(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH,
                                      collapse_key='collapse_key')
     apns_config = messaging.APNSConfig(
         headers={'apns-collapse-id': 'ios_collapse_key'})
     request = FCMRequest(self._app,
                          notification=MockNotification(
                              platform_config=platform_config,
                              apns_config=apns_config),
                          topic='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertIsNone(message.notification)
     self.assertTrue(isinstance(message.android, messaging.AndroidConfig))
     self.assertTrue(isinstance(message.apns, messaging.APNSConfig))
     self.assertEqual(message.apns.headers,
                      {'apns-collapse-id': 'ios_collapse_key'})
     self.assertTrue(isinstance(message.webpush, messaging.WebpushConfig))
     self.assertEqual(message.webpush.headers, {
         'Topic': 'collapse_key',
         'Urgency': 'high'
     })
     self.assertIsNone(message.token)
     self.assertEqual(message.topic, 'abc')
     self.assertIsNone(message.condition)
コード例 #2
0
    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')
コード例 #3
0
 def test_fcm_message_empty(self):
     request = FCMRequest(self._app, notification=MockNotification(), token='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertIsNone(message.notification)
     self.assertIsNone(message.android)
     self.assertIsNone(message.apns)
     self.assertIsNone(message.webpush)
     self.assertEqual(message.token, 'abc')
     self.assertIsNone(message.topic)
     self.assertIsNone(message.condition)
コード例 #4
0
 def test_fcm_message_platform_config(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH, collapse_key='collapse_key')
     request = FCMRequest(self._app, notification=MockNotification(platform_config=platform_config), topic='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertIsNone(message.notification)
     self.assertTrue(isinstance(message.android, messaging.AndroidConfig))
     self.assertTrue(isinstance(message.apns, messaging.APNSConfig))
     self.assertTrue(isinstance(message.webpush, messaging.WebpushConfig))
     self.assertIsNone(message.token)
     self.assertEqual(message.topic, 'abc')
     self.assertIsNone(message.condition)
コード例 #5
0
 def test_fcm_message_notification(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH, collapse_key='collapse_key')
     request = FCMRequest(self._app, notification=MockNotification(fcm_notification=messaging.Notification(title='Title', body='Some body message')), condition='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertTrue(isinstance(message.notification, messaging.Notification))
     self.assertIsNone(message.android)
     self.assertIsNone(message.apns)
     self.assertIsNone(message.webpush)
     self.assertIsNone(message.token)
     self.assertIsNone(message.topic)
     self.assertEqual(message.condition, 'abc')
コード例 #6
0
 def test_fcm_message_data_payload(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH, collapse_key='collapse_key')
     request = FCMRequest(self._app, notification=MockNotification(data_payload={'some_data': 'some test data'}), condition='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertEqual(message.data, {'notification_type': 'verification', 'some_data': 'some test data'})
     self.assertIsNone(message.notification)
     self.assertIsNone(message.android)
     self.assertIsNone(message.apns)
     self.assertIsNone(message.webpush)
     self.assertIsNone(message.token)
     self.assertIsNone(message.topic)
     self.assertEqual(message.condition, 'abc')
コード例 #7
0
 def test_fcm_message_empty(self):
     request = FCMRequest(self._app,
                          notification=MockNotification(),
                          token='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertIsNone(message.notification)
     self.assertIsNone(message.android)
     self.assertIsNone(message.apns)
     self.assertIsNone(message.webpush)
     self.assertEqual(message.token, 'abc')
     self.assertIsNone(message.topic)
     self.assertIsNone(message.condition)
コード例 #8
0
 def test_fcm_message_platform_config_override(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH, collapse_key='collapse_key')
     apns_config = messaging.APNSConfig(headers={'apns-collapse-id': 'ios_collapse_key'})
     request = FCMRequest(self._app, notification=MockNotification(platform_config=platform_config, apns_config=apns_config), topic='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertIsNone(message.notification)
     self.assertTrue(isinstance(message.android, messaging.AndroidConfig))
     self.assertTrue(isinstance(message.apns, messaging.APNSConfig))
     self.assertEqual(message.apns.headers, {'apns-collapse-id': 'ios_collapse_key'})
     self.assertTrue(isinstance(message.webpush, messaging.WebpushConfig))
     self.assertEqual(message.webpush.headers, {'Topic': 'collapse_key', 'Urgency': 'high'})
     self.assertIsNone(message.token)
     self.assertEqual(message.topic, 'abc')
     self.assertIsNone(message.condition)
コード例 #9
0
 def test_fcm_message_data_payload_default(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH,
                                      collapse_key='collapse_key')
     request = FCMRequest(self._app,
                          notification=MockNotification(),
                          condition='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertEqual(message.data, {'notification_type': 'verification'})
     self.assertIsNone(message.notification)
     self.assertIsNone(message.android)
     self.assertIsNone(message.apns)
     self.assertIsNone(message.webpush)
     self.assertIsNone(message.token)
     self.assertIsNone(message.topic)
     self.assertEqual(message.condition, 'abc')
コード例 #10
0
 def test_fcm_message_platform_config(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH,
                                      collapse_key='collapse_key')
     request = FCMRequest(
         self._app,
         notification=MockNotification(platform_config=platform_config),
         topic='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertIsNone(message.notification)
     self.assertTrue(isinstance(message.android, messaging.AndroidConfig))
     self.assertTrue(isinstance(message.apns, messaging.APNSConfig))
     self.assertTrue(isinstance(message.webpush, messaging.WebpushConfig))
     self.assertIsNone(message.token)
     self.assertEqual(message.topic, 'abc')
     self.assertIsNone(message.condition)
コード例 #11
0
 def test_fcm_message_notification(self):
     platform_config = PlatformConfig(priority=PlatformPriority.HIGH,
                                      collapse_key='collapse_key')
     request = FCMRequest(self._app,
                          notification=MockNotification(
                              fcm_notification=messaging.Notification(
                                  title='Title', body='Some body message')),
                          condition='abc')
     message = request._fcm_message()
     self.assertIsNotNone(message)
     self.assertIsNotNone(message.data)
     self.assertTrue(
         isinstance(message.notification, messaging.Notification))
     self.assertIsNone(message.android)
     self.assertIsNone(message.apns)
     self.assertIsNone(message.webpush)
     self.assertIsNone(message.token)
     self.assertIsNone(message.topic)
     self.assertEqual(message.condition, 'abc')
コード例 #12
0
 def test_send(self):
     request = FCMRequest(self._app, notification=MockNotification(), token='abc')
     message_id = request.send()
     self.assertEqual(message_id, 'message-id')
コード例 #13
0
 def test_init_app_type(self):
     with self.assertRaises(ValueError):
         FCMRequest('abc', MockNotification(), token='abcd')
コード例 #14
0
 def test_str_condition(self):
     request = FCMRequest(self._app, MockNotification(), condition='hij')
     self.assertTrue(
         'FCMRequest(condition="hij", notification=' in str(request))
コード例 #15
0
 def test_str_token(self):
     request = FCMRequest(self._app, MockNotification(), token='abc')
     self.assertTrue(
         'FCMRequest(token="abc", notification=' in str(request))
コード例 #16
0
 def test_init_delivery_multiple(self):
     with self.assertRaises(TypeError):
         FCMRequest(self._app,
                    notification=MockNotification(),
                    token='abc',
                    topic='def')
コード例 #17
0
 def test_init_delivery_none(self):
     with self.assertRaises(TypeError):
         FCMRequest(self._app, notification=MockNotification())
コード例 #18
0
 def test_init_app(self):
     FCMRequest(self._app, MockNotification(), token='abcd')
コード例 #19
0
 def test_send(self):
     request = FCMRequest(self._app,
                          notification=MockNotification(),
                          token='abc')
     message_id = request.send()
     self.assertEqual(message_id, 'message-id')
コード例 #20
0
 def test_str_topic(self):
     request = FCMRequest(self._app, MockNotification(), topic='def')
     self.assertTrue(
         'FCMRequest(topic="def", notification=' in str(request))
コード例 #21
0
 def test_subclass(self):
     request = FCMRequest(self._app, MockNotification(), token='abcd')
     self.assertTrue(isinstance(request, Request))