Skip to content

Commit f81d183

Browse files
committed
Tidy imports.
- Sort per PEP8. - Remove Python 2.5 workaround. - Move sys.path munging to the 'if __name__ == __main__' stanza.
1 parent 463cb09 commit f81d183

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

tests/test_oauth.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,16 @@
2323
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
THE SOFTWARE.
2525
"""
26-
import sys
27-
import os
28-
import unittest
29-
import oauth2 as oauth
3026
import random
3127
import time
28+
import unittest
3229
import urllib
3330
import urlparse
34-
from types import ListType
35-
import mock
36-
import httplib2
37-
38-
# Fix for python2.5 compatibility
39-
try:
40-
from urlparse import parse_qs, parse_qsl
41-
except ImportError:
42-
from cgi import parse_qs, parse_qsl
4331

32+
import httplib2
33+
import mock
4434

45-
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), ".."),]
35+
import oauth2 as oauth
4636

4737

4838
class TestError(unittest.TestCase):
@@ -136,7 +126,7 @@ def test_basic(self):
136126
self.assertRaises(ValueError, lambda: oauth.Consumer(None, 'dasf'))
137127

138128
def test_str(self):
139-
res = dict(parse_qsl(str(self.consumer)))
129+
res = dict(urlparse.parse_qsl(str(self.consumer)))
140130
self.assertTrue('oauth_consumer_key' in res)
141131
self.assertTrue('oauth_consumer_secret' in res)
142132
self.assertEquals(res['oauth_consumer_key'], self.consumer.key)
@@ -495,7 +485,7 @@ def test_to_postdata(self):
495485
del params['multi']
496486
flat.extend(params.items())
497487
kf = lambda x: x[0]
498-
self.assertEquals(sorted(flat, key=kf), sorted(parse_qsl(req.to_postdata()), key=kf))
488+
self.assertEquals(sorted(flat, key=kf), sorted(urlparse.parse_qsl(req.to_postdata()), key=kf))
499489

500490
def test_to_url(self):
501491
url = "http://sp.example.com/"
@@ -517,8 +507,8 @@ def test_to_url(self):
517507
self.assertEquals(exp.netloc, res.netloc)
518508
self.assertEquals(exp.path, res.path)
519509

520-
a = parse_qs(exp.query)
521-
b = parse_qs(res.query)
510+
a = urlparse.parse_qs(exp.query)
511+
b = urlparse.parse_qs(res.query)
522512
self.assertEquals(a, b)
523513

524514
def test_to_url_with_query(self):
@@ -542,8 +532,8 @@ def test_to_url_with_query(self):
542532
self.assertEquals(exp.netloc, res.netloc)
543533
self.assertEquals(exp.path, res.path)
544534

545-
a = parse_qs(exp.query)
546-
b = parse_qs(res.query)
535+
a = urlparse.parse_qs(exp.query)
536+
b = urlparse.parse_qs(res.query)
547537
self.assertTrue('alt' in b)
548538
self.assertTrue('max-contacts' in b)
549539
self.assertEquals(b['alt'], ['json'])
@@ -591,7 +581,7 @@ def test_signature_base_string_with_query(self):
591581
req = oauth.Request("GET", url, params)
592582
self.assertEquals(req.normalized_url, 'https://www.google.com/m8/feeds/contacts/default/full/')
593583
self.assertEquals(req.url, 'https://www.google.com/m8/feeds/contacts/default/full/?alt=json&max-contacts=10')
594-
normalized_params = parse_qsl(req.get_normalized_parameters())
584+
normalized_params = urlparse.parse_qsl(req.get_normalized_parameters())
595585
self.assertTrue(len(normalized_params), len(params) + 2)
596586
normalized_params = dict(normalized_params)
597587
for key, value in params.iteritems():
@@ -928,7 +918,7 @@ def test_from_request(self):
928918
qs = urllib.urlencode(params)
929919
req = oauth.Request.from_request("GET", url, query_string=qs)
930920

931-
exp = parse_qs(qs, keep_blank_values=False)
921+
exp = urlparse.parse_qs(qs, keep_blank_values=False)
932922
for k, v in exp.iteritems():
933923
exp[k] = urllib.unquote(v[0])
934924

@@ -1282,7 +1272,7 @@ def test_access_token_post(self):
12821272

12831273
self.assertEquals(int(resp['status']), 200)
12841274

1285-
res = dict(parse_qsl(content))
1275+
res = dict(urlparse.parse_qsl(content))
12861276
self.assertTrue('oauth_token' in res)
12871277
self.assertTrue('oauth_token_secret' in res)
12881278

@@ -1350,8 +1340,8 @@ def mockrequest(cl, ur, **kw):
13501340
req = oauth.Request.from_consumer_and_token(self.consumer, None,
13511341
http_method='GET', http_url=uri, parameters={})
13521342
req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), self.consumer, None)
1353-
expected = parse_qsl(urlparse.urlparse(req.to_url()).query)
1354-
actual = parse_qsl(urlparse.urlparse(ur).query)
1343+
expected = urlparse.parse_qsl(urlparse.urlparse(req.to_url()).query)
1344+
actual = urlparse.parse_qsl(urlparse.urlparse(ur).query)
13551345
self.failUnlessEqual(len(expected), len(actual))
13561346
actual = dict(actual)
13571347
for key, value in expected:
@@ -1381,4 +1371,7 @@ def test_multiple_values_for_a_key(self, mockReqConstructor, mockHttpRequest):
13811371
self.failUnless('multi=2' in mockHttpRequest.call_args[1]['body'])
13821372

13831373
if __name__ == "__main__":
1374+
import os
1375+
import sys
1376+
sys.path[0:0] = [os.path.join(os.path.dirname(__file__), ".."),]
13841377
unittest.main()

0 commit comments

Comments
 (0)