Esempio n. 1
0
    def test_bad_values(self):
        """
        Test error conditions
        """

        # missing __init__ args
        with self.assertRaises(Exception):
            ParsePushNotificationChannelProvider()

        with self.assertRaises(Exception):
            ParsePushNotificationChannelProvider(application_id='foo')

        with self.assertRaises(Exception):
            ParsePushNotificationChannelProvider(rest_api_key='bar')

        # create instance with proper __init__ params
        channel = ParsePushNotificationChannelProvider(application_id='foo', rest_api_key='bar')

        # bad user_id
        with self.assertRaises(ValueError):
            channel.dispatch_notification_to_user(0, self.msg)

        # missing channel context
        with self.assertRaises(ValueError):
            channel.dispatch_notification_to_user(_PARSE_SERVICE_USER_ID, self.msg, None)

        # missing parse_channel_ids
        with self.assertRaises(ValueError):
            channel.dispatch_notification_to_user(_PARSE_SERVICE_USER_ID, self.msg, {})

        # bad type of parse_channel_ids
        with self.assertRaises(TypeError):
            channel.dispatch_notification_to_user(_PARSE_SERVICE_USER_ID, self.msg, {'parse_channel_ids': 'foo'})
Esempio n. 2
0
 def test_resolve_msg_link(self):
     """
     Make sure that resolve_msg_link returns None, because it is not applicable
     """
     channel = ParsePushNotificationChannelProvider(application_id='foo',
                                                    rest_api_key='bar')
     self.assertIsNone(channel.resolve_msg_link(self.msg, 'link', {}))
Esempio n. 3
0
    def test_bulk_publish_notification(self, mock_parse_push):
        """
        Happy path testing of a bulk push notification
        """
        channel = ParsePushNotificationChannelProvider(application_id='foo',
                                                       rest_api_key='bar')

        channel.bulk_dispatch_notification(
            [_PARSE_SERVICE_USER_ID],
            self.msg,
            channel_context={'parse_channel_ids': ['test_channel_id']})
        self.assertTrue(mock_parse_push.alert.called)
        mock_parse_push.alert.assert_called_with(data=self.msg.payload,
                                                 channels=['test_channel_id'])