Exemple #1
0
    def test_email_overrides(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            email=ua.email(message_type='transactional',
                           plaintext_body='hello',
                           reply_to='*****@*****.**',
                           sender_address='*****@*****.**',
                           sender_name='test_name',
                           subject='hi',
                           html_body='<html>so rich!</html>'))
        p.device_types = ua.device_types('email')

        self.assertEqual(
            p.payload, {
                'audience': 'all',
                'device_types': ['email'],
                'notification': {
                    'email': {
                        'message_type': 'transactional',
                        'plaintext_body': 'hello',
                        'reply_to': '*****@*****.**',
                        'sender_address': '*****@*****.**',
                        'sender_name': 'test_name',
                        'subject': 'hi',
                        'html_body': '<html>so rich!</html>'
                    }
                }
            })
Exemple #2
0
    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',
                }
            })
Exemple #3
0
    def test_standard_ios_opts(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            alert='Top level alert',
            ios = ua.ios(
                alert='iOS override alert',
                sound='cat.caf',
            )
        )
        p.device_types = ua.device_types('ios')

        self.assertEqual(
            p.payload,
            {
                'audience': 'all',
                'device_types': ['ios'],
                'notification': {
                    'alert': 'Top level alert',
                    'ios': {
                        'alert': 'iOS override alert',
                        'sound': 'cat.caf'
                    }
                }
            }
        )
    def test_web_push(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            alert='Hello',
            web={
                'title': 'This is a title.',
                'icon': {'url': 'https://example.com/icon.png'},
                'extra': {'attribute': 'id'},
                'time_to_live': 12345,
                'require_interaction': False
            }
        )
        p.device_types = 'web'

        self.assertEqual(
            p.payload,
            {
                'audience': 'all',
                'device_types': 'web',
                'notification': {
                    'alert': 'Hello',
                    'web': {
                        'title': 'This is a title.',
                        'icon': {'url': 'https://example.com/icon.png'},
                        'extra': {'attribute': 'id'},
                        'time_to_live': 12345,
                        'require_interaction': False
                    },
                }
            }
        )
Exemple #5
0
    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",
                    },
                }
            })
Exemple #6
0
 def options(self):
     airship = ua.Airship('key', 'secret')
     push = ua.Push(None)
     push.audience = ua.all_
     push.notification = ua.notification(alert='Hello Expiry')
     push.options = ua.options(expiry='2013-04-01T18:45:0')
     push.device_types = ua.all_
Exemple #7
0
    def test_sms_overrides(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            alert='top level alert',
            sms = ua.sms(
                alert='sms override alert',
                expiry='2018-04-01T12:00:00',
            )
        )
        p.device_types = ua.device_types('sms')

        self.assertEqual(
            p.payload,
            {
                'audience': 'all',
                'device_types': ['sms'],
                'notification': {
                    'alert': 'top level alert',
                    'sms': {
                        'alert': 'sms override alert',
                        'expiry': '2018-04-01T12:00:00'
                    }
                }
            }
        )
Exemple #8
0
    def test_email_missing_override(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(alert='no email to be found!')
        p.device_types = ua.device_types('email')

        with self.assertRaises(ValueError):
            p.send()
Exemple #9
0
    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',
                }
            })
Exemple #10
0
    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_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',
                }
            }
        )
Exemple #12
0
    def test_email_with_device_type_all(self):
        p = ua.Push(None)
        p.audience = ua.all_
        p.notification = ua.notification(
            email=ua.email(message_type='transactional',
                           plaintext_body='hello',
                           reply_to='*****@*****.**',
                           sender_address='*****@*****.**',
                           sender_name='test_name',
                           subject='hi',
                           html_body='<html>so rich!</html>'))
        p.device_types = ua.all_

        with self.assertRaises(ValueError):
            p.send()
Exemple #13
0
 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'
                 },
             }
         })
Exemple #14
0
    def test_web_push_to_channel(self):
        p = ua.Push(None)
        p.audience = ua.channel('7bdf2204-4c1b-4a23-8648-9ea74c6be4a3')
        p.notification = ua.notification(alert='Hello individual')
        p.device_types = 'web'

        self.assertEqual(
            p.payload, {
                'audience': {
                    'channel': '7bdf2204-4c1b-4a23-8648-9ea74c6be4a3'
                },
                'notification': {
                    'alert': 'Hello individual'
                },
                'device_types': 'web'
            })
Exemple #15
0
    def test_sms_push_to_sender(self):
        p = ua.Push(None)
        p.audience = ua.sms_sender('12345')
        p.notification = ua.notification(
            alert='sending sms to all with sender')
        p.device_types = ua.device_types('sms')

        self.assertEqual(
            p.payload, {
                'audience': {
                    'sms_sender': '12345'
                },
                'device_types': ['sms'],
                'notification': {
                    'alert': 'sending sms to all with sender'
                }
            })
    def test_in_app(self):
        self.maxDiff = None

        p = ua.Push(None)
        p.audience = ua.all_
        p.in_app = ua.in_app(
            alert='Alert message',
            display_type='banner',
            display={
                'position': 'top',
                'duration': '500'
            },
            interactive=ua.interactive(
                type='ua_yes_no_foreground',
                button_actions={
                    'yes': ua.actions(open_={
                        'type': 'url',
                        'content': 'https://www.urbanairship.com'
                    })
                }
            )
        )

        self.assertEqual(
            p.in_app,
            {
                'alert': 'Alert message',
                'display_type': 'banner',
                'display': {
                    'position': 'top',
                    'duration': '500'
                },
                'interactive': {
                    'button_actions': {
                        'yes': {
                            'open': {
                                'content': 'https://www.urbanairship.com',
                                'type': 'url'
                            }
                        }
                    },
                    'type': 'ua_yes_no_foreground'
                }
            }
        )
Exemple #17
0
    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'
                    },
                }
            })
Exemple #18
0
    def test_sms_push_to_id(self):
        p = ua.Push(None)
        p.audience = ua.sms_id('01230984567', '12345')
        p.notification = ua.notification(
            alert='send sms to id with sender and msisdn')
        p.device_types = ua.device_types('sms')

        self.assertEqual(
            p.payload, {
                'audience': {
                    'sms_id': {
                        'sender': '12345',
                        'msisdn': '01230984567'
                    }
                },
                'device_types': ['sms'],
                'notification': {
                    'alert': 'send sms to id with sender and msisdn'
                }
            })
Exemple #19
0
    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",
                }
            })
Exemple #20
0
 def test_open_channel_push(self):
     p = ua.Push(None)
     p.audience = ua.all_
     p.notification = ua.notification(
         alert='Hello closed channels',
         open_platform={
             'email': {
                 'alert': 'Hello open channels',
                 'title': 'This is a title.',
                 'summary': 'A longer summary of some content',
                 'media_attachment':
                 'https://example.com/cat_standing_up.jpeg',
                 'extra': {
                     'attribute': 'id'
                 },
                 'interactive': {
                     'type': 'ua_yes_no_foreground',
                     'button_actions': {
                         'yes': {
                             'open': {
                                 'content': 'https://www.urbanairship.com',
                                 'type': 'url'
                             }
                         },
                         'no': {
                             'app_defined': {
                                 'foo': 'bar'
                             }
                         }
                     }
                 }
             }
         })
     p.device_types = 'open::email'
     self.assertDictEqual(
         p.payload, {
             'audience': 'all',
             'device_types': 'open::email',
             'notification': {
                 'alert': 'Hello closed channels',
                 'open::email': {
                     'alert': 'Hello open channels',
                     'title': 'This is a title.',
                     'summary': 'A longer summary of some content',
                     'media_attachment':
                     'https://example.com/cat_standing_up.jpeg',
                     'extra': {
                         'attribute': 'id'
                     },
                     'interactive': {
                         'type': 'ua_yes_no_foreground',
                         'button_actions': {
                             'yes': {
                                 'open': {
                                     'content':
                                     'https://www.urbanairship.com',
                                     'type': 'url'
                                 }
                             },
                             'no': {
                                 'app_defined': {
                                     'foo': 'bar'
                                 }
                             }
                         }
                     }
                 }
             }
         })
Exemple #21
0
    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',
                }
            })