Ejemplo n.º 1
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', {}))
    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'})
Ejemplo n.º 3
0
    def test_parse_exception(self):
        """
        Make sure we can handle a simualted exception from Parse
        """

        with self.assertRaises(ChannelError):
            ParsePushNotificationChannelProvider.publish_notification(
                'test-runner', 'test-type', {
                    'foo': 'bar',
                    'one': 'two'
                }, ['test_channel_id'])
 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',
             {}
         )
     )
Ejemplo n.º 5
0
    def test_publish_notification(self, mock_parse_push):
        """
        Happy path testing of a push notification
        """

        ParsePushNotificationChannelProvider.publish_notification(
            'test-runner', 'test-type', {
                'foo': 'bar',
                'one': 'two'
            }, ['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'])
Ejemplo n.º 6
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'])
    def test_parse_exception(self):
        """
        Make sure we can handle a simualted exception from Parse
        """

        with self.assertRaises(ChannelError):
            ParsePushNotificationChannelProvider.publish_notification(
                'test-runner',
                'test-type',
                {
                    'foo': 'bar',
                    'one': 'two'
                },
                ['test_channel_id']
            )
    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'])
    def test_publish_notification(self, mock_parse_push):
        """
        Happy path testing of a push notification
        """

        ParsePushNotificationChannelProvider.publish_notification(
            'test-runner',
            'test-type',
            {
                'foo': 'bar',
                'one': 'two'
            },
            ['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'])
Ejemplo n.º 10
0
    def test_publish_timed_notification(self, mock_parse_push):
        """
        Happy path testing of a push notification that is put on a timer
        """

        send_at = datetime.now(pytz.UTC) - timedelta(days=1)

        ParsePushNotificationChannelProvider.publish_notification(
            'test-runner',
            'test-type', {
                'foo': 'bar',
                'one': 'two'
            }, ['test_channel_id'],
            send_at=send_at)

        # force the timer to execute
        poll_and_execute_timers()

        # Parse should have been called
        self.assertTrue(mock_parse_push.alert.called)
        mock_parse_push.alert.assert_called_with(data=self.msg.payload,
                                                 channels=['test_channel_id'])
Ejemplo n.º 11
0
    def test_publish_timed_notification(self, mock_parse_push):
        """
        Happy path testing of a push notification that is put on a timer
        """

        send_at = datetime.now(pytz.UTC) - timedelta(days=1)

        ParsePushNotificationChannelProvider.publish_notification(
            'test-runner',
            'test-type',
            {
                'foo': 'bar',
                'one': 'two'
            },
            ['test_channel_id'],
            send_at=send_at
        )

        # force the timer to execute
        poll_and_execute_timers()

        # Parse should have been called
        self.assertTrue(mock_parse_push.alert.called)
        mock_parse_push.alert.assert_called_with(data=self.msg.payload, channels=['test_channel_id'])
Ejemplo n.º 12
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'})