def PersonSendSmsView(request): TWILIO_MAGIC_FROM_NUMBER = "+15005550006" VALID_FROM_NUMBER = TWILIO_MAGIC_FROM_NUMBER VALID_TO_NUMBER = TWILIO_MAGIC_FROM_NUMBER sms = SMSMessage("Body", VALID_FROM_NUMBER, [VALID_TO_NUMBER]) sms.send() send_sms("Body", VALID_FROM_NUMBER, [VALID_TO_NUMBER]) return render(request, 'sms_sent.html')
def test_send_sms(self): with captured_stdout() as stdout: numSent = send_sms("Body", VALID_FROM_NUMBER, [VALID_TO_NUMBER]) self.assertEqual(numSent, 1) self.assertEqual(len(mail.outbox), 0) output = stdout.getvalue() self.assertTrue("Subject: None" in output) self.assertTrue("From: +15005550006" in output) self.assertTrue("To: +15005550006" in output) self.assertTrue("Body" in output)
def send_alert_sms(details): from_number = settings.TWILIO_FROM_NUMBER try: user = details['user'] recipients = (user['phone_number'], ) email = user['email'] except KeyError: logger.error('SMS alert details missing phone number! - %s', details) return try: team = details.get('team_name', 'your team') loc = details.get('location', None) gtime = details.get('gametime', None) ana = 'an' if loc == 'away' else 'a' msg = 'Sports Warning! {team} are playing {ana} {loc} game {gtime}.'.format( team=team, ana=ana, loc=loc, gtime=gtime) except KeyError: logger.error('KeyError in sms alert %s', details) msg = 'Sports Warning! One of your warnings was triggered but we failed. Look out for sports today!' msg += ' - sportswarning.com via {}'.format(email) send_sms(msg, from_number, recipients)
def test_send_sms(self): numSent = send_sms("Body", VALID_FROM_NUMBER, [VALID_TO_NUMBER]) self.assertEqual(numSent, 1) self.assertEqual(len(mail.outbox), 0)
def test_send_sms(self): with self.assertRaises(AssertionError): numSent = send_sms("Body", VALID_FROM_NUMBER, [VALID_TO_NUMBER]) self.assertEqual(numSent, 1) self.assertEqual(len(mail.outbox), 1)
def test_send_sms(self): results = send_sms("Body", VALID_FROM_NUMBER, [VALID_TO_NUMBER]) self.assertEqual(results, [1]) self.assertEqual(len(mail.outbox), 1)
def async_send_single_msg(phone, message): send_sms(message, VALID_FROM_NUMBER, (phone, ))