Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd75a66b

Browse files
jingmingdougblack
authored andcommitted
Remove shipped certs (#376)
* Remove shipped certs* Add tests
1 parentda7a6b2 commitd75a66b

File tree

7 files changed

+68
-3442
lines changed

7 files changed

+68
-3442
lines changed

‎CHANGES.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ twilio-python Changelog
33

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

6+
[2017-08-18] Version 6.6.0
7+
---------------------------
8+
- Add connection pooling. This is enabled by default and will use one Session for all requests
9+
in Client.
10+
- To disable this, you can turn this off when creating your Twilio client.
11+
```python
12+
from twilio.restimport Client
13+
from twilio.http.http_clientimport TwilioHttpClient
14+
15+
client= Client(
16+
username,
17+
password,
18+
http_client=TwilioHttpClient(pool_connections=False)
19+
)
20+
```
21+
622
[2017-08-10] Version 6.5.1
723
---------------------------
824
Fixed PyJWT >= 1.5.1 exception
@@ -17,7 +33,6 @@ Fixed PyJWT >= 1.5.1 exception
1733
- Add`video_codec` enum and`video_codecs` parameter, which can be set to either`VP8` or`H264` during room creation.
1834
- Restrict recordings page size to 100
1935

20-
2136
[2017-07-27] Version 6.5.0
2237
---------------------------
2338
This release adds Beta and Preview products to main artifact.

‎tests/unit/http/test_http_client.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,47 @@ def test_request_with_unicode_response(self):
5050
self.assertEqual('other.twilio.com',self.request_mock.headers['Host'])
5151
self.assertEqual(200,response.status_code)
5252
self.assertEqual('testing-unicode: Ω≈ç√, 💩',response.content)
53+
54+
55+
classTestHttpClientSession(unittest.TestCase):
56+
57+
defsetUp(self):
58+
self.session_patcher=patch('twilio.http.http_client.Session')
59+
self.session_constructor_mock=self.session_patcher.start()
60+
61+
deftearDown(self):
62+
self.session_patcher.stop()
63+
64+
def_setup_session_response(self,value):
65+
session_mock=Mock(wraps=Session())
66+
request_mock=Mock()
67+
68+
session_mock.prepare_request.return_value=request_mock
69+
session_mock.send.return_value=Response(200,value)
70+
self.session_constructor_mock.return_value=session_mock
71+
72+
deftest_session_preserved(self):
73+
self._setup_session_response('response_1')
74+
75+
client=TwilioHttpClient()
76+
response_1=client.request('GET','https://api.twilio.com')
77+
78+
self._setup_session_response('response_2')
79+
response_2=client.request('GET','https://api.twilio.com')
80+
81+
# Used same session, response should be the same
82+
self.assertEqual(response_1.content,'response_1')
83+
self.assertEqual(response_2.content,'response_1')
84+
85+
deftest_session_not_preserved(self):
86+
self._setup_session_response('response_1')
87+
88+
client=TwilioHttpClient(pool_connections=False)
89+
response_1=client.request('GET','https://api.twilio.com')
90+
91+
self._setup_session_response('response_2')
92+
response_2=client.request('GET','https://api.twilio.com')
93+
94+
# Used different session, responses should be different
95+
self.assertEqual(response_1.content,'response_1')
96+
self.assertEqual(response_2.content,'response_2')

‎twilio/conf/cacert.pem‎

Lines changed: 0 additions & 3376 deletions
This file was deleted.

‎twilio/http/__init__.py‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
importos
2-
31
fromtwilio.base.exceptionsimportTwilioException
42

53

6-
defget_cert_file():
7-
""" Get the cert file location or bail """
8-
# XXX - this currently fails test coverage because we don't actually go
9-
# over the network anywhere. Might be good to have a test that stands up a
10-
# local server and authenticates against it.
11-
try:
12-
# Apparently __file__ is not available in all places so wrapping this
13-
# in a try/catch
14-
current_path=os.path.realpath(__file__)
15-
ca_cert_path=os.path.join(current_path,'..','..','conf','cacert.pem')
16-
returnos.path.abspath(ca_cert_path)
17-
exceptException:
18-
# None means use the default system file
19-
returnNone
20-
21-
224
classHttpClient(object):
235
"""
246
An abstract class representing an HTTP client.

‎twilio/http/debug.py‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎twilio/http/http_client.py‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
fromrequestsimportRequest,Session
22

3-
fromtwilio.httpimportHttpClient,get_cert_file
3+
fromtwilio.httpimportHttpClient
44
fromtwilio.http.responseimportResponse
55

66

77
classTwilioHttpClient(HttpClient):
88
"""
99
General purpose HTTP Client for interacting with the Twilio API
1010
"""
11-
def__init__(self,connection_pool=True):
12-
ifconnection_pool:
13-
self.session=Session()
14-
self.session.verify=get_cert_file()
15-
else:
16-
self.session=None
11+
def__init__(self,pool_connections=True):
12+
self.session=Session()ifpool_connectionselseNone
1713

1814
defrequest(self,method,url,params=None,data=None,headers=None,auth=None,timeout=None,
1915
allow_redirects=False):
@@ -33,11 +29,7 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
3329
:return: An http response
3430
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
3531
"""
36-
session=self.session
37-
ifsessionisNone:
38-
session=Session()
39-
session.verify=get_cert_file()
40-
32+
session=self.sessionorSession()
4133
request=Request(method.upper(),url,params=params,data=data,headers=headers,auth=auth)
4234

4335
prepped_request=session.prepare_request(request)

‎twilio/http/validation_client.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fromrequestsimportRequest,Session
44

55
fromtwilio.compatimporturlparse
6-
fromtwilio.httpimportHttpClient,get_cert_file
6+
fromtwilio.httpimportHttpClient
77
fromtwilio.http.responseimportResponse
88
fromtwilio.jwt.validationimportClientValidationJwt
99

@@ -15,7 +15,7 @@
1515
classValidationClient(HttpClient):
1616
__SIGNED_HEADERS= ['authorization','host']
1717

18-
def__init__(self,account_sid,api_key_sid,credential_sid,private_key):
18+
def__init__(self,account_sid,api_key_sid,credential_sid,private_key,pool_connections=True):
1919
"""
2020
Build a ValidationClient which signs requests with private_key and allows Twilio to
2121
validate request has not been tampered with.
@@ -30,6 +30,7 @@ def __init__(self, account_sid, api_key_sid, credential_sid, private_key):
3030
self.credential_sid=credential_sid
3131
self.api_key_sid=api_key_sid
3232
self.private_key=private_key
33+
self.session=Session()ifpool_connectionselseNone
3334

3435
defrequest(self,method,url,params=None,data=None,headers=None,auth=None,timeout=None,
3536
allow_redirects=False):
@@ -49,9 +50,7 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None,
4950
:return: An http response
5051
:rtype: A :class:`Response <twilio.rest.http.response.Response>` object
5152
"""
52-
session=Session()
53-
session.verify=get_cert_file()
54-
53+
session=self.sessionorSession()
5554
request=Request(method.upper(),url,params=params,data=data,headers=headers,auth=auth)
5655
prepared_request=session.prepare_request(request)
5756

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp