Beispiel #1
0
    def test_campaigns_str(self):
        cam = ua.campaigns(categories='bugs')
        self.assertEqual(cam, {'categories': ['bugs']})

        with self.assertRaises(ValueError):
            ua.campaigns(categories='''a_long_string_so_long_its_longer_than_
                                    sixty_four_characters_too_long''')
Beispiel #2
0
    def test_campaigns_list(self):
        cam = ua.campaigns(categories=['bugs', 'worms'])
        self.assertEqual(cam, {'categories': ['bugs', 'worms']})

        with self.assertRaises(ValueError):
            ua.campaigns(categories=[])

        with self.assertRaises(TypeError):
            ua.campaigns({'categories': ['bugs', 'worms']})
    def test_campaigns_str(self):
        cam = ua.campaigns(categories='bugs')
        self.assertEqual(
            cam,
            {'categories': ['bugs']}
        )

        with self.assertRaises(ValueError):
            ua.campaigns(
                categories='''a_long_string_so_long_its_longer_than_
                                    sixty_four_characters_too_long'''
            )
    def test_campaigns_list(self):
        cam = ua.campaigns(categories=['bugs', 'worms'])
        self.assertEqual(
            cam,
            {'categories': ['bugs', 'worms']}
        )

        with self.assertRaises(ValueError):
            ua.campaigns(categories=[])

        with self.assertRaises(TypeError):
            ua.campaigns({'categories': ['bugs', 'worms']})
 def test_email_send(self):
     cas = ua.CreateAndSendPush(
         airship=self.airship,
         channels=self.test_email_objs
     )
     cas.notification = ua.notification(
         email=ua.email(
             message_type='commercial',
             plaintext_body='this is an email',
             reply_to='*****@*****.**',
             sender_address='*****@*****.**',
             sender_name='test sender',
             subject='this is an email'
         )
     )
     cas.device_types = ua.device_types('email')
     cas.campaigns = ua.campaigns(
         categories=['email', 'fun']
     )
     self.assertEqual(
         cas.payload,
         {
             'audience': {
                 'create_and_send': [
                     {
                         'ua_address': '*****@*****.**',
                         'ua_commercial_opted_in': '2018-02-13T11:58:59'
                     },
                     {
                         'ua_address': '*****@*****.**',
                         'ua_commercial_opted_in': '2018-02-13T11:58:59'
                     },
                     {
                         'ua_address': '*****@*****.**',
                         'ua_commercial_opted_in': '2018-02-13T11:58:59'
                     }
                 ]
             },
             'device_types': ['email'],
             'notification': {
                 'email': {
                     'subject': 'this is an email',
                     'plaintext_body': 'this is an email',
                     'message_type': 'commercial',
                     'sender_name': 'test sender',
                     'sender_address': '*****@*****.**',
                     'reply_to': '*****@*****.**'
                 }
             },
             'campaigns': {
                 'categories': ['email', 'fun']
             }
         }
     )
    def setUp(self):
        self.airship = ua.Airship(TEST_KEY, TEST_SECRET)
        self.name = "Experiment Test"
        self.audience = "all"
        self.description = "just testing"
        self.device_types = ["ios", "android"]
        self.campaigns = ua.campaigns(categories=["campaign", "categories"])
        self.operation_id = "d67d4de6-934f-4ebb-aef0-250d89699b6b"
        self.experiment_id = "f0c975e4-c01a-436b-92a0-2a360f87b211"
        self.push_id = "0edb9e6f-2198-4c42-aada-5a49eb03bcbb"

        push_1 = self.airship.create_push()
        push_1.notification = ua.notification(alert="test message 1")

        push_2 = self.airship.create_push()
        push_2.notification = ua.notification(alert="test message 2")

        push_3 = self.airship.create_push()
        push_3.notification = ua.notification(alert="test message 1")
        push_3.in_app = ua.in_app(alert="This part appears in-app!",
                                  display_type="banner")

        push_4 = self.airship.create_push()
        push_4.notification = ua.notification(alert="test message 2")
        push_4.in_app = ua.in_app(alert="This part appears in-app!",
                                  display_type="banner",
                                  expiry="2025-10-14T12:00:00",
                                  display={"position": "top"},
                                  actions={"add_tag": "in-app"}
                                  )

        variant_1 = ua.Variant(push_1,
                               description="A description of the variant",
                               name="Testing")
        variant_2 = ua.Variant(push_2)

        variant_3 = ua.Variant(push_3,
                               description="A description of the variant one",
                               name="Testing",
                               schedule=ua.scheduled_time(
                                   datetime.datetime(2025, 10, 10, 18, 45, 30)),
                               weight=2
                               )
        variant_4 = ua.Variant(push_4,
                               description="A description of the variant two",
                               name="Testing",
                               schedule=ua.scheduled_time(datetime.datetime(
                                   2025, 10, 10,  18, 45, 30)),
                               weight=3
                               )

        self.variants_1 = [variant_1, variant_2]
        self.variants_2 = [variant_3, variant_4]
 def test_scheduled_send(self):
     cas = ua.CreateAndSendPush(
         airship=self.airship,
         channels=self.test_sms_objs
     )
     cas.notification = ua.notification(
         alert='test sms'
     )
     cas.device_types = ua.device_types('sms')
     cas.campaigns = ua.campaigns(
         categories=['sms', 'offers']
     )
     schedule = ua.ScheduledPush(airship=self.airship)
     schedule.name = 'test schedule name'
     schedule.push = cas
     schedule.schedule = ua.scheduled_time(
         datetime.datetime(2025, 10, 8, 12, 15)
         )
     self.assertEqual(
         schedule.payload,
         {
             'schedule': {
                 'scheduled_time': '2025-10-08T12:15:00'
             },
             'name': 'test schedule name',
             'push': {
                 'audience': {
                     'create_and_send': [
                         {
                             'ua_msisdn': '15035556789',
                             'ua_sender': '12345',
                             'ua_opted_in': '2018-02-13T11:58:59'
                         },
                         {
                             'ua_msisdn': '15035556788',
                             'ua_sender': '12345',
                             'ua_opted_in': '2018-02-13T11:58:59'
                         },
                         {
                             'ua_msisdn': '15035556787',
                             'ua_sender': '12345',
                             'ua_opted_in': '2018-02-13T11:58:59'
                         },
                     ]
                 },
                 'notification': {'alert': 'test sms'},
                 'device_types': ['sms'],
                 'campaigns': {
                     'categories': ['sms', 'offers']
                 }
             }
         }
     )
Beispiel #8
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'
                 },
             }
         })
 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_sms_send(self):
     cas = ua.CreateAndSendPush(
         airship=self.airship,
         channels=self.test_sms_objs
     )
     cas.notification = ua.notification(
         alert='test sms'
     )
     cas.device_types = ua.device_types('sms')
     cas.campaigns = ua.campaigns(
         categories=['sms', 'offers']
     )
     self.assertEqual(
         cas.payload,
         {
             'audience': {
                 'create_and_send': [
                     {
                         'ua_msisdn': '15035556789',
                         'ua_sender': '12345',
                         'ua_opted_in': '2018-02-13T11:58:59'
                     },
                     {
                         'ua_msisdn': '15035556788',
                         'ua_sender': '12345',
                         'ua_opted_in': '2018-02-13T11:58:59'
                     },
                     {
                         'ua_msisdn': '15035556787',
                         'ua_sender': '12345',
                         'ua_opted_in': '2018-02-13T11:58:59'
                     },
                 ]
             },
             'notification': {'alert': 'test sms'},
             'device_types': ['sms'],
             'campaigns': {
                 'categories': ['sms', 'offers']
             }
         }
     )
 def test_open_channel_send(self):
     cas = ua.CreateAndSendPush(
         airship=self.airship,
         channels=self.test_open_channel_objs,
     )
     cas.notification = ua.notification(
         alert='test open channel'
     )
     cas.device_types = ua.device_types('open::foo')
     cas.campaigns = ua.campaigns(
         categories=['foo', 'bar', 'baz']
     )
     self.assertEqual(
         cas.payload,
         {
             'audience': {
                 'create_and_send': [
                     {
                         'ua_address': 'bfecbb67-5352-4582-a95d-24e4760a3907'
                     },
                     {
                         'ua_address': 'bfecbb67-5352-4582-a95d-24e4760a3908'
                     },
                     {
                         'ua_address': 'bfecbb67-5352-4582-a95d-24e4760a3909'
                     }
                 ]
             },
             'device_types': ['open::foo'],
             'notification': {
                 'alert': 'test open channel'
             },
             'campaigns': {
                 'categories': ['foo', 'bar', 'baz']
             }
         }
     )