def send_subscription_update(cls, user_id, sending_device_key=""):
        clients = PushHelper.get_client_ids_for_users(
            [user_id], os_types=[ClientType.OS_ANDROID])

        notification = UpdateSubscriptionsNotification(user_id,
                                                       sending_device_key)
        notification.send(clients)
class TestUpdateFavoritesNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.test_user = "******"  # Mock user ID
        self.sending_key = "31415926"
        self.keys = {ClientType.OS_ANDROID: [self.sending_key, "123456", "abcdefg"]}
        self.notification = UpdateSubscriptionsNotification(self.test_user, self.sending_key)
        self.notification.keys = self.keys

    def tearDown(self):
        self.testbed.deactivate()

    def test_build(self):
        expected = {}
        expected['message_type'] = NotificationType.type_names[NotificationType.UPDATE_SUBSCRIPTION]
        data = self.notification._build_dict()

        self.assertEqual(expected, data)

    """
    Because this notification type uses its own render method, we test that implementation here
    We're testing that we have matches on the user list and collapse key (data is tested above)
    """
    def test_render_android(self):
        collapse_key = "{}_subscriptions_update".format(self.test_user)
        user_list = ["123456", "abcdefg"]

        message = self.notification._render_android()
        self.assertEqual(collapse_key, message.collapse_key)
        self.assertEqual(user_list, message.device_tokens)
class TestUpdateFavoritesNotification(unittest2.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.test_user = "******"  # Mock user ID
        self.sending_key = "31415926"
        self.keys = {ClientType.OS_ANDROID: [self.sending_key, "123456", "abcdefg"]}
        self.notification = UpdateSubscriptionsNotification(self.test_user, self.sending_key)
        self.notification.keys = self.keys

    def tearDown(self):
        self.testbed.deactivate()

    def test_build(self):
        expected = {}
        expected['notification_type'] = NotificationType.type_names[NotificationType.UPDATE_SUBSCRIPTION]
        data = self.notification._build_dict()

        self.assertEqual(expected, data)

    """
    Because this notification type uses its own render method, we test that implementation here
    We're testing that we have matches on the user list and collapse key (data is tested above)
    """
    def test_render_android(self):
        collapse_key = "{}_subscriptions_update".format(self.test_user)
        user_list = ["123456", "abcdefg"]

        message = self.notification._render_android()
        self.assertEqual(collapse_key, message.collapse_key)
        self.assertEqual(user_list, message.device_tokens)
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.test_user = "******"  # Mock user ID
        self.sending_key = "31415926"
        self.keys = {ClientType.OS_ANDROID: [self.sending_key, "123456", "abcdefg"]}
        self.notification = UpdateSubscriptionsNotification(self.test_user, self.sending_key)
        self.notification.keys = self.keys
    def send_subscription_update(cls, user_id, sending_device_key):

        clients = PushHelper.get_client_ids_for_users("android", [user_id])
        if sending_device_key in clients:
            clients.remove(sending_device_key)
        if len(clients) == 0:
            return

        notification = UpdateSubscriptionsNotification(user_id)
        message = notification.build(ClientType.OS_ANDROID, {ClientType.OS_ANDROID: clients})
        gcm_connection = GCMConnection()
        gcm_connection.notify_device(message)
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        self.test_user = "******"  # Mock user ID
        self.sending_key = "31415926"
        self.keys = {ClientType.OS_ANDROID: [self.sending_key, "123456", "abcdefg"]}
        self.notification = UpdateSubscriptionsNotification(self.test_user, self.sending_key)
        self.notification.keys = self.keys
    def send_subscription_update(cls, user_id, sending_device_key=""):
        clients = PushHelper.get_client_ids_for_users([user_id])

        notification = UpdateSubscriptionsNotification(user_id, sending_device_key)
        notification.send(clients)