8000 update code · twilio/twilio-python@e5c295a · GitHub
[go: up one dir, main page]

Skip to content

Commit e5c295a

Browse files
committed
update code
1 parent 0d28adf commit e5c295a

File tree

8 files changed

+15
-26
lines changed

8 files changed

+15
-26
lines changed

tests/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,3 @@ def setUp(self):
1515
self.client = Client(username=self.account_sid,
1616
password=self.auth_token,
1717
http_client=self.holodeck)
18-
19-
20-
class MockResponse(Response):
21-
def __init__(self, status, text):
22-
# Here we will convert text (a string type) to a bytes object in
23-
# Python 3 for consistency purposes
24-
# if (six.PY3):
25-
# text = bytes(content, 'utf-8')
26-
self.text = text
27-
super(MockResponse, self).__init__(status, text)

tests/unit/http/test_http_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from requests import Session
1111

1212
from twilio.http.http_client import TwilioHttpClient
13+
from twilio.http.response import Response
1314

1415

1516
class TestHttpClientRequest(unittest.TestCase):
@@ -21,7 +22,7 @@ def setUp(self):
2122
self.request_mock = Mock()
2223

2324
self.session_mock.prepare_request.return_value = self.request_mock
24-
self.session_mock.send.return_value = Mock(status_code=200, content=six.u('testing-unicodeΩ≈ç√'))
25+
self.session_mock.send.return_value = Response(200, 'testing-unicode: Ω≈ç√, 💩')
2526
self.request_mock.headers = {}
2627

2728
session_constructor_mock = self.session_patcher.start()
@@ -48,4 +49,4 @@ def test_request_with_unicode_response(self):
4849

4950
self.assertEqual('other.twilio.com', self.request_mock.headers['Host'])
5051
self.assertEqual(200, response.status_code)
51-
self.assertEqual(six.u('testing-unicodeΩ≈ç√'), response.content)
52+
self.assertEqual('testing-unicode: Ω≈ç√, 💩', response.content)

tests/unit/http/test_validation_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from requests import Session
99

1010
from twilio.http.validation_client import ValidationClient
11-
from tests import MockResponse
11+
from twilio.http.response import Response
1212

1313

1414
class TestValidationClientHelpers(unittest.TestCase):
@@ -79,7 +79,7 @@ def setUp(self):
7979
self.request_mock = Mock()
8080

8181
self.session_mock.prepare_request.return_value = self.request_mock
82-
self.session_mock.send.return_value = MockResponse(200, 'test, omega: Ω, pile of poop: 💩')
82+
self.session_mock.send.return_value = Response(200, 'test, omega: Ω, pile of poop: 💩')
8383
self.validation_token.return_value.to_jwt.return_value = 'test-token'
8484
self.request_mock.headers = {}
8585

twilio/base/version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,8 @@ def create(self, method, uri, params=None, data=None, headers=None, auth=None, t
208208
if response.status_code < 200 or response.status_code >= 300:
209209
raise self.exception(method, uri, response, 'Unable to create record')
210210

211+
print(response)
212+
print(type(response))
213+
print(response.__dict__)
214+
211215
return json.loads(response.text)

twilio/compat.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,3 @@
1717
except ImportError:
1818
# python 3
1919
izip = zip
20-
21-
22-
def string_compat(s):
23-
if isinstance(s, six.binary_type):
24-
if (six.PY2):
25-
# s is `str` in Python 2
26-
return s
27-
elif (six.PY3):
28-
# s is `bytes` in Python 3
29-
return s.decode('utf-8')

twilio/http/http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
8000
3838
timeout=timeout,
3939
)
4040

41-
return Response(int(response.status_code), response.content)
41+
return Response(int(response.status_code), response.text)

twilio/http/response.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ def __init__(self, status_code, text):
88
self.status_code = status_code
99
self.ok = self.status_code < 400
1010

11+
@property
12+
def text(self):
13+
return self.content
14+
1115
def __repr__(self):
1216
return 'HTTP {} {}'.format(self.status_code, self.content)

twilio/http/validation_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from requests import Request, Session
44

5-
from twilio.compat import urlparse, string_compat
5+
from twilio.compat import urlparse
66
from twilio.http import HttpClient, get_cert_file
77
from twilio.http.response import Response
88
from twilio.jwt.validation import ClientValidationJwt

0 commit comments

Comments
 (0)
0