def test_rich_push(self): self.assertEqual( ua.message( title='My Title', body='My Body', content_type='text/html', content_encoding='utf8', extra={ 'more': 'stuff' }, expiry='time' ), { 'title': 'My Title', 'body': 'My Body', 'content_type': 'text/html', 'content_encoding': 'utf8', 'extra': { 'more': 'stuff' }, 'expiry': 'time' } ) self.assertEqual( ua.message( title='My Title', body='My Body'), { 'title': 'My Title', 'body': 'My Body' } )
def test_rich_push(self): self.assertEqual( ua.message("My Title", "My Body", content_type='text/html', content_encoding='utf8'), { 'title': 'My Title', 'body': 'My Body', 'content_type': 'text/html', 'content_encoding': 'utf8', }) self.assertEqual( ua.message("My Title", "My Body"), {'title': 'My Title', 'body': 'My Body'})
def test_rich_push(self): self.assertEqual( ua.message("My Title", "My Body", content_type='text/html', content_encoding='utf8'), { 'title': 'My Title', 'body': 'My Body', 'content_type': 'text/html', 'content_encoding': 'utf8', }) self.assertEqual(ua.message("My Title", "My Body"), { 'title': 'My Title', 'body': 'My Body' })
def test_ios_alert_dict(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(ios=ua.ios(alert={'foo': 'bar'})) p.options = ua.options(10080) p.device_types = 'ios' p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'ios': { 'alert': { 'foo': 'bar' } } }, 'device_types': 'ios', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', } })
def test_full_scheduled_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = {} p.device_types = ua.all_ p.message = ua.message("Title", "Body", "text/html", "utf8") sched = ua.ScheduledPush(None) sched.push = p sched.name = "a schedule" sched.schedule = ua.scheduled_time( datetime.datetime(2014, 1, 1, 12, 0, 0)) self.assertEqual( sched.payload, { "name": "a schedule", "schedule": { 'scheduled_time': '2014-01-01T12:00:00' }, "push": { "audience": "all", "notification": { "alert": "Hello" }, "device_types": "all", "options": {}, "message": { "title": "Title", "body": "Body", "content_type": "text/html", "content_encoding": "utf8", }, } })
def test_full_scheduled_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = {} p.device_types = ua.all_ p.message = ua.message("Title", "Body", "text/html", "utf8") sched = ua.ScheduledPush(None) sched.push = p sched.name = "a schedule" sched.schedule = ua.scheduled_time( datetime.datetime(2014, 1, 1, 12, 0, 0)) self.assertEqual(sched.payload, { "name": "a schedule", "schedule": {'scheduled_time': '2014-01-01T12:00:00'}, "push": { "audience": "all", "notification": {"alert": "Hello"}, "device_types": "all", "options": {}, "message": { "title": "Title", "body": "Body", "content_type": "text/html", "content_encoding": "utf8", }, } })
def test_interactive(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification( alert='Hey, click yes!', interactive=ua.interactive( type='some_type', button_actions={ 'yes': { 'add_tag': 'clicked_yes', 'remove_tag': 'never_clicked_yes', 'open': { 'type': 'url', 'content': 'http://www.urbanairship.com' } }, 'no': { 'add_tag': 'hater' } })) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'alert': 'Hey, click yes!', 'interactive': { 'type': 'some_type', 'button_actions': { 'yes': { 'add_tag': 'clicked_yes', 'remove_tag': 'never_clicked_yes', 'open': { 'type': 'url', 'content': 'http://www.urbanairship.com' } }, 'no': { 'add_tag': 'hater' } } } }, 'device_types': 'all', 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', } })
def test_full_scheduled_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = ua.options(10080) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', extra={'more': 'stuff'}, expiry=10080, icons={'list_icon': 'http://cdn.example.com/message.png'}, options={'some_delivery_option': 'true'}, ) sched = ua.ScheduledPush(None) sched.push = p sched.name = 'a schedule' sched.schedule = ua.scheduled_time( datetime.datetime(2014, 1, 1, 12, 0, 0)) self.assertEqual( sched.payload, { 'name': 'a schedule', 'schedule': { 'scheduled_time': '2014-01-01T12:00:00' }, 'push': { 'audience': 'all', 'notification': { 'alert': 'Hello' }, 'device_types': 'all', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', 'extra': { 'more': 'stuff' }, 'expiry': 10080, 'icons': { 'list_icon': 'http://cdn.example.com/message.png' }, 'options': { 'some_delivery_option': 'true' }, }, } })
def test_rich_push(self): self.assertEqual( ua.message(title='My Title', body='My Body', content_type='text/html', content_encoding='utf8', extra={'more': 'stuff'}, expiry='time'), { 'title': 'My Title', 'body': 'My Body', 'content_type': 'text/html', 'content_encoding': 'utf8', 'extra': { 'more': 'stuff' }, 'expiry': 'time' }) self.assertEqual(ua.message(title='My Title', body='My Body'), { 'title': 'My Title', 'body': 'My Body' })
def test_actions(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification( alert='Hello', actions=ua.actions( add_tag='new_tag', remove_tag='old_tag', share='Check out Urban Airship!', open_={ 'type': 'url', 'content': 'http://www.urbanairship.com' }, app_defined={'some_app_defined_action': 'some_values'} ) ) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'alert': 'Hello', 'actions': { 'add_tag': 'new_tag', 'remove_tag': 'old_tag', 'share': 'Check out Urban Airship!', 'open': { 'type': 'url', 'content': 'http://www.urbanairship.com' }, 'app_defined': { 'some_app_defined_action': 'some_values' } } }, 'device_types': 'all', 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', } } )
def test_full_scheduled_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = ua.options(10080) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', extra={'more': 'stuff'}, expiry=10080, icons={ 'list_icon': 'http://cdn.example.com/message.png' }, options={'some_delivery_option': 'true'}, ) sched = ua.ScheduledPush(None) sched.push = p sched.name = 'a schedule' sched.schedule = ua.scheduled_time( datetime.datetime(2014, 1, 1, 12, 0, 0) ) self.assertEqual( sched.payload, { 'name': 'a schedule', 'schedule': {'scheduled_time': '2014-01-01T12:00:00'}, 'push': { 'audience': 'all', 'notification': {'alert': 'Hello'}, 'device_types': 'all', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', 'extra': {'more': 'stuff'}, 'expiry': 10080, 'icons': { 'list_icon': 'http://cdn.example.com/message.png' }, 'options': {'some_delivery_option': 'true'}, }, } } )
def test_full_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = ua.options(expiry=10080) p.campaigns = ua.campaigns( categories=['kittens', 'tacos', 'horse_racing']) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', extra={'more': 'stuff'}, expiry=10080, icons={'list_icon': 'http://cdn.example.com/message.png'}, options={'some_delivery_option': 'true'}, ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'alert': 'Hello' }, 'device_types': 'all', 'options': { 'expiry': 10080 }, 'campaigns': { 'categories': ['kittens', 'tacos', 'horse_racing'] }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', 'extra': { 'more': 'stuff' }, 'expiry': 10080, 'icons': { 'list_icon': 'http://cdn.example.com/message.png' }, 'options': { 'some_delivery_option': 'true' }, } })
def message(test): message = test['message'] if 'title' in message and 'body' in message: message_opts = {} for k,v in test['message'].iteritems(): if k == 'title': message_opts['title'] = v if k == 'body': message_opts['body'] = v if k == 'extra': message_opts['extra'] = v return ua.message(**message_opts) else: return None
def test_full_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = ua.options(expiry=10080) p.campaigns = ua.campaigns( categories=['kittens', 'tacos', 'horse_racing'] ) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', extra={'more': 'stuff'}, expiry=10080, icons={'list_icon': 'http://cdn.example.com/message.png'}, options={'some_delivery_option': 'true'}, ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': {'alert': 'Hello'}, 'device_types': 'all', 'options': { 'expiry': 10080 }, 'campaigns': { 'categories': ['kittens', 'tacos', 'horse_racing'] }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', 'extra': {'more': 'stuff'}, 'expiry': 10080, 'icons': { 'list_icon': 'http://cdn.example.com/message.png' }, 'options': {'some_delivery_option': 'true'}, } } )
def test_local_scheduled_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = ua.options(10080) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) sched = ua.ScheduledPush(None) sched.push = p sched.name = 'a schedule in device local time' sched.schedule = ua.local_scheduled_time( datetime.datetime(2015, 1, 1, 12, 0, 0)) self.assertEqual( sched.payload, { 'name': 'a schedule in device local time', 'schedule': { 'local_scheduled_time': '2015-01-01T12:00:00' }, 'push': { 'audience': 'all', 'notification': { 'alert': 'Hello' }, 'device_types': 'all', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8' }, } })
def test_full_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = {} p.device_types = ua.all_ p.message = ua.message("Title", "Body", "text/html", "utf8") self.assertEqual(p.payload, { "audience": "all", "notification": {"alert": "Hello"}, "device_types": "all", "options": {}, "message": { "title": "Title", "body": "Body", "content_type": "text/html", "content_encoding": "utf8", } })
def test_ios_alert_dict(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification( ios=ua.ios( alert={'foo': 'bar'} ) ) p.options = ua.options(10080) p.device_types = 'ios' p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'ios': { 'alert': { 'foo': 'bar' } } }, 'device_types': 'ios', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', } } )
def test_local_scheduled_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = ua.options(10080) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) sched = ua.ScheduledPush(None) sched.push = p sched.name = 'a schedule in device local time' sched.schedule = ua.local_scheduled_time( datetime.datetime(2015, 1, 1, 12, 0, 0) ) self.assertEqual(sched.payload, { 'name': 'a schedule in device local time', 'schedule': {'local_scheduled_time': '2015-01-01T12:00:00'}, 'push': { 'audience': 'all', 'notification': {'alert': 'Hello'}, 'device_types': 'all', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8' }, } })
def test_full_payload(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification(alert='Hello') p.options = {} p.device_types = ua.all_ p.message = ua.message("Title", "Body", "text/html", "utf8") self.assertEqual( p.payload, { "audience": "all", "notification": { "alert": "Hello" }, "device_types": "all", "options": {}, "message": { "title": "Title", "body": "Body", "content_type": "text/html", "content_encoding": "utf8", } })
def test_ios_overrides(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification( ios=ua.ios(alert={ 'title': 'this is', 'body': 'backwards', 'summary-arg': 'Matmos', 'summary-arg-count': 1 }, sound={ 'name': 'Amplified Synapse', 'volume': 0.8, 'critical': False }, thread_id='plastic minor', priority=10, badge=3, extra={'office': 'furniture'}, mutable_content=False, title='this is', subtitle='backwards', collapse_id='nugent sand')) p.options = ua.options(10080) p.device_types = 'ios' p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'ios': { 'alert': { 'title': 'this is', 'body': 'backwards', 'summary-arg': 'Matmos', 'summary-arg-count': 1 }, 'sound': { 'name': 'Amplified Synapse', 'volume': 0.8, 'critical': False }, 'thread_id': 'plastic minor', 'priority': 10, 'badge': 3, 'extra': { 'office': 'furniture' }, 'mutable_content': False, 'title': 'this is', 'subtitle': 'backwards', 'collapse_id': 'nugent sand' } }, 'device_types': 'ios', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', } })
def test_ios_overrides(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification( ios=ua.ios( alert={'title': 'this is', 'body': 'backwards', 'summary-arg': 'Matmos', 'summary-arg-count': 1}, sound={'name': 'Amplified Synapse', 'volume': 0.8, 'critical': False}, thread_id='plastic minor', priority=10, badge=3, extra={'office': 'furniture'}, mutable_content=False, title='this is', subtitle='backwards', collapse_id='nugent sand' ) ) p.options = ua.options(10080) p.device_types = 'ios' p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'ios': { 'alert': { 'title': 'this is', 'body': 'backwards', 'summary-arg': 'Matmos', 'summary-arg-count': 1 }, 'sound': { 'name': 'Amplified Synapse', 'volume': 0.8, 'critical': False }, 'thread_id': 'plastic minor', 'priority': 10, 'badge': 3, 'extra': { 'office': 'furniture' }, 'mutable_content': False, 'title': 'this is', 'subtitle': 'backwards', 'collapse_id': 'nugent sand' } }, 'device_types': 'ios', 'options': { 'expiry': 10080 }, 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', } } )
def test_interactive(self): p = ua.Push(None) p.audience = ua.all_ p.notification = ua.notification( alert='Hey, click yes!', interactive=ua.interactive( type='some_type', button_actions={ 'yes': { 'add_tag': 'clicked_yes', 'remove_tag': 'never_clicked_yes', 'open': { 'type': 'url', 'content': 'http://www.urbanairship.com' } }, 'no': { 'add_tag': 'hater' } } ) ) p.device_types = ua.all_ p.message = ua.message( title='Title', body='Body', content_type='text/html', content_encoding='utf8', ) self.assertEqual( p.payload, { 'audience': 'all', 'notification': { 'alert': 'Hey, click yes!', 'interactive': { 'type': 'some_type', 'button_actions': { 'yes': { 'add_tag': 'clicked_yes', 'remove_tag': 'never_clicked_yes', 'open': { 'type': 'url', 'content': 'http://www.urbanairship.com' } }, 'no': { 'add_tag': 'hater' } } } }, 'device_types': 'all', 'message': { 'title': 'Title', 'body': 'Body', 'content_type': 'text/html', 'content_encoding': 'utf8', } } )