10000 Merge branch 'master' of github.com:twilio/twilio-python · RekindleInc/twilio-python@bba64f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit bba64f2

Browse files
author
Doug Black
committed
Merge branch 'master' of github.com:twilio/twilio-python
2 parents ad5ec46 + 5a2c1e5 commit bba64f2

22 files changed

+215
-59
lines changed

CHANGES.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ twilio-python Changelog
33

44
Here you can see the full list of changes between each twilio-python release.
55

6+
Version 3.6.2
7+
------------
8+
9+
Released on September 24, 2013
10+
11+
- Adds support for HTTP and SOCKS4/5 proxies to the REST client.
12+
13+
14+
Version 3.6.0, 3.6.1
15+
--------------------
16+
17+
Released on September 18, 2013
18+
19+
- Adds support for the new Message and SIP resources to the REST
20+
API client.
21+
- Adds support for the new Message verb to the TwiML generator.
22+
23+
624
Version 3.5.3, 3.5.4
725
--------------------
826

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
# built documents.
5858
#
5959
# The short X.Y version.
60-
version = '3.5'
60+
version = '3.6'
6161
# The full version, including alpha/beta/rc tags.
62-
release = '3.5.4'
62+
release = '3.6.2'
6363

6464
# The language for content autogenerated by Sphinx. Refer to documentation
6565
# for a list of supported languages.

docs/usage/basics.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ directly to the the constructor.
3838
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
3939
4040
41+
Proxies
42+
-------
43+
44+
:class:`TwilioRestClient` supports HTTP and SOCKS4/5 proxies. You can change
45+
the proxy configuration at any time with the :class:`Connection` class:
46+
47+
.. code-block:: python
48+
49+
from twilio.rest.resources import Connection
50+
from twilio.rest.resources.connection import PROXY_TYPE_SOCKS5
51+
52+
Connection.set_proxy_info(
53+
'example.com',
54+
5000,
55+
proxy_type=PROXY_TYPE_SOCKS5,
56+
proxy_user='username',
57+
proxy_pass='password',
58+
)
59+
60+
The :class:`TwilioRestClient` will retrieve and use the current proxy
61+
information for each request.
62+
63+
4164
Listing Resources
4265
-------------------
4366

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
six
22
httplib2
3+
socksipy-branch

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
#
1010
# You need to have the setuptools module installed. Try reading the setuptools
1111
# documentation: http://pypi.python.org/pypi/setuptools
12-
REQUIRES = ["httplib2 >= 0.7", "six", "Werkzeug"]
12+
REQUIRES = ["httplib2 >= 0.7", "six"]
1313

1414
if sys.version_info < (2, 6):
1515
REQUIRES.append('simplejson')
1616
if sys.version_info >= (3,0):
1717
REQUIRES.append('unittest2py3k')
18+
REQUIRES.append('socksipy-branch')
1819
else:
1920
REQUIRES.append('unittest2')
2021

tests/test_base_resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def testListResourceCreateResponse201(self):
105105
self.r.create_instance({})
106106
self.r.request.assert_called_with("POST", "https://api.twilio.com/2010-04-01/Resources", data={})
107107

108+
108109
class testInstanceResourceInit(unittest.TestCase):
109110

110111
def setUp(self):

tests/test_make_request.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
Uses the awesome httpbin.org to validate responses
55
"""
66
import twilio
7-
from nose.tools import raises
8-
from mock import patch, Mock
7+
from nose.tools import assert_equal, raises
8+
from mock import patch, Mock, ANY
99
from twilio import TwilioRestException
1010
from twilio.rest.resources.base import make_request, make_twilio_request
11+
from twilio.rest.resources.connection import Connection
12+
from twilio.rest.resources.connection import PROXY_TYPE_SOCKS5
1113

1214
get_headers = {
1315
"User-Agent": "twilio-python/%s" % (twilio.__version__),
@@ -90,3 +92,24 @@ def test_make_twilio_request_bad_data(mock):
9092
make_twilio_request("POST", url)
9193
mock.assert_called_with("POST", "http://random/url.json",
9294
headers=post_headers)
95+
96+
97+
@patch('twilio.rest.resources.base.Response')
98+
@patch('httplib2.Http')
99+
def test_proxy_info(http_mock, resp_mock):
100+
http = Mock()
101+
http.request.return_value = (Mock(), Mock())
102+
http_mock.return_value = http
103+
Connection.set_proxy_info(
104+
'example.com',
105+
8080,
106+
proxy_type=PROXY_TYPE_SOCKS5,
107+
)
108+
make_request("GET", "http://httpbin.org/get")
109+
http_mock.assert_called_with(timeout=None, ca_certs=ANY, proxy_info=ANY)
110+
http.request.assert_called_with("http://httpbin.org/get", "GET",
111+
body=None, headers=None)
112+
proxy_info = http_mock.call_args[1]['proxy_info']
113+
assert_equal(proxy_info.proxy_host, 'example.com')
114+
assert_equal(proxy_info.proxy_port, 8080)
115+
assert_equal(proxy_info.proxy_type, PROXY_TYPE_SOCKS5)

tests/test_messages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from datetime import date
88
from mock import Mock
9+
from six import u
910
from twilio.rest.resources import Messages
1011

1112
DEFAULT = {
@@ -45,12 +46,12 @@ def test_create(self):
4546
self.resource.create(
4647
from_='+14155551234',
4748
to='+14155556789',
48-
body=u'ahoy hoy',
49+
body=u('ahoy hoy'),
4950
)
5051
self.resource.create_instance.assert_called_with(
5152
{
5253
'from': '+14155551234',
5354
'to': '+14155556789',
54-
'body': u'ahoy hoy',
55+
'body': u('ahoy hoy'),
5556
},
5657
)

tests/test_twiml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class TestEnqueue(TwilioTest):
376376
def setUp(self):
377377
r = Response()
378378
r.enqueue("TestEnqueueAttribute", action="act", method='GET',
379-
wait_url='wait', wait_url_method='POST')
379+
waitUrl='wait', waitUrlMethod='POST')
380380
xml = r.toxml()
381381

382382
#parse twiml XML string with Element Tree and inspect
@@ -388,7 +388,7 @@ def test_conf_text(self):
388388
self.assertEqual(self.conf.text.strip(), "TestEnqueueAttribute")
389389

390390
def test_conf_waiturl(self):
391-
self.assertEqual(self.conf.get('wait_url'), "wait")
391+
self.assertEqual(self.conf.get('waitUrl'), "wait")
392392

393393
def test_conf_method(self):
394394
self.assertEqual(self.conf.get('method'), "GET")
@@ -397,7 +397,7 @@ def test_conf_action(self):
397397
self.assertEqual(self.conf.get('action'), "act")
398398

399399
def test_conf_waitmethod(self):
400-
self.assertEqual(self.conf.get('wait_url_method'), "POST")
400+
self.assertEqual(self.conf.get('waitUrlMethod'), "POST")
401401

402402

403403
class TestDial(TwilioTest):

tests/test_unicode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_unicode_sequence_form_value(resp_mock, mock):
7777
http.request.return_value = (Mock(), Mock())
7878

7979
data = {
80-
"body": [u'å', u'ç'],
80+
"body": [u('\xe5'), u('\xe7')],
8181
}
8282

8383
resources.make_request("POST", "http://www.example.com", data=data)

0 commit comments

Comments
 (0)
0