Example #1
0
class AddressesTest(unittest.TestCase):
    def setUp(self):
        self.parent = Mock()
        self.resource = Addresses("http://api.twilio.com", ("user", "pass"))

    def test_update(self):
        request = Mock()
        request.return_value = (Mock(), {"sid": "123"})
        self.resource.request = request

        self.resource.update("123", friendly_name="hi")

        uri = "http://api.twilio.com/Addresses/123"
        request.assert_called_with("POST", uri, data={"FriendlyName": "hi"})

    @raises(TwilioException)
    def test_update_rejects_iso_country(self):
        self.resource.update("123", iso_country="CA")

    def test_dependent_phone_numbers(self):
        pn_list = DependentPhoneNumbers(
            'http://api.twilio.com/mock',
            ('user', 'pass'),
        )
        request = Mock()
        request.return_value = (
            Mock(),
            {
                "dependent_phone_numbers": [{
                    "sid": "PN123"
                }],
                "total": 1,
                "page": 0,
                "page_size": 50,
            },
        )
        pn_list.request = request

        result = pn_list.list()
        request.assert_called_with(
            "GET",
            "http://api.twilio.com/mock/DependentPhoneNumbers",
            params={},
        )
        assert_equal(result[0].sid, 'PN123')
class AddressesTest(unittest.TestCase):
    def setUp(self):
        self.parent = Mock()
        self.resource = Addresses("http://api.twilio.com", ("user", "pass"))

    def test_update(self):
        request = Mock()
        request.return_value = (Mock(), {"sid": "123"})
        self.resource.request = request

        self.resource.update("123", friendly_name="hi")

        uri = "http://api.twilio.com/Addresses/123"
        request.assert_called_with("POST", uri, data={"FriendlyName": "hi"})

    @raises(TwilioException)
    def test_update_rejects_iso_country(self):
        self.resource.update("123", iso_country="CA")

    def test_dependent_phone_numbers(self):
        pn_list = DependentPhoneNumbers(
            'http://api.twilio.com/mock',
            ('user', 'pass'),
        )
        request = Mock()
        request.return_value = (
            Mock(),
            {
                "dependent_phone_numbers": [{"sid": "PN123"}],
                "total": 1,
                "page": 0,
                "page_size": 50,
            },
        )
        pn_list.request = request

        result = pn_list.list()
        request.assert_called_with(
            "GET",
            "http://api.twilio.com/mock/DependentPhoneNumbers",
            params={},
        )
        assert_equal(result[0].sid, 'PN123')
Example #3
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)
Example #4
0
 def setUp(self):
     self.parent = Mock()
     self.resource = Addresses("http://api.twilio.com", ("user", "pass"))
 def setUp(self):
     self.parent = Mock()
     self.resource = Addresses("http://api.twilio.com", ("user", "pass"))