示例#1
0
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 = UpdateFavoritesNotification(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_FAVORITES]
        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 = "{}_favorite_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)
示例#2
0
    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 = UpdateFavoritesNotification(self.test_user, self.sending_key)
        self.notification.keys = self.keys
    def send_favorite_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 = UpdateFavoritesNotification(user_id)
        message = notification.build(ClientType.OS_ANDROID, {ClientType.OS_ANDROID: clients})
        gcm_connection = GCMConnection()
        gcm_connection.notify_device(message)
示例#4
0
    def send_favorite_update(cls, user_id, sending_device_key=""):
        clients = PushHelper.get_client_ids_for_users([user_id])

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