8000 Merge branch 'master' of github.com:twilio/twilio-python · MC6/twilio-python@6f3adc9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f3adc9

Browse files
committed
Merge branch 'master' of github.com:twilio/twilio-python
2 parents 8f08baa + 7c2400a commit 6f3adc9

File tree

7 files changed

+114
-10
lines changed

7 files changed

+114
-10
lines changed

CHANGES

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

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

6+
Version 3.3.4
7+
-------------
8+
9+
Released on December 16, 2011
10+
11+
- Allow both unicode strings and encoded byte strings in request data
12+
- Add support for SMS and Voice application sids to phone number updating
13+
- Fix documentation error relating to phone number purchasing
14+
- Include doc string information for decorated functions
15+
616
Version 3.3.3
717
-------------
818

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
# The short X.Y version.
5757
version = '3.3'
5858
# The full version, including alpha/beta/rc tags.
59-
release = '3.3.3'
59+
release = '3.3.4'
6060

6161
# The language for content autogenerated by Sphinx. Refer to documentation
6262
# for a list of supported languages.
< 10000 /div>

docs/usage/phone-numbers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ An :class:`Application` encapsulates all necessary URLs for use with phone numbe
9797
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
9898
9999
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
100-
number = client.phone_numbers.update(phone_sid, application="AP123")
100+
number = client.phone_numbers.update(phone_sid, sms_application_sid="AP123")
101101
102102
See :doc:`/usage/applications` for instructions on updating and maintaining Applications.
103103

tests/test_phone_numbers.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,21 @@ def test_application_sid(self):
1818
resource.update_instance = Mock()
1919
resource.update("SID", application_sid="foo")
2020
resource.update_instance.assert_called_with(
21-
"SID", {"ApplicationSid": "foo"})
21+
"SID", {"VoiceApplicationSid": "foo", "SmsApplicationSid": "foo"})
22+
23+
def test_voice_application_sid(self):
24+
resource = PhoneNumbers(self.uri, self.auth)
25+
resource.update_instance = Mock()
26+
resource.update("SID", voice_application_sid="foo")
27+
resource.update_instance.assert_called_with(
28+
"SID", {"VoiceApplicationSid": "foo"})
29+
30+
def test_sms_application_sid(self):
31+
resource = PhoneNumbers(self.uri, self.auth)
32+
resource.update_instance = Mock()
33+
resource.update("SID", sms_application_sid="foo")
34+
resource.update_instance.assert_called_with(
35+
"SID", {"SmsApplicationSid": "foo"})
2236

2337

2438
def test_status_callback_url(self):

tests/test_unicode.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
from mock import patch, Mock
3+
from twilio.rest import resources
4+
5+
@patch("httplib2.Http")
6+
@patch("twilio.rest.resources.Response")
7+
def test_ascii_encode(resp_mock, mock):
8+
http = mock.return_value
9+
http.request.return_value = (Mock(), Mock())
10+
11+
data = {
12+
"body": "HeyHey".encode('utf-8')
13+
}
14+
15+
resources.make_request("GET", "http://www.example.com", data=data)
16+
17+
http.request.assert_called_with("http://www.example.com", "GET",
18+
headers=None, body="body=HeyHey")
19+
20+
21+
@patch("httplib2.Http")
22+
@patch("twilio.rest.resources.Response")
23+
def test_ascii(resp_mock, mock):
24+
http = mock.return_value
25+
http.request.return_value = (Mock(), Mock())
26+
27+
data = {
28+
"body": "HeyHey"
29+
}
30+
31+
resources.make_request("GET", "http://www.example.com", data=data)
32+
33+
http.request.assert_called_with("http://www.example.com", "GET",
34+
headers=None, body="body=HeyHey")
35+
36+
37+
@patch("httplib2.Http")
38+
@patch("twilio.rest.resources.Response")
39+
def test_double_encoding(resp_mock, mock):
40+
http = mock.return_value
41+
http.request.return_value = (Mock(), Mock())
42+
43+
body = u"Chloéñ"
44+
45+
data = {
46+
"body": body.encode('utf-8'),
47+
}
48+
49+
resources.make_request("GET", "http://www.example.com", data=data)
50+
51+
http.request.assert_called_with("http://www.example.com", "GET",
52+
headers=None, body="body=Chlo%C3%A9%C3%B1")
53+
54+
55+
@patch("httplib2.Http")
56+
@patch("twilio.rest.resources.Response")
57+
def test_paging(resp_mock, mock):
58+
http = mock.return_value
59+
http.request.return_value = (Mock(), Mock())
60+
61+
data = {
62+
"body": u"Chloéñ",
63+
}
64+
65+
resources.make_request("GET", "http://www.example.com", data=data)
66+
67+
http.request.assert_called_with("http://www.example.com", "GET",
68+
headers=None, body="body=Chlo%C3%A9%C3%B1")
69+
70+
71+

twilio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version_info__ = ('3', '3', '3')
1+
__version_info__ = ('3', '3', '4')
22
__version__ = '.'.join(__version_info__)
33

44

twilio/rest/resources.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ def inner_func(*args, **kwargs):
9393
if len(res):
9494
kwargs[k] = parse_date(v)
9595
return myfunc(*args, **kwargs)
96+
inner_func.__doc__ = myfunc.__doc__
97+
inner_func.__repr__ = myfunc.__repr__
9698
return inner_func
9799

98100

99101
class Response(object):
100102
"""
101103
Take a httplib2 response and turn it into a requests response
102104
"""
103-
104105
def __init__(self, httplib_resp, content, url):
105106
self.content = content
106107
self.cached = False
@@ -125,7 +126,13 @@ def make_request(method, url,
125126
http.add_credentials(auth[0], auth[1])
126127

127128
if data is not None:
128-
data = urlencode(data)
129+
udata = {}
130+
for k, v in data.iteritems():
131+
try:
132+
udata[k.encode('utf-8')] = unicode(v).encode('utf-8')
133+
except UnicodeDecodeError:
134+
udata[k.encode('utf-8')] = unicode(v, 'utf-8').encode('utf-8')
135+
data = urlencode(udata)
129136

130137
if params is not None:
131138
enc_params = urlencode(params, doseq=True)
@@ -359,6 +366,7 @@ def load_instance(self, data):
359366
instance.load_subresources()
360367
return instance
361368

369+
362370
class AvailablePhoneNumber(InstanceResource):
363371
""" An available phone number resource """
364372

@@ -790,7 +798,6 @@ def load(self, entries):
790798

791799
# Only check if entries has a uri
792800
if "account_sid" in entries:
793-
794801
# Parse the parent's uri to get the scheme and base
795802
uri = re.sub(r'AC(.*)', entries["account_sid"],
796803
self.parent.base_uri)
@@ -810,7 +817,7 @@ def transfer(self, account_sid):
810817

811818
def update(self, **kwargs):
812819
"""
813-
Update this phone number instance
820+
Update this phone number instance.
814821
"""
815822
a = self.parent.update(self.name, **kwargs)
816823
self.load(a.__dict__)
@@ -927,7 +934,8 @@ def update(self, sid, api_version=None, voice_url=None, voice_method=None,
927934
status_callback_method=None, sms_url=None, sms_method=None,
928935
sms_fallback_url=None, sms_fallback_method=None,
929936
voice_caller_id_lookup=None, account_sid=None,
930-
application_sid=None, status_callback=None):
937+
voice_application_sid=None, status_callback=None,
938+
application_sid=None, sms_application_sid=None):
931939
"""
932940
Update this phone number instance
933941
"""
@@ -937,15 +945,16 @@ def update(self, sid, api_version=None, voice_url=None, voice_method=None,
937945
"VoiceMethod": voice_method,
938946
"VoiceFallbackUrl": voice_fallback_url,
939947
"VoiceFallbackMethod": voice_fallback_method,
948+
"VoiceApplicationSid": voice_application_sid or application_sid,
940949
"StatusCallback": status_callback,
941950
"StatusCallbackMethod": status_callback_method,
942951
"SmsUrl": sms_url,
943952
"SmsMethod": sms_method,
944953
"SmsFallbackUrl": sms_fallback_url,
945954
"SmsFallbackMethod": sms_fallback_method,
955+
"SmsApplicationSid": sms_application_sid or application_sid,
946956
"VoiceCallerIdLookup": voice_caller_id_lookup,
947957
"AccountSid": account_sid,
948-
"ApplicationSid": application_sid,
949958
})
950959
return self.update_instance(sid, params)
951960

0 commit comments

Comments
 (0)
0