Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
send(message: String, recipients: List, senderId: Optional, enqueue: Optional): Send a bulk message to recipients, optionally from senderId (Short Code or Alphanumeric).
sendPremium(message: String, keyword: String, linkId: String, recipients: List, senderId: Optional, retryDurationInHours: Optional): Send a premium SMS
fetchMessages(lastReceivedId: Optional): Fetch your messages
fetchSubscriptions(shortCode: String, keyword: String, lastReceivedId: Optional): Fetch your premium subscription data
createSubscription(shortCode: String, keyword: String, phoneNumber: String, checkoutToken: String): Create a premium subscription
"""
import africastalking
import unittest
from test import USERNAME, API_KEY
africastalking.initialize(USERNAME, API_KEY)
token_service = africastalking.Token
service = africastalking.SMS
class TestSmsService(unittest.TestCase):
def test_send(self):
res = service.send('test_send()', ['+254718769882', '+254718769881'], enqueue=True, sender_id='AT2FA')
recipients = res['SMSMessageData']['Recipients']
assert len(recipients) == 2
assert recipients[0]['status'] == 'Success'
def test_heavy_single_send(self):
count = 100000
phone_numbers = list(map(lambda x: str("+254718" + str(x + count)), range(1, count)))
def on_finish(error, data):
"""
Token
createCheckoutToken(phoneNumber: String): Create a new checkout token for phoneNumber
generateAuthToken(): Generate an auth token to us for authentication instead of the API key.
"""
import africastalking
import unittest
from test import USERNAME, API_KEY
africastalking.initialize(USERNAME, API_KEY)
service = africastalking.Token
class TestTokenService(unittest.TestCase):
def test_create_checkout_token(self):
res = service.create_checkout_token("+254718769882")
assert res['token'] != "None"
def test_generate_auth_token(self):
res = service.generate_auth_token()
assert res['lifetimeInSeconds'] == 3600
if __name__ == '__main__':
unittest.main()