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'})
    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'})