8000 Fix edge build · shgrady/twilio-python@cacebbe · GitHub
[go: up one dir, main page]

Skip to content

Commit cacebbe

Browse files
committed
Fix edge build
1 parent 2751b5d commit cacebbe

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

requirements.txt

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

tests/test_access_token.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import unittest
22

3-
from nose.tools import assert_equal, assert_is_not_none
3+
from nose.tools import assert_equal
44
from twilio.jwt import decode
55
from twilio.access_token import AccessToken
66

77
ACCOUNT_SID = 'AC123'
88
SIGNING_KEY_SID = 'SK123'
99

1010

11+
# python2.6 support
12+
def assert_is_not_none(obj):
13+
assert obj is not None, '%r is None' % obj
14+
15+
1116
class AccessTokenTest(unittest.TestCase):
1217
def _validate_claims(self, payload):
1318
assert_equal(SIGNING_KEY_SID, payload['iss'])
@@ -16,7 +21,7 @@ def _validate_claims(self, payload):
1621
assert_is_not_none(payload['exp'])
1722
assert_equal(payload['nbf'] + 3600, payload['exp'])
1823
assert_is_not_none(payload['jti'])
19-
assert_equal('{}-{}'.format(payload['iss'], payload['nbf']),
24+
assert_equal('{0}-{1}'.format(payload['iss'], payload['nbf']),
2025
payload['jti'])
2126
assert_is_not_none(payload['grants'])
2227

tests/test_keys.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
66
AUTH = (ACCOUNT_SID, "token")
7-
BASE_URL = "https://api.twilio.com/2010-04-01/Accounts/{}".format(ACCOUNT_SID)
7+
BASE_URL = "https://api.twilio.com/2010-04-01/Accounts/{0}".format(ACCOUNT_SID)
88
KEY_SID = "SKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
99

1010
list_resource = Keys(BASE_URL, AUTH)
@@ -15,7 +15,7 @@ def test_get_key(mock):
1515
resp = create_mock_json("tests/resources/keys_instance.json")
1616
mock.return_value = resp
1717

18-
url = BASE_URL + "/Keys/{}".format(KEY_SID)
18+
url = BASE_URL + "/Keys/{0}".format(KEY_SID)
1919
list_resource.get(KEY_SID)
2020

2121
mock.assert_called_with("GET", url, auth=AUTH, use_json_extension=True)
@@ -41,7 +41,7 @@ def test_update_key(mock):
4141
resp = create_mock_json("tests/resources/keys_instance.json")
4242
mock.return_value = resp
4343

44-
url = BASE_URL + "/Keys/{}".format(KEY_SID)
44+
url = BASE_URL + "/Keys/{0}".format(KEY_SID)
4545
list_resource.update(sid=KEY_SID, friendly_name="Fuzzy Lumpkins' SigningKey")
4646
params = {
4747
'FriendlyName': "Fuzzy Lumpkins' SigningKey"
@@ -60,7 +60,7 @@ def test_delete_key(mock):
6060
key = Key(list_resource, KEY_SID)
6161
key.delete()
6262

63-
url = BASE_URL + "/Keys/{}".format(KEY_SID)
63+
url = BASE_URL + "/Keys/{0}".format(KEY_SID)
6464
mock.assert_called_with("DELETE", url)
6565

6666

tests/test_make_request.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ def test_make_request_basic_auth(self, mock_request, mock_response):
9090
})
9191
mock_request.side_effect = [(response, Mock()), (Mock(), Mock())]
9292
make_request('GET', 'http://httpbin.org/get', auth=('AC123', 'AuthToken'))
93+
94+
auth = "{0}:{1}".format('AC123', 'AuthToken')
95+
encoded_auth = auth.encode('utf-8')
96+
b64_auth = base64.b64encode(encoded_auth)
97+
9398
mock_request.assert_called_with(
9499
ANY,
95100
'/get',
96101
'GET',
97102
None,
98103
{
99104
'accept-encoding': 'gzip, deflate',
100-
'authorization': 'Basic {}'.format(
101-
base64.b64encode("{}:{}".format('AC123', 'AuthToken'))
102-
),
105+
'authorization': 'Basic {0}'.format(b64_auth.decode('utf-8')),
103106
'user-agent': ANY,
104107
}
105108
)

twilio/access_token.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
32
import jwt
43

54
ALL = '*'
@@ -34,16 +33,18 @@ def add_grant(self, resource, actions=ALL):
3433
return self
3534

3635
def add_rest_grant(self, uri, actions=ALL):
37-
resource = 'https://api.twilio.com/2010-04-01/Accounts/{}/{}'.format(
36+
resource = 'https://api.twilio.com/2010-04-01/Accounts/{0}/{1}'.format(
3837
self.account_sid,
3938
uri.lstrip('/'),
4039
)
4140
return self.add_grant(resource, actions)
4241

4342
def add_endpoint_grant(self, endpoint, actions=None):
4443
actions = actions or [CLIENT_LISTEN, CLIENT_INVITE]
45-
resource = 'sip:{}@{}.endpoint.twilio.com'.format(endpoint,
46-
self.account_sid)
44+
resource = 'sip:{0}@{1}.endpoint.twilio.com'.format(
45+
endpoint,
46+
self.account_sid
47+
)
4748
return self.add_grant(resource, actions)
4849

4950
def enable_nts(self):
@@ -55,7 +56,7 @@ def to_jwt(self):
5556
"cty": "twilio-sat;v=1"
5657
}
5758
payload = {
58-
"jti": '{}-{}'.format(self.signing_key_sid, now),
59+
"jti": '{0}-{1}'.format(self.signing_key_sid, now),
5960
"iss": self.signing_key_sid,
6061
"sub": self.account_sid,
6162
"nbf": now,
@@ -66,4 +67,4 @@ def to_jwt(self):
6667
return jwt.encode(payload, self.secret, headers=headers)
6768

6869
def __str__(self):
69-
return self.to_jwt()
70+
return self.to_jwt().decode('utf-8')

0 commit comments

Comments
 (0)
0