コード例 #1
0
    def test_delete_old_key_if_canonical_is_registered(self):
        notification = PushNotification.objects.create(
            title='test',
            payload=self.payload,
            active=PushNotification.PUSH_ACTIVE,
            sent=PushNotification.PUSH_NOT_SENT
        )
        # Create a test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY_ANDROID', type=Device.DEVICE_TYPE_ANDROID)
        Device.objects.create(key='123123', type=Device.DEVICE_TYPE_ANDROID)

        # Make sure old device is deleted if the new canonical ID already exists
        gcm = mock.Mock()
        gcm.return_value = '123123'
        with mock.patch('gcm.GCM.plaintext_request', new=gcm):
            send_push_notification_group(notification.id, 0, 1)

            self.assertFalse(Device.objects.filter(pk=device.id).exists())
コード例 #2
0
    def test_delete_old_key_if_canonical_is_registered(self):
        notification = PushNotification.objects.create(
            title='test',
            payload=self.payload,
            active=PushNotification.PUSH_ACTIVE,
            sent=PushNotification.PUSH_NOT_SENT)
        # Create a test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY_ANDROID',
                                       type=Device.DEVICE_TYPE_ANDROID)
        Device.objects.create(key='123123', type=Device.DEVICE_TYPE_ANDROID)

        # Make sure old device is deleted
        # if the new canonical ID already exists
        gcm = mock.Mock()
        gcm.return_value = '123123'
        with mock.patch('pushy.dispatchers.GCMDispatcher.send', new=gcm):
            send_push_notification_group(notification.to_dict(), 0, 1)

            self.assertFalse(Device.objects.filter(pk=device.id).exists())
コード例 #3
0
    def test_send_notification_groups(self):
        notification = PushNotification.objects.create(
            title='test',
            payload=self.payload,
            active=PushNotification.PUSH_ACTIVE,
            sent=PushNotification.PUSH_NOT_SENT)

        # Assert return when the notification was not found
        self.assertFalse(send_push_notification_group(13, 0, 1))

        # Create a test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY',
                                       type=Device.DEVICE_TYPE_ANDROID)

        # Make sure canonical ID is saved
        gcm = mock.Mock()
        gcm.return_value = 123123
        with mock.patch('gcm.GCM.plaintext_request', new=gcm):
            send_push_notification_group(notification.id, 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, '123123')

        # Make sure the key is deleted when not registered exception is fired
        gcm = mock.Mock()
        gcm.side_effect = GCMNotRegisteredException
        with mock.patch('gcm.GCM.plaintext_request', new=gcm):
            send_push_notification_group(notification.id, 0, 1)

            self.assertRaises(Device.DoesNotExist,
                              Device.objects.get,
                              pk=device.id)

        # Create an another test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY',
                                       type=Device.DEVICE_TYPE_ANDROID)

        # No canonical ID wasn't returned
        gcm = mock.Mock()
        gcm.return_value = False
        with mock.patch('gcm.GCM.plaintext_request', new=gcm):
            send_push_notification_group(notification.id, 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, 'TEST_DEVICE_KEY')
コード例 #4
0
ファイル: test_tasks.py プロジェクト: rakanalh/django-pushy
    def test_send_notification_groups(self):
        notification = PushNotification.objects.create(
            title='test',
            payload=self.payload,
            active=PushNotification.PUSH_ACTIVE,
            sent=PushNotification.PUSH_NOT_SENT
        )

        # Create a test device key
        device = Device.objects.create(
            key='TEST_DEVICE_KEY_ANDROID',
            type=Device.DEVICE_TYPE_ANDROID
        )

        # Make sure canonical ID is saved
        gcm = mock.Mock()
        gcm.return_value = 123123
        with mock.patch('pushy.dispatchers.GCMDispatcher.send', new=gcm):
            send_push_notification_group(notification.to_dict(), 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, '123123')

        # Make sure the key is deleted when not registered exception is fired
        gcm = mock.Mock()
        gcm.side_effect = PushInvalidTokenException
        with mock.patch('pushy.dispatchers.GCMDispatcher.send', new=gcm):
            send_push_notification_group(notification.to_dict(), 0, 1)

            self.assertRaises(
                Device.DoesNotExist,
                Device.objects.get,
                pk=device.id
            )

        # Create an another test device key
        device = Device.objects.create(
            key='TEST_DEVICE_KEY_ANDROID2',
            type=Device.DEVICE_TYPE_ANDROID
        )

        # No canonical ID wasn't returned
        gcm = mock.Mock()
        gcm.return_value = False
        with mock.patch('pushy.dispatchers.GCMDispatcher.send', new=gcm):
            send_push_notification_group(notification.to_dict(), 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, 'TEST_DEVICE_KEY_ANDROID2')
コード例 #5
0
ファイル: test_tasks.py プロジェクト: raverat/django-pushy
    def test_send_notification_groups(self):
        notification = PushNotification.objects.create(
            title='test',
            payload=self.payload,
            active=PushNotification.PUSH_ACTIVE,
            sent=PushNotification.PUSH_NOT_SENT
        )

        # Assert return when the notification was not found
        self.assertFalse(send_push_notification_group(13, 0, 1))

        # Create a test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY', type=Device.DEVICE_TYPE_ANDROID)

        # Make sure canonical ID is saved
        gcm = mock.Mock()
        gcm.return_value = 123123
        with mock.patch('gcm.GCM.plaintext_request', new=gcm):
            send_push_notification_group(notification.id, 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, '123123')

        # Make sure the key is deleted when not registered exception is fired
        gcm = mock.Mock()
        gcm.side_effect = GCMNotRegisteredException
        with mock.patch('gcm.GCM.plaintext_request', new=gcm):
            send_push_notification_group(notification.id, 0, 1)

            self.assertRaises(Device.DoesNotExist, Device.objects.get, pk=device.id)

        # Create an another test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY', type=Device.DEVICE_TYPE_ANDROID)

        # No canonical ID wasn't returned
        gcm = mock.Mock()
        gcm.return_value = False
        with mock.patch('gcm.GCM.plaintext_request', new=gcm):
            send_push_notification_group(notification.id, 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, 'TEST_DEVICE_KEY')
コード例 #6
0
    def test_send_notification_groups(self):
        notification = PushNotification.objects.create(
            title='test',
            payload=self.payload,
            active=PushNotification.PUSH_ACTIVE,
            sent=PushNotification.PUSH_NOT_SENT)

        # Create a test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY_ANDROID',
                                       type=Device.DEVICE_TYPE_ANDROID)

        # Make sure canonical ID is saved
        gcm = mock.Mock()
        gcm.return_value = 123123
        with mock.patch('pushy.dispatchers.GCMDispatcher.send', new=gcm):
            send_push_notification_group(notification.to_dict(), 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, '123123')

        # Make sure the key is deleted when not registered exception is fired
        gcm = mock.Mock()
        gcm.side_effect = PushInvalidTokenException
        with mock.patch('pushy.dispatchers.GCMDispatcher.send', new=gcm):
            send_push_notification_group(notification.to_dict(), 0, 1)

            self.assertRaises(Device.DoesNotExist,
                              Device.objects.get,
                              pk=device.id)

        # Create an another test device key
        device = Device.objects.create(key='TEST_DEVICE_KEY_ANDROID2',
                                       type=Device.DEVICE_TYPE_ANDROID)

        # No canonical ID wasn't returned
        gcm = mock.Mock()
        gcm.return_value = False
        with mock.patch('pushy.dispatchers.GCMDispatcher.send', new=gcm):
            send_push_notification_group(notification.to_dict(), 0, 1)

            device = Device.objects.get(pk=device.id)
            self.assertEqual(device.key, 'TEST_DEVICE_KEY_ANDROID2')