8000 Make twilio.util.ScopeURI param string have a consistent ordering. · ftobia/twilio-python@15a5069 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 15a5069

Browse files
committed
Make twilio.util.ScopeURI param string have a consistent ordering.
Update tests accordingly. This makes the test suite pass consistently on Python 3.3
1 parent 3133805 commit 15a5069

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tests/test_jwt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_outbound_permissions_params(self):
4646
token.allow_client_outgoing("AP123", foobar=3)
4747
payload = token.payload()
4848

49-
eurl = "scope:client:outgoing?appSid=AP123&appParams=foobar%3D3"
49+
eurl = "scope:client:outgoing?appParams=foobar%3D3&appSid=AP123"
5050
self.assertEquals(payload["scope"], eurl)
5151

5252
def test_events(self):
@@ -62,7 +62,7 @@ def test_events_with_filters(self):
6262
token.allow_event_stream(foobar="hey")
6363
payload = token.payload()
6464

65-
event_uri = "scope:stream:subscribe?path=%2F2010-04-01%2FEvents&params=foobar%3Dhey"
65+
event_uri = "scope:stream:subscribe?params=foobar%3Dhey&path=%2F2010-04-01%2FEvents"
6666
self.assertEquals(payload["scope"], event_uri)
6767

6868
def test_decode(self):
@@ -71,7 +71,7 @@ def test_decode(self):
7171
token.allow_client_incoming("andy")
7272
token.allow_event_stream()
7373

74-
outgoing_uri = "scope:client:outgoing?appSid=AP123&appParams=foobar%3D3&clientName=andy"
74+
outgoing_uri = "scope:client:outgoing?appParams=foobar%3D3&appSid=AP123&clientName=andy"
7575
incoming_uri = "scope:client:incoming?clientName=andy"
7676
event_uri = "scope:stream:subscribe?path=%2F2010-04-01%2FEvents"
7777

twilio/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ def __init__(self, service, privilege, params=None):
138138
self.params = params
139139

140140
def __str__(self):
141-
params = urlencode(self.params) if self.params else None
142-
param_string = "?%s" % params if params else ''
141+
if self.params:
142+
sorted_params = sorted([(k, v) for k, v in self.params.items()])
143+
encoded_params = urlencode(sorted_params)
144+
param_string = '?%s' % encoded_params
145+
else:
146+
param_string = ''
143147
return "scope:%s:%s%s" % (self.service, self.privilege, param_string)

0 commit comments

Comments
 (0)
0