def test_platform_config_apns_priority(self): config = PlatformConfig(priority=PlatformPriority.HIGH) apns_config = config.platform_config(PlatformType.APNS) self.assertTrue(isinstance(apns_config, messaging.APNSConfig)) self.assertEqual(apns_config.headers, {'apns-priority': '10'}) self.assertTrue(isinstance(apns_config.payload, messaging.APNSPayload)) self.assertTrue(isinstance(apns_config.payload.aps, messaging.Aps))
def test_platform_config_apns(self): config = PlatformConfig(priority=PlatformPriority.NORMAL, collapse_key='collapse_key') apns_config = config.platform_config(PlatformType.APNS) self.assertTrue(isinstance(apns_config, messaging.APNSConfig)) self.assertEqual(apns_config.headers, {'apns-collapse-id': 'collapse_key', 'apns-priority': '5'}) self.assertTrue(isinstance(apns_config.payload, messaging.APNSPayload)) self.assertTrue(isinstance(apns_config.payload.aps, messaging.Aps))
def test_platform_config_apns_empty(self): config = PlatformConfig() apns_config = config.platform_config(PlatformType.APNS) self.assertTrue(isinstance(apns_config, messaging.APNSConfig)) self.assertIsNone(apns_config.headers) self.assertTrue(isinstance(apns_config.payload, messaging.APNSPayload)) self.assertTrue(isinstance(apns_config.payload.aps, messaging.Aps))
def test_platform_config_apns_collapse_key(self): config = PlatformConfig(collapse_key='apns_collapse_key') apns_config = config.platform_config(PlatformType.APNS) self.assertTrue(isinstance(apns_config, messaging.APNSConfig)) self.assertEqual(apns_config.headers, {'apns-collapse-id': 'apns_collapse_key'}) self.assertTrue(isinstance(apns_config.payload, messaging.APNSPayload)) self.assertTrue(isinstance(apns_config.payload.aps, messaging.Aps))
def test_platform_config_android(self): config = PlatformConfig(priority=PlatformPriority.NORMAL, collapse_key='collapse_key') android_config = config.platform_config(PlatformType.ANDROID) self.assertTrue(isinstance(android_config, messaging.AndroidConfig)) self.assertEqual(android_config.collapse_key, 'collapse_key') self.assertEqual(android_config.priority, 'NORMAL')
def test_platform_config_webpush(self): config = PlatformConfig(priority=PlatformPriority.NORMAL, collapse_key='collapse_key') webpush_config = config.platform_config(PlatformType.WEBPUSH) self.assertTrue(isinstance(webpush_config, messaging.WebpushConfig)) self.assertEqual(webpush_config.headers, { 'Topic': 'collapse_key', 'Urgency': 'normal' })
def test_str(self): fcm_notification = messaging.Notification(title='Title Here', body='Body here') data_payload = {'data': 'payload'} platform_config = PlatformConfig(priority=PlatformPriority.HIGH, collapse_key='general_collapse_key') apns_config = messaging.APNSConfig(headers={'apns-collapse-id': 'ios_collapse_key'}) notification = MockNotification(fcm_notification=fcm_notification, data_payload=data_payload, platform_config=platform_config, apns_config=apns_config) self.assertEqual(str(notification), 'MockNotification(data_payload={\'data\': \'payload\'} fcm_notification.title="Title Here" fcm_notification.body="Body here" platform_config=PlatformConfig(collapse_key="general_collapse_key" priority=1) apns_config={\'apns-collapse-id\': \'ios_collapse_key\'} webhook_message_data={\'data\': \'payload\'})')
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_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'])
def test_platform_config_webpush_empty(self): config = PlatformConfig() webpush_config = config.platform_config(PlatformType.WEBPUSH) self.assertTrue(isinstance(webpush_config, messaging.WebpushConfig)) self.assertIsNone(webpush_config.headers)
def test_platform_config_android_priority(self): config = PlatformConfig(priority=PlatformPriority.HIGH) android_config = config.platform_config(PlatformType.ANDROID) self.assertTrue(isinstance(android_config, messaging.AndroidConfig)) self.assertIsNone(android_config.collapse_key) self.assertEqual(android_config.priority, 'HIGH')
def test_platform_config_android_collapse_key(self): config = PlatformConfig(collapse_key='android_collapse_key') android_config = config.platform_config(PlatformType.ANDROID) self.assertTrue(isinstance(android_config, messaging.AndroidConfig)) self.assertEqual(android_config.collapse_key, 'android_collapse_key') self.assertIsNone(android_config.priority)
def test_platform_config_unsupported_platform_payload_type(self): # Hack this test as if we'd added a new PlatformType but hadn't supported it properly config = PlatformConfig() with patch.object(PlatformType, '_types', return_value=[-1]), \ self.assertRaises(ValueError, msg='Unsupported PlatformPayload platform_type: -1'): config.platform_config(-1)
def test_platform_config_unsupported_platform_type(self): config = PlatformConfig() with self.assertRaises(ValueError, msg='Unsupported platform_type: -1'): config.platform_config(-1)
def test_priority_supported(self): with self.assertRaises(ValueError, msg='Unsupported platform_priority: -1'): PlatformConfig(priority=-1)
def test_priority_type(self): with self.assertRaises(ValueError, msg='Unsupported platform_priority: abc'): PlatformConfig(priority='abc')
def test_empty(self): PlatformConfig()
def test_platform_config_webpush_priority(self): config = PlatformConfig(priority=PlatformPriority.HIGH) webpush_config = config.platform_config(PlatformType.WEBPUSH) self.assertTrue(isinstance(webpush_config, messaging.WebpushConfig)) self.assertEqual(webpush_config.headers, {'Urgency': 'high'})
def test_str(self): payload = PlatformConfig(collapse_key='android_collapse_key', priority=PlatformPriority.NORMAL) self.assertEqual( str(payload), 'PlatformConfig(collapse_key="android_collapse_key" priority=0)')
def platform_config(self): from models.fcm.platform_config import PlatformConfig return PlatformConfig(collapse_key='{}_favorite_update'.format(self.user_id))
def platform_config(self): from consts.fcm.platform_priority import PlatformPriority from models.fcm.platform_config import PlatformConfig return PlatformConfig(priority=PlatformPriority.HIGH)
def test_platform_config_webpush_collapse_key(self): config = PlatformConfig(collapse_key='webpush_collapse_key') webpush_config = config.platform_config(PlatformType.WEBPUSH) self.assertTrue(isinstance(webpush_config, messaging.WebpushConfig)) self.assertEqual(webpush_config.headers, {'Topic': 'webpush_collapse_key'})