コード例 #1
0
 def test_platform_payload_dict(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.ANDROID,
                               priority=PlatformPayloadPriority.NORMAL,
                               collapse_key='android_collapse_key')
     self.assertNotEqual(
         payload.payload_dict,
         payload.platform_payload_dict(PlatformPayloadType.APNS))
コード例 #2
0
    def test_str(self):
        notification_payload = NotificationPayload(title='Title Here', body='Body here')
        data_payload = {'data': 'payload'}
        platform_payload = PlatformPayload(priority=PlatformPayloadPriority.HIGH, collapse_key='general_collapse_key')
        apns_payload = PlatformPayload(platform_type=PlatformPayloadType.APNS, priority=PlatformPayloadPriority.NORMAL, collapse_key='ios_collapse_key')

        notification = MockNotification(notification_payload=notification_payload, data_payload=data_payload, platform_payload=platform_payload, apns_payload=apns_payload)
        self.assertEqual(str(notification), 'MockNotification(data_payload={\'data\': \'payload\'} notification_payload=NotificationPayload(title="Title Here" body="Body here") platform_payload=PlatformPayload(platform_type=None priority=1 collapse_key="general_collapse_key") apns_payload=PlatformPayload(platform_type=1 priority=0 collapse_key="ios_collapse_key") webhook_payload={\'data\': \'payload\'})')
コード例 #3
0
    def test_set_platform_payload_override(self):
        data = {}

        platform_payload = PlatformPayload(priority=PlatformPayloadPriority.HIGH, collapse_key='collapse_key')
        apns_payload = PlatformPayload(platform_type=PlatformPayloadType.APNS, priority=PlatformPayloadPriority.NORMAL, collapse_key='different_collapse_key')

        notification = MockNotification(platform_payload=platform_payload, apns_payload=apns_payload)
        FCMRequest._set_platform_payload(data, PlatformPayloadType.APNS, notification.apns_payload, notification.platform_payload)
        self.assertEqual(data, {'apns': {'apns-collapse-id': 'different_collapse_key', 'apns-priority': '5'}})
コード例 #4
0
 def test_platform_payload_webpush(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.WEBPUSH,
                               priority=PlatformPayloadPriority.NORMAL,
                               collapse_key='web_collapse_key')
     self.assertEqual(payload.payload_dict, {
         'Urgency': 'normal',
         'Topic': 'web_collapse_key'
     })
     self.assertEqual(
         payload.payload_dict,
         payload.platform_payload_dict(PlatformPayloadType.WEBPUSH))
コード例 #5
0
 def test_platform_payload_apns(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.APNS,
                               priority=PlatformPayloadPriority.NORMAL,
                               collapse_key='ios_collapse_key')
     self.assertEqual(payload.payload_dict, {
         'apns-priority': '5',
         'apns-collapse-id': 'ios_collapse_key'
     })
     self.assertEqual(
         payload.payload_dict,
         payload.platform_payload_dict(PlatformPayloadType.APNS))
コード例 #6
0
 def test_platform_payload_android(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.ANDROID,
                               priority=PlatformPayloadPriority.NORMAL,
                               collapse_key='android_collapse_key')
     self.assertEqual(payload.payload_dict, {
         'priority': 'NORMAL',
         'collapse_key': 'android_collapse_key'
     })
     self.assertEqual(
         payload.payload_dict,
         payload.platform_payload_dict(PlatformPayloadType.ANDROID))
コード例 #7
0
 def test_json_string_platform_payload_override(self):
     platform_payload = PlatformPayload(
         priority=PlatformPayloadPriority.HIGH, collapse_key='collapse_key')
     apns_payload = PlatformPayload(platform_type=PlatformPayloadType.APNS,
                                    priority=PlatformPayloadPriority.NORMAL,
                                    collapse_key='different_collapse_key')
     message = FCMMessage(MockNotification(
         platform_payload=platform_payload, apns_payload=apns_payload),
                          token='abc')
     self.assertEqual(
         message.json_string(),
         '{"message": {"apns": {"apns-collapse-id": "different_collapse_key", "apns-priority": "5"}, "token": "abc", "data": {"message_type": "verification"}, "android": {"priority": "HIGH", "collapse_key": "collapse_key"}, "webpush": {"Topic": "collapse_key", "Urgency": "high"}}}'
     )
コード例 #8
0
 def test_str_partial(self):
     payload = PlatformPayload(priority=PlatformPayloadPriority.NORMAL,
                               collapse_key='android_collapse_key')
     self.assertEqual(
         str(payload),
         'PlatformPayload(platform_type=None priority=0 collapse_key="android_collapse_key")'
     )
コード例 #9
0
 def test_json_string_platform_payload(self):
     message = FCMMessage(MockNotification(platform_payload=PlatformPayload(
         priority=PlatformPayloadPriority.HIGH,
         collapse_key='collapse_key')),
                          token='abc')
     self.assertEqual(
         message.json_string(),
         '{"message": {"apns": {"apns-collapse-id": "collapse_key", "apns-priority": "10"}, "token": "abc", "data": {"message_type": "verification"}, "android": {"priority": "HIGH", "collapse_key": "collapse_key"}, "webpush": {"Topic": "collapse_key", "Urgency": "high"}}}'
     )
コード例 #10
0
 def test_platform_payload_webpush(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.WEBPUSH, priority=PlatformPayloadPriority.NORMAL, collapse_key='web_collapse_key')
     self.assertEqual(payload.payload_dict, {'Urgency': 'normal', 'Topic': 'web_collapse_key'})
     self.assertEqual(payload.payload_dict, payload.platform_payload_dict(PlatformPayloadType.WEBPUSH))
コード例 #11
0
 def platform_payload(self):
     return PlatformPayload(
         collapse_key='{}_{}_update'.format(self.user_id, self.type_name))
コード例 #12
0
 def test_platform_payload_android(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.ANDROID, priority=PlatformPayloadPriority.NORMAL, collapse_key='android_collapse_key')
     self.assertEqual(payload.payload_dict, {'priority': 'NORMAL', 'collapse_key': 'android_collapse_key'})
     self.assertEqual(payload.payload_dict, payload.platform_payload_dict(PlatformPayloadType.ANDROID))
コード例 #13
0
 def test_platform_payload_apns(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.APNS, priority=PlatformPayloadPriority.NORMAL, collapse_key='ios_collapse_key')
     self.assertEqual(payload.payload_dict, {'apns-priority': '5', 'apns-collapse-id': 'ios_collapse_key'})
     self.assertEqual(payload.payload_dict, payload.platform_payload_dict(PlatformPayloadType.APNS))
コード例 #14
0
 def test_platform_payload_dict_unsupported(self):
     payload = PlatformPayload()
     with self.assertRaises(TypeError):
         payload.platform_payload_dict(200)
コード例 #15
0
 def test_platform_payload_dict(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.ANDROID, priority=PlatformPayloadPriority.NORMAL, collapse_key='android_collapse_key')
     self.assertNotEqual(payload.payload_dict, payload.platform_payload_dict(PlatformPayloadType.APNS))
コード例 #16
0
 def test_collapse_key_type(self):
     with self.assertRaises(TypeError):
         PlatformPayload(collapse_key=True)
コード例 #17
0
 def test_platform_type_supported(self):
     with self.assertRaises(TypeError):
         PlatformPayload(platform_type=200)
コード例 #18
0
 def test_platform_type_empty(self):
     PlatformPayload()
コード例 #19
0
 def test_validate_platform_type(self):
     PlatformPayload._validate_platform_type(PlatformPayloadType.APNS)
コード例 #20
0
 def test_validate_platform_type_unsupported(self):
     with self.assertRaises(TypeError):
         PlatformPayload._validate_platform_type(200)
コード例 #21
0
 def test_str(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.ANDROID,
                               priority=PlatformPayloadPriority.NORMAL,
                               collapse_key='android_collapse_key')
コード例 #22
0
 def test_platform_payload_dict_unsupported(self):
     payload = PlatformPayload()
     with self.assertRaises(TypeError):
         payload.platform_payload_dict(200)
コード例 #23
0
 def test_platform_type_type(self):
     with self.assertRaises(TypeError):
         PlatformPayload(platform_type='abc')
コード例 #24
0
 def test_validate_platform_type_unsupported(self):
     with self.assertRaises(TypeError):
         PlatformPayload._validate_platform_type(200)
コード例 #25
0
 def platform_payload(self):
     from tbans.models.notifications.payloads.platform_payload import PlatformPayload
     return PlatformPayload(
         collapse_key='{}_{}_update'.format(self.user_id, self.type_name))
コード例 #26
0
 def test_platform_payload_empty(self):
     payload = PlatformPayload(platform_type=PlatformPayloadType.ANDROID)
     self.assertIsNone(payload.payload_dict)
コード例 #27
0
 def test_validate_platform_type(self):
     PlatformPayload._validate_platform_type(PlatformPayloadType.APNS)
コード例 #28
0
 def test_priority_supported(self):
     with self.assertRaises(TypeError):
         PlatformPayload(priority='abc')