Skip to content

Commit 974a4c4

Browse files
committed
Updated tests to be < 2.6 compatible.
1 parent 0575c84 commit 974a4c4

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tests/test_oauth.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
import urllib
2929
import urlparse
3030

31+
32+
# Fix for python2.5 compatibility
33+
try:
34+
from urlparse import parse_qs, parse_qsl
35+
except ImportError:
36+
from cgi import parse_qs, parse_qsl
37+
38+
3139
class TestError(unittest.TestCase):
3240
def test_message(self):
3341
try:
@@ -90,7 +98,7 @@ def test_basic(self):
9098
self.assertRaises(ValueError, lambda: oauth.Consumer(None, 'dasf'))
9199

92100
def test_str(self):
93-
res = dict(urlparse.parse_qsl(str(self.consumer)))
101+
res = dict(parse_qsl(str(self.consumer)))
94102
self.assertTrue('oauth_consumer_key' in res)
95103
self.assertTrue('oauth_consumer_secret' in res)
96104
self.assertEquals(res['oauth_consumer_key'], self.consumer.key)
@@ -319,7 +327,7 @@ def test_to_postdata(self):
319327

320328
req = oauth.Request("GET", realm, params)
321329

322-
self.assertEquals(params, dict(urlparse.parse_qsl(req.to_postdata())))
330+
self.assertEquals(params, dict(parse_qsl(req.to_postdata())))
323331

324332
def test_to_url(self):
325333
url = "http://sp.example.com/"
@@ -341,8 +349,8 @@ def test_to_url(self):
341349
self.assertEquals(exp.netloc, res.netloc)
342350
self.assertEquals(exp.path, res.path)
343351

344-
a = urlparse.parse_qs(exp.query)
345-
b = urlparse.parse_qs(res.query)
352+
a = parse_qs(exp.query)
353+
b = parse_qs(res.query)
346354
self.assertEquals(a, b)
347355

348356
def test_get_normalized_parameters(self):
@@ -360,7 +368,7 @@ def test_get_normalized_parameters(self):
360368

361369
req = oauth.Request("GET", url, params)
362370

363-
res = dict(urlparse.parse_qsl(req.get_normalized_parameters()))
371+
res = dict(parse_qsl(req.get_normalized_parameters()))
364372

365373
foo = params.copy()
366374
del foo['oauth_signature']
@@ -428,7 +436,7 @@ def test_from_request(self):
428436
qs = urllib.urlencode(params)
429437
req = oauth.Request.from_request("GET", url, query_string=qs)
430438

431-
exp = urlparse.parse_qs(qs, keep_blank_values=False)
439+
exp = parse_qs(qs, keep_blank_values=False)
432440
for k, v in exp.iteritems():
433441
exp[k] = urllib.unquote(v[0])
434442

@@ -710,7 +718,7 @@ def test_access_token_post(self):
710718

711719
self.assertEquals(int(resp['status']), 200)
712720

713-
res = dict(urlparse.parse_qsl(content))
721+
res = dict(parse_qsl(content))
714722
self.assertTrue('oauth_token_key' in res)
715723
self.assertTrue('oauth_token_secret' in res)
716724

@@ -732,4 +740,3 @@ def test_two_legged_get(self):
732740
"""A test of a two-legged OAuth GET request."""
733741
resp, content = self._two_legged("GET")
734742
self.assertEquals(int(resp['status']), 200)
735-

0 commit comments

Comments
 (0)