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)
Example #2
0
 def test_json_string_condition(self):
     message = FCMMessage(MockNotification(),
                          condition="\'dogs\' in topics")
     self.assertEqual(
         message.json_string(),
         '{"message": {"data": {"message_type": "verification"}, "condition": "\'dogs\' in topics"}}'
     )
Example #3
0
 def test_send(self):
     message = WebhookRequest(
         MockNotification(webhook_payload={'data': 'value'}),
         'https://www.thebluealliance.com/', 'secret')
     response = message.send()
     self.assertEqual(response.status_code, 200)
     self.assertIsNone(response.content)
Example #4
0
 def test_generate_webhook_checksum(self):
     message = WebhookRequest(
         MockNotification(webhook_payload={'data': 'value'}),
         'https://www.thebluealliance.com/', 'secret')
     message_json = message.json_string()
     self.assertEqual(message._generate_webhook_checksum(message_json),
                      'dbecd85ae53d221c387647085912d2107fa04cd5')
 def test_webhook_message_data(self):
     webhook_message_data = {'data': 'here'}
     notification = MockNotification(
         webhook_message_data=webhook_message_data)
     self.assertIsNone(notification.data_payload)
     self.assertEqual(notification.webhook_message_data,
                      webhook_message_data)
 def test_send_fail(self):
     message = WebhookRequest(
         MockNotification(
             webhook_message_data={'data': 'some new value value'}),
         'https://somenewwebsite.com', 'somenewsecret')
     with self.assertRaises(AssertionError):
         response = message.send()
Example #7
0
 def test_json_string_data_payload(self):
     message = FCMMessage(
         MockNotification(data_payload={"verification": "some_code"}),
         token='abc')
     self.assertEqual(
         message.json_string(),
         '{"message": {"token": "abc", "data": {"message_type": "verification", "verification": "some_code"}}}'
     )
 def test_send(self):
     message = WebhookRequest(
         MockNotification(webhook_message_data={'data': 'value'}),
         'https://www.thebluealliance.com/', 'secret')
     response = message.send()
     result = response.get_result()
     self.assertEqual(result.status_code, 200)
     self.assertEqual(result.content, 'Some content here')
Example #9
0
 def test_webhook_message(self):
     webhook_payload = {'test': 'something'}
     notification = MockNotification(webhook_payload=webhook_payload)
     message = WebhookRequest(notification,
                              'https://www.thebluealliance.com/', 'secret')
     self.assertEqual(
         message.json_string(),
         '{"message_data": {"test": "something"}, "message_type": "verification"}'
     )
Example #10
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"}}}'
     )
Example #11
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'}})
Example #12
0
 def test_json_string_notification_payload(self):
     message = FCMMessage(
         MockNotification(notification_payload=NotificationPayload(
             title='Title Here', body='Body here')),
         token='abc')
     self.assertEqual(
         message.json_string(),
         '{"message": {"notification": {"body": "Body here", "title": "Title Here"}, "token": "abc", "data": {"message_type": "verification"}}}'
     )
Example #13
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"}}}'
     )
 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)
 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')
    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\'})'
        )
Example #20
0
 def test_send(self):
     request = Request(MockNotification())
     with self.assertRaises(NotImplementedError):
         request.send()
Example #21
0
 def test_notification(self):
     Request(MockNotification())
Example #22
0
 def test_json_string(self):
     message = Message(notification=MockNotification())
     with self.assertRaises(NotImplementedError):
         message.send()
Example #23
0
 def test_init_delivery_multiple(self):
     with self.assertRaises(TypeError):
         FCMMessage(notification=MockNotification(),
                    token='abc',
                    topic='def')
Example #24
0
 def test_init_delivery_none(self):
     with self.assertRaises(TypeError):
         FCMMessage(notification=MockNotification())
Example #25
0
 def test_subclass(self):
     message = FCMMessage(MockNotification(), token='abcd')
     self.assertTrue(isinstance(message, Message))
Example #26
0
 def test_send(self):
     message = FCMMessage(notification=MockNotification(), token='abc')
     response = message.send()
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.content, 'Some content here')
Example #27
0
 def test_fcm_url(self):
     message = FCMMessage(MockNotification(), token='abc')
     self.assertEqual(
         message._fcm_url,
         'https://fcm.googleapis.com/v1/projects/testbed-test/messages:send'
     )
Example #28
0
 def test_str_condition(self):
     message = FCMMessage(MockNotification(), condition='hij')
     self.assertTrue(
         'FCMMessage(condition="hij", notification=' in str(message))
Example #29
0
 def test_str_topic(self):
     message = FCMMessage(MockNotification(), topic='def')
     self.assertTrue(
         'FCMMessage(topic="def", notification=' in str(message))
Example #30
0
 def test_str_token(self):
     message = FCMMessage(MockNotification(), token='abc')
     self.assertTrue(
         'FCMMessage(token="abc", notification=' in str(message))