def test_fcm_message_empty(self): request = FCMRequest(self.app, notification=MockNotification(), tokens=['abc']) message = request._fcm_message() self.assertIsNotNone(message) self.assertIsNotNone(message.data) self.assertIsNone(message.notification) self.assertIsNone(message.android) self.assertTrue(isinstance(message.apns, messaging.APNSConfig)) self.assertIsNone(message.webpush) self.assertEqual(message.tokens, ['abc'])
def test_fcm_message_data_payload_default(self): platform_config = PlatformConfig(priority=PlatformPriority.HIGH, collapse_key='collapse_key') request = FCMRequest(self.app, notification=MockNotification(), tokens=['abc']) message = request._fcm_message() self.assertIsNotNone(message) self.assertEqual(message.data, {'notification_type': 'verification'}) self.assertIsNone(message.notification) self.assertIsNone(message.android) self.assertTrue(isinstance(message.apns, messaging.APNSConfig)) self.assertIsNone(message.webpush) self.assertEqual(message.tokens, ['abc'])
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), tokens=['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.assertEqual(message.tokens, ['abc'])
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')), tokens=['abc']) message = request._fcm_message() self.assertIsNotNone(message) self.assertIsNotNone(message.data) self.assertTrue( isinstance(message.notification, messaging.Notification)) self.assertIsNone(message.android) self.assertTrue(isinstance(message.apns, messaging.APNSConfig)) self.assertIsNone(message.webpush) self.assertEqual(message.tokens, ['abc'])
def test_fcm_message_apns_content_available(self): request = FCMRequest(self.app, notification=MockNotification(), tokens=['abc']) message = request._fcm_message() self.assertIsNotNone(message) self.assertIsNotNone(message.data) self.assertIsNone(message.notification) self.assertIsNone(message.android) self.assertTrue(isinstance(message.apns, messaging.APNSConfig)) self.assertTrue(isinstance(message.apns.payload, messaging.APNSPayload)) self.assertTrue(isinstance(message.apns.payload.aps, messaging.Aps)) self.assertIsNone(message.apns.payload.aps.sound) self.assertTrue(message.apns.payload.aps.content_available) self.assertIsNone(message.webpush) self.assertEqual(message.tokens, ['abc'])
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'}), tokens=['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.assertEqual(message.tokens, ['abc'])
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), tokens=['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.assertEqual(message.tokens, ['abc'])