def test_sms_lookup(self): sender = '12345' msisdn = '15035556789' with mock.patch.object(ua.Airship, '_request') as mock_request: response = requests.Response() response._content = json.dumps({ "ok": True, "channel": { "channel_id": "84e36d69-873b-4ffe-81cd-e74c9f002057", "device_type": "sms", "installed": True, "push_address": None, "named_user_id": None, "alias": None, "tags": [], "tag_groups": { "ua_channel_type": ["sms"], "ua_sender_id": ["12345"], "ua_opt_in": ["true"] }, "created": "2018-04-27T22:06:21", "opt_in": True, "last_registration": "2018-05-14T19:51:38" } }).encode('utf-8') response.status_code = 200 mock_request.return_value = response airship = ua.Airship(TEST_KEY, TEST_SECRET) sms_obj = ua.Sms(airship, sender=sender, msisdn=msisdn) r = sms_obj.lookup() self.assertTrue(r.ok)
def test_template_fields_not_dict(self): with self.assertRaises(TypeError): ua.Sms( airship=self.airship, sender=self.test_sms_sender, opted_in=self.test_optin_datestring, msisdn='15035551234', template_fields='bad_idea_okay' )
def setUp(self): self.airship = ua.Airship(TEST_KEY, TEST_SECRET) self.test_sms_sender = '12345' self.test_sms_msisdns = ['15035556789', '15035556788', '15035556787'] self.test_open_channel_addresses = [ 'bfecbb67-5352-4582-a95d-24e4760a3907', 'bfecbb67-5352-4582-a95d-24e4760a3908', 'bfecbb67-5352-4582-a95d-24e4760a3909' ] self.test_email_addresses = [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ] self.test_optin_datestring = '2018-02-13T11:58:59' self.template_fields = { 'name': 'bruce', 'event': 'zoom meeting' } self.test_sms_objs = [] self.test_open_channel_objs = [] self.test_email_objs = [] self.template_alert = '{{name}} you are late for your {{event}}' for msisdn in self.test_sms_msisdns: sms_obj = ua.Sms( airship=self.airship, sender=self.test_sms_sender, opted_in=self.test_optin_datestring, msisdn=msisdn, template_fields=self.template_fields) self.test_sms_objs.append(sms_obj) for address in self.test_open_channel_addresses: open_channel_obj = ua.OpenChannel( airship=self.airship, ) open_channel_obj.address = address open_channel_obj.open_platform = 'open::foo' open_channel_obj.template_fields = self.template_fields self.test_open_channel_objs.append(open_channel_obj) for email in self.test_email_addresses: email_obj = ua.Email( airship=self.airship, address=email, commercial_opted_in=self.test_optin_datestring, template_fields=self.template_fields ) self.test_email_objs.append(email_obj)
def test_sms_without_optin(self): no_opt_in_sms = ua.Sms( airship=self.airship, sender=self.test_sms_sender, msisdn=self.test_sms_msisdns[0] ) channels = self.test_sms_objs channels.append(no_opt_in_sms) cas = ua.CreateAndSendPush( self.airship, channels=channels ) cas.device_types = ua.device_types('sms') cas.notification = ua.notification(alert='test sms') with self.assertRaises(ValueError): cas.payload
def test_sms_uninstall(self): sender = '12345' msisdn = '15035556789' with mock.patch.object(ua.Airship, '_request') as mock_request: response = requests.Response() response._content = json.dumps({ 'ok': True, }).encode('utf-8') response.status_code = 202 mock_request.return_value = response airship = ua.Airship(TEST_KEY, TEST_SECRET) sms_obj = ua.Sms(airship, sender=sender, msisdn=msisdn) r = sms_obj.uninstall() self.assertTrue(r.ok)
def test_sms_channel_reg(self): sender = '12345' msisdn = '15035556789' channel_id = None with mock.patch.object(ua.Airship, '_request') as mock_request: response = requests.Response() response._content = json.dumps({ 'ok': True, 'status': 'pending' }).encode('utf-8') response.status_code = 202 mock_request.return_value = response airship = ua.Airship(TEST_KEY, TEST_SECRET) sms_obj = ua.Sms(airship, sender=sender, msisdn=msisdn) sms_obj.register() self.assertEqual(channel_id, sms_obj.channel_id)
def test_sms_channel_reg_with_optin(self): sender = '12345' msisdn = '15035556789' channel_id = '59968b83-4e21-4e4a-85ce-25bb59a93993' opt_in_date = '2018-02-13T11:58:59' with mock.patch.object(ua.Airship, '_request') as mock_request: response = requests.Response() response._content = json.dumps({ 'ok': True, 'channel_id': channel_id }).encode('utf-8') response.status_code = 201 mock_request.return_value = response airship = ua.Airship(TEST_KEY, TEST_SECRET) sms_obj = ua.Sms(airship, sender=sender, msisdn=msisdn) sms_obj.register(opted_in=opt_in_date) self.assertEqual(channel_id, sms_obj.channel_id)
def setUp(self): self.airship = ua.Airship(TEST_KEY, TEST_SECRET) self.test_sms_sender = '12345' self.test_sms_msisdns = ['15035556789', '15035556788', '15035556787'] self.test_open_channel_addresses = [ 'bfecbb67-5352-4582-a95d-24e4760a3907', 'bfecbb67-5352-4582-a95d-24e4760a3908', 'bfecbb67-5352-4582-a95d-24e4760a3909' ] self.test_email_addresses = [ '*****@*****.**', '*****@*****.**', '*****@*****.**' ] self.test_optin_datestring = '2018-02-13T11:58:59' self.test_sms_objs = [] self.test_open_channel_objs = [] self. test_email_objs = [] for msisdn in self.test_sms_msisdns: sms_obj = ua.Sms( airship=self.airship, sender=self.test_sms_sender, opted_in=self.test_optin_datestring, msisdn=msisdn) self.test_sms_objs.append(sms_obj) for address in self.test_open_channel_addresses: open_channel_obj = ua.OpenChannel( airship=self.airship ) open_channel_obj.address = address open_channel_obj.open_platform = 'open::foo' self.test_open_channel_objs.append(open_channel_obj) for email in self.test_email_addresses: email_obj = ua.Email( airship=self.airship, address=email, commercial_opted_in=self.test_optin_datestring ) self.test_email_objs.append(email_obj)