Skip to content

Commit 9833537

Browse files
committed
Add tests for issue #6: oauth2.Request strips query parameters from the URL.
1 parent 283cb5e commit 9833537

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_oauth.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ def test_url(self):
258258
req = oauth.Request(method, url2)
259259
self.assertEquals(req.url, exp2)
260260

261+
def test_url_query(self):
262+
url = "https://www.google.com/m8/feeds/contacts/default/full/?alt=json&max-contacts=10"
263+
method = "GET"
264+
265+
req = oauth.Request(method, url)
266+
self.assertEquals(req.url, url)
267+
261268
def test_get_parameter(self):
262269
url = "http://example.com"
263270
method = "GET"
@@ -363,6 +370,35 @@ def test_to_url(self):
363370
a = parse_qs(exp.query)
364371
b = parse_qs(res.query)
365372
self.assertEquals(a, b)
373+
374+
def test_to_url_with_query(self):
375+
url = "https://www.google.com/m8/feeds/contacts/default/full/?alt=json&max-contacts=10"
376+
377+
params = {
378+
'oauth_version': "1.0",
379+
'oauth_nonce': "4572616e48616d6d65724c61686176",
380+
'oauth_timestamp': "137131200",
381+
'oauth_consumer_key': "0685bd9184jfhq22",
382+
'oauth_signature_method': "HMAC-SHA1",
383+
'oauth_token': "ad180jjd733klru7",
384+
'oauth_signature': "wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
385+
}
386+
387+
req = oauth.Request("GET", url, params)
388+
# Note: the url above already has query parameters, so append new ones with &
389+
exp = urlparse.urlparse("%s&%s" % (url, urllib.urlencode(params)))
390+
res = urlparse.urlparse(req.to_url())
391+
self.assertEquals(exp.scheme, res.scheme)
392+
self.assertEquals(exp.netloc, res.netloc)
393+
self.assertEquals(exp.path, res.path)
394+
395+
a = parse_qs(exp.query)
396+
b = parse_qs(res.query)
397+
self.assertTrue('alt' in b)
398+
self.assertTrue('max-contacts' in b)
399+
self.assertEquals(b['alt'], ['json'])
400+
self.assertEquals(b['max-contacts'], ['10'])
401+
self.assertEquals(a, b)
366402

367403
def test_get_normalized_parameters(self):
368404
url = "http://sp.example.com/"

0 commit comments

Comments
 (0)