def test_android_unicode(self): self.assertEqual( ua.notification( android=ua.android( alert=u'Hello', time_to_live=u'100', ) ), { 'android': { 'alert': 'Hello', 'time_to_live': '100', } } )
def create_notification(type, source_id, from_user, for_user, message=None): notification = Notification(type=type, source_id=source_id, from_user=from_user, for_user=for_user, message=message, seen=False, action_taken=False) notification.save() extra = { "id": notification.id, "type": notification.type } app_key = settings.UA['app_key'] master_secret = settings.UA['master_secret'] logger.debug("app_key") logger.debug(app_key) logger.debug("master_secret") logger.debug(master_secret) airship = ua.Airship(app_key, master_secret) devices = for_user.user_devices.all() for device in devices: logger.debug("push_token") logger.debug(device.push_token) if device.push_token: push = airship.create_push() if device.device_type == 'iOS': push.audience = ua.device_token(device.push_token) elif device.device_type == 'Android': push.audience = ua.apid(device.push_token) push.notification = ua.notification(ios=ua.ios(alert=message, badge="+1", extra=extra), android=ua.android(alert=message, extra=extra)) push.device_types = ua.device_types('ios', 'android', ) logger.debug("push response") logger.debug(push.send()) return notification
def test_android(self): self.assertEqual( ua.notification(android=ua.android( alert='Hello', delay_while_idle=True, collapse_key='123456', time_to_live=100, extra={'more': 'stuff'} )), {'android': { 'alert': 'Hello', 'delay_while_idle': True, 'collapse_key': '123456', 'time_to_live': 100, 'extra': { 'more': 'stuff', } }})
def test_wearable(self): self.assertEqual( ua.android( alert='android alert', local_only=False, wearable={ 'background_image': 'http://example.com/background.png', 'extra_pages': [ {'title': 'title', 'alert': 'wearable alert'} ], 'interactive': { 'type': 'a_type', 'button_actions': { 'yes': {'add_tag': 'clicked_yes'} } } } ), { 'alert': 'android alert', 'local_only': False, 'wearable': { 'background_image': 'http://example.com/background.png', 'extra_pages': [ {'title': 'title', 'alert': 'wearable alert'} ], 'interactive': { 'type': 'a_type', 'button_actions': { 'yes': {'add_tag': 'clicked_yes'} } } } } )
def test_android(self): self.assertEqual( ua.notification( android=ua.android( alert='Hello', delay_while_idle=True, collapse_key='123456', time_to_live=100, extra={ 'more': 'stuff' }, interactive={ 'type': 'a_type', 'button_actions': { 'yes': { 'add_tag': 'clicked_yes' }, 'no': { 'add_tag': 'clicked_no' } } }, local_only=True, wearable={ 'background_image': 'http://example.com/background.png', 'extra_pages': [ { 'title': 'Page 1 title - optional title', 'alert': 'Page 1 title - optional alert' }, { 'title': 'Page 2 title - optional title', 'alert': 'Page 2 title - optional alert' } ], 'interactive': { 'type': 'a_type', 'button_actions': { 'yes': { 'add_tag': 'clicked_yes' }, 'no': { 'add_tag': 'clicked_no' } } } } ) ), { 'android': { 'alert': 'Hello', 'delay_while_idle': True, 'collapse_key': '123456', 'time_to_live': 100, 'extra': { 'more': 'stuff', }, 'interactive': { 'type': 'a_type', 'button_actions': { 'yes': { 'add_tag': 'clicked_yes' }, 'no': { 'add_tag': 'clicked_no' } } }, 'local_only': True, 'wearable': { 'background_image': 'http://example.com/background.png', 'extra_pages': [ { 'title': 'Page 1 title - optional title', 'alert': 'Page 1 title - optional alert' }, { 'title': 'Page 2 title - optional title', 'alert': 'Page 2 title - optional alert' } ], 'interactive': { 'type': 'a_type', 'button_actions': { 'yes': { 'add_tag': 'clicked_yes' }, 'no': { 'add_tag': 'clicked_no' } } } } } } )