Exemple #1
0
 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')
Exemple #2
0
 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'
     })
Exemple #3
0
 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_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)
 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')
 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)
    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_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')
Exemple #9
0
 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 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'})
Exemple #11
0
 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'})
 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_apns_empty(self):
     config = PlatformConfig()
     apns_config = config.platform_config(PlatformType.APNS)
     self.assertTrue(isinstance(apns_config, messaging.APNSConfig))
     self.assertIsNone(apns_config.headers)
Exemple #14
0
 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(self):
     config = PlatformConfig()
     with self.assertRaises(ValueError):
         config.platform_config(-1)
Exemple #16
0
 def test_priority_supported(self):
     with self.assertRaises(ValueError):
         PlatformConfig(priority=-1)
Exemple #17
0
 def test_platform_config_unsupported(self):
     config = PlatformConfig()
     with self.assertRaises(ValueError):
         config.platform_config(-1)
Exemple #18
0
 def test_priority_type(self):
     with self.assertRaises(TypeError):
         PlatformConfig(priority='abc')
Exemple #19
0
 def test_collapse_key_type(self):
     with self.assertRaises(TypeError):
         PlatformConfig(collapse_key=True)
Exemple #20
0
 def test_empty(self):
     PlatformConfig()
Exemple #21
0
 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)
Exemple #22
0
 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_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_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_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_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_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 platform_config(self):
     from tbans.models.fcm.platform_config import PlatformConfig
     return PlatformConfig(collapse_key='{}_subscriptions_update'.format(self.user_id))
 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'})
Exemple #30
0
 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'})
 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'})
Exemple #32
0
 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_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'})
Exemple #34
0
 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)
 def platform_config(self):
     from tbans.consts.fcm.platform_priority import PlatformPriority
     from tbans.models.fcm.platform_config import PlatformConfig
     return PlatformConfig(priority=PlatformPriority.HIGH)
Exemple #36
0
 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'})