Exemplo n.º 1
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_
Exemplo n.º 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',
                }
            })
Exemplo n.º 3
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_
Exemplo n.º 4
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'
                        },
                    },
                }
            })
Exemplo n.º 5
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'},
                    },
                }
            }
        )
Exemplo n.º 6
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'
                 },
             }
         })
Exemplo n.º 7
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'},
             }
         }
     )
Exemplo n.º 8
0
    def test_push_success(self):
        with mock.patch.object(ua.Airship, '_request') as mock_request:
            response = requests.Response()
            response._content = json.dumps({
                'push_ids': ['0492662a-1b52-4343-a1f9-c6b0c72931c0']
            }).encode('utf-8')
            response.status_code = 202
            mock_request.return_value = response

            airship = ua.Airship('key', 'secret')
            push = airship.create_push()
            push.audience = ua.all_
            push.notification = ua.notification(alert='Hello')
            push.options = ua.options(expiry=10080)
            push.device_types = ua.all_
            pr = push.send()
            self.assertEqual(pr.push_ids,
                             ['0492662a-1b52-4343-a1f9-c6b0c72931c0'])
Exemplo n.º 9
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'
                    },
                }
            })
Exemplo n.º 10
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',
                }
            }
        )
Exemplo n.º 11
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'
                },
            }
        })
Exemplo n.º 12
0
    def test_push_success(self):
        with mock.patch.object(ua.Airship, '_request') as mock_request:
            response = requests.Response()
            response._content = json.dumps(
                {
                    'push_ids': [
                        '0492662a-1b52-4343-a1f9-c6b0c72931c0'
                    ]
                }
            ).encode('utf-8')
            response.status_code = 202
            mock_request.return_value = response

            airship = ua.Airship('key', 'secret')
            push = airship.create_push()
            push.audience = ua.all_
            push.notification = ua.notification(alert='Hello')
            push.options = ua.options(expiry=10080)
            push.device_types = ua.all_
            pr = push.send()
            self.assertEqual(
                pr.push_ids,
                ['0492662a-1b52-4343-a1f9-c6b0c72931c0']
            )
Exemplo n.º 13
0
 def test_options_date_expiry(self):
     opt = ua.options(expiry='2015-04-01T12:00:00')
     self.assertEqual(
         opt,
         {'expiry': '2015-04-01T12:00:00'}
     )
Exemplo n.º 14
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',
                }
            })
Exemplo n.º 15
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',
                }
            }
        )
Exemplo n.º 16
0
 def test_options_int_expiry(self):
     opt = ua.options(expiry=10080)
     self.assertEqual(opt, {'expiry': 10080})
Exemplo n.º 17
0
 def test_options_date_expiry(self):
     opt = ua.options(expiry='2015-04-01T12:00:00')
     self.assertEqual(opt, {'expiry': '2015-04-01T12:00:00'})
Exemplo n.º 18
0
 def test_options_int_expiry(self):
     opt = ua.options(expiry=10080)
     self.assertEqual(
         opt,
         {'expiry': 10080}
     )