def test_application_sid(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update_instance = Mock()
     resource.update("SID", application_sid="foo")
     resource.update_instance.assert_called_with(
         "SID", {"voice_application_sid": "foo", "sms_application_sid": "foo"}
     )
class PhoneNumbersTest(unittest.TestCase):
    def setUp(self):
        self.resource = PhoneNumbers("http://api.twilio.com", ("user", "pass"))

    def test_reference(self):
        self.assertEquals(self.resource.available_phone_numbers.phone_numbers,
                          self.resource)

    def test_purchase_status_callback(self):
        request = Mock()
        response = Mock()
        response.status_code = 201
        request.return_value = (response, {"sid": ""})
        self.resource.request = request

        self.resource.purchase(area_code="530",
                               status_callback_url="http://",
                               status_callback_method="POST")

        uri = "http://api.twilio.com/IncomingPhoneNumbers"

        data = {
            "AreaCode": "530",
            "StatusCallback": "http://",
            "StatusCallbackMethod": "POST",
        }

        request.assert_called_with("POST", uri, data=data)
class PhoneNumbersTest(unittest.TestCase):

    def setUp(self):
        self.resource = PhoneNumbers("http://api.twilio.com",
                                     ("user", "pass"))

    def test_reference(self):
        assert_equal(self.resource.available_phone_numbers.phone_numbers,
                     self.resource)

    def test_purchase_status_callback(self):
        request = Mock()
        response = Mock()
        response.status_code = 201
        request.return_value = (response, {"sid": ""})
        self.resource.request = request

        self.resource.purchase(area_code="530", status_callback_url="http://",
                               status_callback_method="POST")

        uri = "http://api.twilio.com/IncomingPhoneNumbers"

        data = {
            "AreaCode": "530",
            "StatusCallback": "http://",
            "StatusCallbackMethod": "POST",
            }

        request.assert_called_with("POST", uri, data=data)
Esempio n. 4
0
 def test_application_sid(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update_instance = Mock()
     resource.update("SID", application_sid="foo")
     resource.update_instance.assert_called_with(
         "SID", {
             "voice_application_sid": "foo",
             "sms_application_sid": "foo"
         })
    def test_purchase_type(self):

        types = {'local': 'Local', 'mobile': 'Mobile', 'tollfree': 'TollFree'}
        for type in ('local', 'mobile', 'tollfree'):
            resource = PhoneNumbers(self.uri, self.auth)
            resource.request = Mock()
            resource.request.return_value = (None, None)
            resource.load_instance = Mock()
            resource.purchase(type=type, phone_number='888')
            resource.request.assert_called_with('POST', self.uri + '/IncomingPhoneNumbers/' + types[type],
                                                data={'PhoneNumber': '888'})
    def test_purchase_type(self):

        types = {"local": "Local", "mobile": "Mobile", "tollfree": "TollFree"}
        for type in ("local", "mobile", "tollfree"):
            resource = PhoneNumbers(self.uri, self.auth)
            resource.request = Mock()
            resource.request.return_value = (None, None)
            resource.load_instance = Mock()
            resource.purchase(type=type, phone_number="888")
            resource.request.assert_called_with(
                "POST", self.uri + "/IncomingPhoneNumbers/" + types[type], data={"PhoneNumber": "888"}
            )
Esempio n. 7
0
    def __init__(self,
                 account=None,
                 token=None,
                 base="https://api.twilio.com",
                 version="2010-04-01",
                 client=None):
        """
        Create a Twilio REST API client.
        """

        # Get account credentials
        if not account or not token:
            account, token = find_credentials()
            if not account or not token:
                raise TwilioException("Could not find account credentials")

        auth = (account, token)
        version_uri = "%s/%s" % (base, version)
        account_uri = "%s/%s/Accounts/%s" % (base, version, account)

        self.accounts = Accounts(version_uri, auth)
        self.applications = Applications(account_uri, auth)
        self.calls = Calls(account_uri, auth)
        self.caller_ids = CallerIds(account_uri, auth)
        self.notifications = Notifications(account_uri, auth)
        self.recordings = Recordings(account_uri, auth)
        self.transcriptions = Transcriptions(account_uri, auth)
        self.sms = Sms(account_uri, auth)
        self.phone_numbers = PhoneNumbers(account_uri, auth)
        self.conferences = Conferences(account_uri, auth)
        self.sandboxes = Sandboxes(account_uri, auth)

        self.auth = auth
        self.account_uri = account_uri
Esempio n. 8
0
    def __init__(self,
                 account=None,
                 token=None,
                 base="https://api.twilio.com",
                 version="2010-04-01",
                 client=None,
                 timeout=UNSET_TIMEOUT):
        """
        Create a Twilio REST API client.
        """

        # Get account credentials
        if not account or not token:
            account, token = find_credentials()
            if not account or not token:
                raise TwilioException("""
Twilio could not find your account credentials. Pass them into the
TwilioRestClient constructor like this:

    client = TwilioRestClient(account='AC38135355602040856210245275870',
                              token='2flnf5tdp7so0lmfdu3d')

Or, add your credentials to your shell environment. From the terminal, run

    echo "export TWILIO_ACCOUNT_SID=AC3813535560204085626521" >> ~/.bashrc
    echo "export TWILIO_AUTH_TOKEN=2flnf5tdp7so0lmfdu3d7wod" >> ~/.bashrc

and be sure to replace the values for the Account SID and auth token with the
values from your Twilio Account at https://www.twilio.com/user/account.
""")

        self.base = base
        auth = (account, token)
        version_uri = "%s/%s" % (base, version)
        account_uri = "%s/%s/Accounts/%s" % (base, version, account)

        self.accounts = Accounts(version_uri, auth, timeout)
        self.applications = Applications(account_uri, auth, timeout)
        self.authorized_connect_apps = AuthorizedConnectApps(
            account_uri, auth, timeout)
        self.calls = Calls(account_uri, auth, timeout)
        self.caller_ids = CallerIds(account_uri, auth, timeout)
        self.connect_apps = ConnectApps(account_uri, auth, timeout)
        self.notifications = Notifications(account_uri, auth, timeout)
        self.recordings = Recordings(account_uri, auth, timeout)
        self.transcriptions = Transcriptions(account_uri, auth, timeout)
        self.sms = Sms(account_uri, auth, timeout)
        self.phone_numbers = PhoneNumbers(account_uri, auth, timeout)
        self.conferences = Conferences(account_uri, auth, timeout)
        self.queues = Queues(account_uri, auth, timeout)
        self.sandboxes = Sandboxes(account_uri, auth, timeout)
        self.usage = Usage(account_uri, auth, timeout)
        self.messages = Messages(account_uri, auth, timeout)
        self.media = MediaList(account_uri, auth, timeout)
        self.sip = Sip(account_uri, auth, timeout)

        self.auth = auth
        self.account_uri = account_uri
        self.timeout = timeout
class IncomingPhoneNumbersTest(unittest.TestCase):
    def setUp(self):
        self.resource = PhoneNumbers("http://api.twilio.com", ("user", "pass"))

    def test_mobile(self):
        request = Mock()
        request.return_value = (Mock(), {"incoming_phone_numbers": []})
        self.resource.request = request
        self.resource.list(type="mobile")

        uri = "http://api.twilio.com/IncomingPhoneNumbers/Mobile"
        request.assert_called_with("GET", uri, params={})

    def test_local(self):
        request = Mock()
        request.return_value = (Mock(), {"incoming_phone_numbers": []})
        self.resource.request = request
        self.resource.list(type="local")

        uri = "http://api.twilio.com/IncomingPhoneNumbers/Local"
        request.assert_called_with("GET", uri, params={})

    def test_toll_free(self):
        request = Mock()
        request.return_value = (Mock(), {"incoming_phone_numbers": []})
        self.resource.request = request
        self.resource.list(type="tollfree")

        uri = "http://api.twilio.com/IncomingPhoneNumbers/TollFree"
        request.assert_called_with("GET", uri, params={})
Esempio n. 10
0
class IncomingPhoneNumbersTest(unittest.TestCase):
    def setUp(self):
        self.resource = PhoneNumbers("http://api.twilio.com", ("user", "pass"))

    def test_mobile(self):
        request = Mock()
        request.return_value = (Mock(), {"incoming_phone_numbers": []})
        self.resource.request = request
        self.resource.list(type='mobile')

        uri = "http://api.twilio.com/IncomingPhoneNumbers/Mobile"
        request.assert_called_with("GET", uri, params={})

    def test_local(self):
        request = Mock()
        request.return_value = (Mock(), {"incoming_phone_numbers": []})
        self.resource.request = request
        self.resource.list(type='local')

        uri = "http://api.twilio.com/IncomingPhoneNumbers/Local"
        request.assert_called_with("GET", uri, params={})

    def test_toll_free(self):
        request = Mock()
        request.return_value = (Mock(), {"incoming_phone_numbers": []})
        self.resource.request = request
        self.resource.list(type='tollfree')

        uri = "http://api.twilio.com/IncomingPhoneNumbers/TollFree"
        request.assert_called_with("GET", uri, params={})
Esempio n. 11
0
    def test_purchase_type(self):

        types = {'local': 'Local', 'mobile': 'Mobile', 'tollfree': 'TollFree'}
        for type in ('local', 'mobile', 'tollfree'):
            resource = PhoneNumbers(self.uri, self.auth)
            resource.request = Mock()
            resource.request.return_value = (None, None)
            resource.load_instance = Mock()
            resource.purchase(type=type, phone_number='888')
            resource.request.assert_called_with(
                'POST',
                self.uri + '/IncomingPhoneNumbers/' + types[type],
                data={'PhoneNumber': '888'})
Esempio n. 12
0
    def __init__(self, account=None, token=None, base="https://api.twilio.com",
                 version="2010-04-01", timeout=UNSET_TIMEOUT,
                 request_account=None):
        """
        Create a Twilio REST API client.
        """
        super(TwilioRestClient, self).__init__(account, token, base, version,
                                               timeout, request_account)

        version_uri = "%s/%s" % (base, version)

        self.accounts = Accounts(version_uri, self.auth, timeout)
        self.applications = Applications(self.account_uri, self.auth, timeout)
        self.authorized_connect_apps = AuthorizedConnectApps(
            self.account_uri,
            self.auth,
            timeout
        )
        self.addresses = Addresses(self.account_uri, self.auth, timeout)
        self.calls = Calls(self.account_uri, self.auth, timeout)
        self.caller_ids = CallerIds(self.account_uri, self.auth, timeout)
        self.connect_apps = ConnectApps(self.account_uri, self.auth, timeout)
        self.notifications = Notifications(self.account_uri, self.auth,
                                           timeout)
        self.recordings = Recordings(self.account_uri, self.auth, timeout)
        self.transcriptions = Transcriptions(self.account_uri, self.auth,
                                             timeout)
        self.sms = Sms(self.account_uri, self.auth, timeout)
        self.phone_numbers = PhoneNumbers(self.account_uri, self.auth, timeout)
        self.conferences = Conferences(self.account_uri, self.auth, timeout)
        self.queues = Queues(self.account_uri, self.auth, timeout)
        self.sandboxes = Sandboxes(self.account_uri, self.auth, timeout)
        self.usage = Usage(self.account_uri, self.auth, timeout)
        self.messages = Messages(self.account_uri, self.auth, timeout)
        self.media = MediaList(self.account_uri, self.auth, timeout)
        self.sip = Sip(self.account_uri, self.auth, timeout)
        self.tokens = Tokens(self.account_uri, self.auth, timeout)
        self.keys = Keys(self.account_uri, self.auth, timeout)
Esempio n. 13
0
 def test_transfer(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update = Mock()
     resource.transfer("SID", "AC123")
     resource.update.assert_called_with("SID", account_sid="AC123")
Esempio n. 14
0
 def test_status_callback_url(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update_instance = Mock()
     resource.update("SID", status_callback="foo")
     resource.update_instance.assert_called_with(
             "SID", {"status_callback": "foo"})
 def test_update_instance_rename_status_callback_url(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update_instance = Mock()
     resource.update("SID", status_callback_url="http://www.example.com")
     resource.update_instance.assert_called_with("SID", {"status_callback": "http://www.example.com"})
 def setUp(self):
     self.resource = PhoneNumbers("http://api.twilio.com", ("user", "pass"))
Esempio n. 17
0
 def test_transfer(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update = Mock()
     resource.transfer("SID", "AC123")
     resource.update.assert_called_with("SID", account_sid="AC123")
Esempio n. 18
0
 def test_status_callback_url(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update_instance = Mock()
     resource.update("SID", status_callback="foo")
     resource.update_instance.assert_called_with("SID",
                                                 {"status_callback": "foo"})
Esempio n. 19
0
 def test_update_instance_rename_status_callback_url(self):
     resource = PhoneNumbers(self.uri, self.auth)
     resource.update_instance = Mock()
     resource.update("SID", status_callback_url="http://www.example.com")
     resource.update_instance.assert_called_with(
         "SID", {"status_callback": "http://www.example.com"})
 def setUp(self):
     self.resource = PhoneNumbers("http://api.twilio.com",
                                  ("user", "pass"))