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 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_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 push_notification(devices: list, title: str, message: str, extra: dict): push = airship.create_push() push.device_types = ua.device_types(*DeviceType.choices_list()) channels = [ua.android_channel(device.channel_id) for device in devices if device.device_type == 'android'] + \ [ua.ios_channel(device.channel_id) for device in devices if device.device_type == 'ios'] if len(channels) == 0: return push.audience = ua.and_(*channels) push.notification = ua.notification( alert=message, android=ua.android(alert=message, title=title, extra={'payload': json.dumps(extra)}), ios=ua.ios(alert=message, title=title, extra={'payload': json.dumps(extra)})) # print(push.payload) response = push.send() print(response.ok) return response
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' } } } } } } )
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' } } } }, delivery_priority='high', style={ 'type': 'big_picture', 'big_picture': 'bigpic.png', 'title': 'A title', 'summary': 'A summary' }, title='A title', summary='A summary', sound='cowbell.mp3', priority=-1, category='alarm', visibility=0, public_notification={ 'title': 'A title', 'alert': 'An alert', 'summary': 'A summary' }, notification_tag='test_notification_tag', notification_channel='test_notification_channel', icon='test_drawable_res.png', icon_color='#ff00bb')), { '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' } } } }, 'delivery_priority': 'high', 'style': { 'type': 'big_picture', 'big_picture': 'bigpic.png', 'title': 'A title', 'summary': 'A summary' }, 'title': 'A title', 'summary': 'A summary', 'sound': 'cowbell.mp3', 'priority': -1, 'category': 'alarm', 'visibility': 0, 'public_notification': { 'title': 'A title', 'alert': 'An alert', 'summary': 'A summary' }, 'notification_tag': 'test_notification_tag', 'notification_channel': 'test_notification_channel', 'icon': 'test_drawable_res.png', 'icon_color': '#ff00bb' } })
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' } } } } } })