Merge lp:~dobey/poauth/test-runner into lp:poauth

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 9
Merged at revision: 8
Proposed branch: lp:~dobey/poauth/test-runner
Merge into: lp:poauth
Diff against target: 655 lines (+157/-97)
11 files modified
.bzrignore (+7/-0)
COPYING (+1/-1)
MANIFEST.in (+1/-0)
poauth/client.py (+26/-16)
poauth/oauth.py (+23/-15)
poauth/server.py (+10/-14)
poauth/tests/test_client.py (+2/-1)
poauth/tests/test_oauth.py (+12/-10)
poauth/tests/test_server.py (+40/-38)
run-tests (+31/-0)
setup.py (+4/-2)
To merge this branch: bzr merge lp:~dobey/poauth/test-runner
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
Roberto Alsina (community) code review Approve
Review via email: mp+105874@code.launchpad.net

Commit message

Add a run-tests script to run tests, pep8 and pyflakes
Update the code to work on both python 3.x and 2.x
Update the setup.py to run tests with setup.py test
Run the tests with both python (2.x) and python3

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve (code review)
Revision history for this message
Mike McCracken (mikemc) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

The attempt to merge lp:~dobey/poauth/test-runner into lp:poauth failed. Below is the output from the failed tests.

running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/poauth
copying poauth/__init__.py -> build/lib.linux-x86_64-2.7/poauth
copying poauth/server.py -> build/lib.linux-x86_64-2.7/poauth
copying poauth/client.py -> build/lib.linux-x86_64-2.7/poauth
copying poauth/oauth.py -> build/lib.linux-x86_64-2.7/poauth
creating build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/__init__.py -> build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/test_server.py -> build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/test_oauth.py -> build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/test_client.py -> build/lib.linux-x86_64-2.7/poauth/tests
running test
running egg_info
creating poauth.egg-info
writing poauth.egg-info/PKG-INFO
writing top-level names to poauth.egg-info/top_level.txt
writing dependency_links to poauth.egg-info/dependency_links.txt
writing manifest file 'poauth.egg-info/SOURCES.txt'
reading manifest file 'poauth.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'poauth.egg-info/SOURCES.txt'
running build_ext

+ ./setup.py build test clean
test_authorize_request_token (poauth.tests.test_server.OAuthServerTests)
Test authorizing the request token. ... ok
test_get_access_token (poauth.tests.test_server.OAuthServerTests)
Test getting an access token. ... ok
test_get_request_token (poauth.tests.test_server.OAuthServerTests)
Test the creation of a request token. ... ok
test_authorize_request_token (poauth.tests.test_server.OAuthStorageTests)
Test authorizing a request token. ... ok
test_fetch_access_token (poauth.tests.test_server.OAuthStorageTests)
Test fetching the access token. ... ok
test_fetch_request_token (poauth.tests.test_server.OAuthStorageTests)
Test fetching the request token. ... ok
test_fetch_request_token_compat (poauth.tests.test_server.OAuthStorageTests)
Test fetching the request token. ... ok
test_validate_consumer (poauth.tests.test_server.OAuthStorageTests)
Test consumer validation. ... ok
test_HMACSHA1 (poauth.tests.test_oauth.OAuthSignatureTests)
Test the HMAC-SHA1 signature method. ... ok
test_PLAINTEXT (poauth.tests.test_oauth.OAuthSignatureTests)
Test the PLAINTEXT signature method. ... ok
test_RSASHA1 (poauth.tests.test_oauth.OAuthSignatureTests)
Test the RSA-SHA1 signature method. ... ok
test_from_consumer_and_token (poauth.tests.test_client.OAuthRequestTests)
Test the from_consumer_and_token method. ... ok
test_from_token_and_callback (poauth.tests.test_client.OAuthRequestTests)
Test the from_consumer_and_token method. ... ok
test_parameters (poauth.tests.test_client.OAuthRequestTests)
Tests setting and getting a parameter. ... ok

----------------------------------------------------------------------
Ran 14 tests in 0.006s

OK
+ python3 ./setup.py build test clean
Traceback (most recent call last):
  File "./setup.py", line 27, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

The attempt to merge lp:~dobey/poauth/test-runner into lp:poauth failed. Below is the output from the failed tests.

running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/poauth
copying poauth/__init__.py -> build/lib.linux-x86_64-2.7/poauth
copying poauth/server.py -> build/lib.linux-x86_64-2.7/poauth
copying poauth/client.py -> build/lib.linux-x86_64-2.7/poauth
copying poauth/oauth.py -> build/lib.linux-x86_64-2.7/poauth
creating build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/__init__.py -> build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/test_server.py -> build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/test_oauth.py -> build/lib.linux-x86_64-2.7/poauth/tests
copying poauth/tests/test_client.py -> build/lib.linux-x86_64-2.7/poauth/tests
running test
running egg_info
creating poauth.egg-info
writing poauth.egg-info/PKG-INFO
writing top-level names to poauth.egg-info/top_level.txt
writing dependency_links to poauth.egg-info/dependency_links.txt
writing manifest file 'poauth.egg-info/SOURCES.txt'
reading manifest file 'poauth.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'poauth.egg-info/SOURCES.txt'
running build_ext

+ ./setup.py build test clean
test_authorize_request_token (poauth.tests.test_server.OAuthServerTests)
Test authorizing the request token. ... ok
test_get_access_token (poauth.tests.test_server.OAuthServerTests)
Test getting an access token. ... ok
test_get_request_token (poauth.tests.test_server.OAuthServerTests)
Test the creation of a request token. ... ok
test_authorize_request_token (poauth.tests.test_server.OAuthStorageTests)
Test authorizing a request token. ... ok
test_fetch_access_token (poauth.tests.test_server.OAuthStorageTests)
Test fetching the access token. ... ok
test_fetch_request_token (poauth.tests.test_server.OAuthStorageTests)
Test fetching the request token. ... ok
test_fetch_request_token_compat (poauth.tests.test_server.OAuthStorageTests)
Test fetching the request token. ... ok
test_validate_consumer (poauth.tests.test_server.OAuthStorageTests)
Test consumer validation. ... ok
test_HMACSHA1 (poauth.tests.test_oauth.OAuthSignatureTests)
Test the HMAC-SHA1 signature method. ... ok
test_PLAINTEXT (poauth.tests.test_oauth.OAuthSignatureTests)
Test the PLAINTEXT signature method. ... ok
test_RSASHA1 (poauth.tests.test_oauth.OAuthSignatureTests)
Test the RSA-SHA1 signature method. ... ok
test_from_consumer_and_token (poauth.tests.test_client.OAuthRequestTests)
Test the from_consumer_and_token method. ... ok
test_from_token_and_callback (poauth.tests.test_client.OAuthRequestTests)
Test the from_consumer_and_token method. ... ok
test_parameters (poauth.tests.test_client.OAuthRequestTests)
Tests setting and getting a parameter. ... ok

----------------------------------------------------------------------
Ran 14 tests in 0.007s

OK
+ python3 ./setup.py build test clean
Traceback (most recent call last):
  File "./setup.py", line 27, in <module>
    from setuptools import setup, find_packages
ImportError: No module named setuptools

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2012-05-21 13:12:18 +0000
4@@ -0,0 +1,7 @@
5+__pycache__/
6+build/
7+dist/
8+*.egg-info/
9+
10+MANIFEST
11+
12
13=== modified file 'COPYING'
14--- COPYING 2009-08-28 18:58:58 +0000
15+++ COPYING 2012-05-21 13:12:18 +0000
16@@ -1,7 +1,7 @@
17 The MIT License
18
19 Copyright (c) 2007 Leah Culver
20-Copyright (c) 2009 Canonical, Ltd.
21+Copyright (c) 2009-2012 Canonical, Ltd.
22
23 Permission is hereby granted, free of charge, to any person obtaining a copy
24 of this software and associated documentation files (the "Software"), to deal
25
26=== modified file 'MANIFEST.in'
27--- MANIFEST.in 2009-08-31 14:26:36 +0000
28+++ MANIFEST.in 2012-05-21 13:12:18 +0000
29@@ -1,1 +1,2 @@
30 include COPYING README
31+include run-tests
32
33=== modified file 'poauth/client.py'
34--- poauth/client.py 2009-08-31 18:54:22 +0000
35+++ poauth/client.py 2012-05-21 13:12:18 +0000
36@@ -24,35 +24,46 @@
37 OAuth Client interface
38 '''
39 import random
40-import urllib
41-import urlparse
42+
43+quoteurl = None
44+parseurl = None
45+try:
46+ import urllib.parse
47+ quoteurl = urllib.parse.quote
48+ parseurl = urllib.parse.urlparse
49+except ImportError:
50+ import urllib
51+ import urlparse
52+ quoteurl = urllib.quote
53+ parseurl = urlparse.urlparse
54
55 from warnings import warn
56
57+
58 def escape(s):
59 '''Escape a URL including any /.'''
60- return urllib.quote(s, safe='~')
61+ return quoteurl(s, safe='~')
62+
63
64 def generate_nonce(length=8):
65 '''Generate pseudorandom number.'''
66 return ''.join([str(random.randint(0, 9)) for i in range(length)])
67
68+
69 def _utf8_str(s):
70 """Convert unicode to utf-8."""
71- if isinstance(s, unicode):
72- return s.encode("utf-8")
73- else:
74- return str(s)
75+ return s.encode("utf-8")
76+
77
78 class OAuthRequest(object):
79 '''OAuthRequest represents the request and can be serialized.
80
81 OAuth parameters:
82- - oauth_consumer_key
83+ - oauth_consumer_key
84 - oauth_token
85 - oauth_signature_method
86- - oauth_signature
87- - oauth_timestamp
88+ - oauth_signature
89+ - oauth_timestamp
90 - oauth_nonce
91 - oauth_version
92 ... any additional parameters, as defined by the Service Provider.
93@@ -77,7 +88,7 @@
94 self.parameters['oauth_verifier'] = self.verifier
95 if self.callback:
96 self.parameters['oauth_callback'] = self.callback
97-
98+
99 def set_parameter(self, parameter, value):
100 self.parameters[parameter] = value
101
102@@ -98,7 +109,7 @@
103 pass
104 # Escape key values before sorting.
105 key_values = [(escape(_utf8_str(k)), escape(_utf8_str(v))) \
106- for k,v in params.items()]
107+ for k, v in params.items()]
108 # Sort lexicographically, first after key, then after value.
109 key_values.sort()
110 # Combine key value pairs into a string.
111@@ -110,7 +121,7 @@
112
113 def get_normalized_http_url(self):
114 """Parses the URL and rebuilds it to be scheme://host/path."""
115- parts = urlparse.urlparse(self.http_url)
116+ parts = parseurl(self.http_url)
117 scheme, netloc, path = parts[:3]
118 # Exclude default port numbers.
119 if scheme == 'http' and netloc[-3:] == ':80':
120@@ -135,7 +146,7 @@
121 auth_header = 'OAuth realm="%s"' % realm
122 # Add the oauth parameters.
123 if self.parameters:
124- for k, v in self.parameters.iteritems():
125+ for k, v in self.parameters.items():
126 if k.startswith('oauth_'):
127 auth_header += ', %s="%s"' % (k, escape(str(v)))
128 return {'Authorization': auth_header}
129@@ -143,7 +154,7 @@
130 def to_postdata(self):
131 """Serialize as post data for a POST request."""
132 return '&'.join(['%s=%s' % (escape(str(k)), escape(str(v))) \
133- for k, v in self.parameters.iteritems()])
134+ for k, v in self.parameters.items()])
135
136 def to_url(self):
137 """Serialize as a URL for a GET request."""
138@@ -193,7 +204,6 @@
139 return OAuthRequest(token=token, *args, **newargs)
140
141
142-
143 class OAuthClient(object):
144 '''OAuthClient is a worker to attempt to execute a request.'''
145
146
147=== modified file 'poauth/oauth.py'
148--- poauth/oauth.py 2009-09-24 14:54:57 +0000
149+++ poauth/oauth.py 2012-05-21 13:12:18 +0000
150@@ -1,7 +1,7 @@
151 # The MIT License
152 #
153 # Copyright (c) 2007 Leah Culver
154-# Copyright (c) 2009 Canonical, Ltd.
155+# Copyright (c) 2009-2012 Canonical, Ltd.
156 #
157 # Permission is hereby granted, free of charge, to any person obtaining a copy
158 # of this software and associated documentation files (the "Software"), to deal
159@@ -20,13 +20,18 @@
160 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
161 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
162 # THE SOFTWARE.
163-'''
164-OAuth common interface
165-'''
166+"""OAuth common interface."""
167 import binascii
168 import cgi
169 import hmac
170-import urllib
171+
172+encodeurl = None
173+try:
174+ from urllib.parse import urlencode
175+ encodeurl = urlencode
176+except ImportError:
177+ import urllib
178+ encodeurl = urllib.urlencode
179
180 # For compatibility
181 from poauth import client
182@@ -45,6 +50,7 @@
183 self.key = key
184 self.secret = secret
185
186+
187 class OAuthToken(object):
188 '''
189 OAuthToken is the data type for storing the token in memory.
190@@ -59,9 +65,9 @@
191 '''
192 Returns a form encoded string with the token and secret
193 '''
194- return urllib.urlencode({'oauth_token': self.key,
195- 'oauth_token_secret': self.secret})
196-
197+ return encodeurl({'oauth_token': self.key,
198+ 'oauth_token_secret': self.secret})
199+
200 @staticmethod
201 def from_string(s):
202 '''
203@@ -71,8 +77,8 @@
204 params = cgi.parse_qs(s, keep_blank_values=False)
205 key = params['oauth_token'][0]
206 secret = params['oauth_token_secret'][0]
207- verifier = params.get('oauth_verifier', [None])[0]
208- callback = params.get('oauth_callback', [None])[0]
209+ # verifier = params.get('oauth_verifier', [None])[0]
210+ # callback = params.get('oauth_callback', [None])[0]
211 return OAuthToken(key, secret)
212
213 def __str__(self):
214@@ -86,7 +92,8 @@
215 """-> str."""
216 raise NotImplementedError
217
218- def build_signature_base_string(self, oauth_request, oauth_consumer, oauth_token):
219+ def build_signature_base_string(self, oauth_request,
220+ oauth_consumer, oauth_token):
221 """-> str key, str raw."""
222 raise NotImplementedError
223
224@@ -104,7 +111,7 @@
225
226 def get_name(self):
227 return 'HMAC-SHA1'
228-
229+
230 def build_signature_base_string(self, oauth_request, consumer, token):
231 sig = (
232 escape(oauth_request.get_normalized_http_method()),
233@@ -125,10 +132,11 @@
234
235 # HMAC object.
236 try:
237- import hashlib # 2.5
238- hashed = hmac.new(key, raw, hashlib.sha1)
239+ import hashlib # 2.5
240+ hashed = hmac.new(bytes(key.encode('ascii')),
241+ bytes(raw.encode('ascii')), hashlib.sha1)
242 except:
243- import sha # Deprecated
244+ import sha # Deprecated
245 hashed = hmac.new(key, raw, sha)
246 return hashed.digest()
247
248
249=== modified file 'poauth/server.py'
250--- poauth/server.py 2009-09-02 14:20:00 +0000
251+++ poauth/server.py 2012-05-21 13:12:18 +0000
252@@ -1,7 +1,7 @@
253 # The MIT License
254 #
255 # Copyright (c) 2007 Leah Culver
256-# Copyright (c) 2009 Canonical, Ltd.
257+# Copyright (c) 2009-2012 Canonical, Ltd.
258 #
259 # Permission is hereby granted, free of charge, to any person obtaining a copy
260 # of this software and associated documentation files (the "Software"), to deal
261@@ -20,14 +20,12 @@
262 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
263 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
264 # THE SOFTWARE.
265-'''
266-OAuth Server interface
267-'''
268-import urlparse
269+"""OAuth Server interface."""
270
271 from poauth.client import OAuthRequest
272 from poauth.oauth import OAuthToken, OAUTH_VERSION
273
274+
275 class OAuthResponse(OAuthRequest):
276 '''Class to manage OAuthServer response data.'''
277
278@@ -38,12 +36,12 @@
279 self.realm = kwargs.get('realm', None)
280 self.header = {}
281 if self.status_code != 200:
282- self.header = {'WWW-Authenticate' : 'OAuth realm="%s"' % self.realm}
283+ self.header = {'WWW-Authenticate': 'OAuth realm="%s"' % self.realm}
284
285 self.callback = kwargs.pop('callback', None)
286 if self.callback:
287 self.status_code = 307
288- self.header = {'Location' : self.callback}
289+ self.header = {'Location': self.callback}
290
291 self.parameters = kwargs.get('parameters', {})
292 try:
293@@ -55,7 +53,7 @@
294 def headers(self):
295 '''Return the set of headers to respond with.'''
296 return self.header
297-
298+
299
300 class OAuthServer(object):
301 '''Class for building an OAuth server.'''
302@@ -80,7 +78,7 @@
303 'oauth_timestamp',
304 'oauth_nonce',
305 'oauth_callback']
306- supported_params = ['oauth_version']
307+ # supported_params = ['oauth_version']
308
309 bad_request = OAuthResponse(status=400, message="Bad Request",
310 realm=self.realm)
311@@ -100,7 +98,7 @@
312 response_params['oauth_callback_confirmed'] = 'true'
313 else:
314 try:
315- parts = urlparse.urlparse(callback)
316+ # parts = urlparse.urlparse(callback)
317 response_params['oauth_callback_confirmed'] = 'true'
318 except:
319 return bad_request
320@@ -142,7 +140,7 @@
321 'oauth_timestamp',
322 'oauth_nonce',
323 'oauth_verifier']
324- supported_params = ['oauth_version']
325+ # supported_params = ['oauth_version']
326
327 parameters = request.parameters
328
329@@ -174,9 +172,7 @@
330 def __validate_required_params(self, required_params, parameters):
331 '''Validate that all the required parameters are there.'''
332 for param in required_params:
333- try:
334- exists = parameters[param]
335- except KeyError:
336+ if parameters.get(param, None) is None:
337 return False
338 return True
339
340
341=== modified file 'poauth/tests/test_client.py'
342--- poauth/tests/test_client.py 2009-08-31 18:54:22 +0000
343+++ poauth/tests/test_client.py 2012-05-21 13:12:18 +0000
344@@ -1,7 +1,7 @@
345 #
346 # The MIT License
347 #
348-# Copyright 2009 Canonical Ltd.
349+# Copyright 2009-2012 Canonical Ltd.
350 #
351 # Permission is hereby granted, free of charge, to any person obtaining a copy
352 # of this software and associated documentation files (the "Software"), to deal
353@@ -27,6 +27,7 @@
354 from poauth.oauth import OAuthConsumer, OAuthToken
355 from poauth.client import OAuthRequest
356
357+
358 class OAuthRequestTests(unittest.TestCase):
359 '''Tests for OAuthRequest'''
360
361
362=== modified file 'poauth/tests/test_oauth.py'
363--- poauth/tests/test_oauth.py 2009-09-24 14:54:57 +0000
364+++ poauth/tests/test_oauth.py 2012-05-21 13:12:18 +0000
365@@ -1,7 +1,7 @@
366 #
367 # The MIT License
368 #
369-# Copyright 2009 Canonical Ltd.
370+# Copyright 2009-2012 Canonical Ltd.
371 #
372 # Permission is hereby granted, free of charge, to any person obtaining a copy
373 # of this software and associated documentation files (the "Software"), to deal
374@@ -27,6 +27,7 @@
375 from poauth import oauth
376 from poauth.client import OAuthRequest
377
378+
379 class OAuthSignatureTests(unittest.TestCase):
380 '''Tests for OAuthSignatureMethod'''
381
382@@ -37,15 +38,16 @@
383 http_url='http://example.com/request',
384 consumer=self.consumer,
385 callback='oob')
386+
387 def test_PLAINTEXT(self):
388 '''Test the PLAINTEXT signature method.'''
389 method = oauth.OAuthSignatureMethod_PLAINTEXT()
390- self.assertEquals('PLAINTEXT', method.get_name())
391+ self.assertEqual('PLAINTEXT', method.get_name())
392 self.request.sign_request(method, self.consumer, None)
393- self.assertEquals(self.request.get_parameter('oauth_signature_method'),
394- 'PLAINTEXT')
395+ self.assertEqual(self.request.get_parameter('oauth_signature_method'),
396+ 'PLAINTEXT')
397 signature = self.request.get_parameter('oauth_signature')
398- self.assertEquals('secret&', signature)
399+ self.assertEqual('secret&', signature)
400 self.assertTrue(method.check_signature(self.request,
401 self.consumer, None,
402 signature))
403@@ -53,10 +55,10 @@
404 def test_HMACSHA1(self):
405 '''Test the HMAC-SHA1 signature method.'''
406 method = oauth.OAuthSignatureMethod_HMAC_SHA1()
407- self.assertEquals('HMAC-SHA1', method.get_name())
408+ self.assertEqual('HMAC-SHA1', method.get_name())
409 self.request.sign_request(method, self.consumer, None)
410- self.assertEquals(self.request.get_parameter('oauth_signature_method'),
411- 'HMAC-SHA1')
412+ self.assertEqual(self.request.get_parameter('oauth_signature_method'),
413+ 'HMAC-SHA1')
414 signature = self.request.get_parameter('oauth_signature')
415 self.assertTrue(method.check_signature(self.request,
416 self.consumer, None,
417@@ -64,9 +66,9 @@
418 import binascii
419 digest = method._build_digest(self.request, self.consumer, None)
420
421- self.assertEquals(digest, binascii.a2b_base64(signature))
422+ self.assertEqual(digest, binascii.a2b_base64(signature))
423
424 def test_RSASHA1(self):
425 '''Test the RSA-SHA1 signature method.'''
426 method = oauth.OAuthSignatureMethod_RSA_SHA1()
427- self.assertEquals('RSA-SHA1', method.get_name())
428+ self.assertEqual('RSA-SHA1', method.get_name())
429
430=== modified file 'poauth/tests/test_server.py'
431--- poauth/tests/test_server.py 2009-09-02 14:20:00 +0000
432+++ poauth/tests/test_server.py 2012-05-21 13:12:18 +0000
433@@ -1,7 +1,7 @@
434 #
435 # The MIT License
436 #
437-# Copyright 2009 Canonical Ltd.
438+# Copyright 2009-2012 Canonical Ltd.
439 #
440 # Permission is hereby granted, free of charge, to any person obtaining a copy
441 # of this software and associated documentation files (the "Software"), to deal
442@@ -29,6 +29,7 @@
443 from poauth.client import OAuthRequest
444 from poauth.server import OAuthServer, OAuthStorage, OAuthResponse
445
446+
447 class FakeOAuthStorage(OAuthStorage):
448 '''Fake storage for testing.'''
449
450@@ -57,8 +58,8 @@
451
452 def fetch_request_token(self, parameters):
453 '''Get a request token.'''
454- response_params = {'oauth_token' : self.request_token.key,
455- 'oauth_token_secret' : self.request_token.secret,
456+ response_params = {'oauth_token': self.request_token.key,
457+ 'oauth_token_secret': self.request_token.secret,
458 }
459
460 if parameters['oauth_nonce'] != self.nonce:
461@@ -71,8 +72,8 @@
462
463 def authorize_request_token(self, token, parameters):
464 '''Authorize the token.'''
465- response_params = {'oauth_token' : self.request_token.key,
466- 'oauth_verifier' : self.verifier,
467+ response_params = {'oauth_token': self.request_token.key,
468+ 'oauth_verifier': self.verifier,
469 }
470 if parameters['oauth_token'] == self.request_token.key:
471 return OAuthResponse(status=200, parameters=response_params)
472@@ -80,8 +81,8 @@
473
474 def fetch_access_token(self, token, parameters):
475 '''Fetch the access token.'''
476- response_params = {'oauth_token' : self.access_token.key,
477- 'oauth_token_secret' : self.access_token.secret,
478+ response_params = {'oauth_token': self.access_token.key,
479+ 'oauth_token_secret': self.access_token.secret,
480 }
481 verifier = parameters.get('oauth_verifier', self.verifier)
482 if verifier == self.verifier:
483@@ -104,9 +105,9 @@
484
485 def test_get_request_token(self):
486 '''Test the creation of a request token.'''
487- request_params = {'oauth_timestamp' : str(int(time.time())),
488- 'oauth_nonce' : 'nonce',
489- 'oauth_version' : oauth.OAUTH_VERSION,
490+ request_params = {'oauth_timestamp': str(int(time.time())),
491+ 'oauth_nonce': 'nonce',
492+ 'oauth_version': oauth.OAUTH_VERSION,
493 }
494 request = OAuthRequest(callback="oob", consumer=self.consumer,
495 parameters=request_params)
496@@ -114,9 +115,9 @@
497 request.sign_request(method, self.consumer, None)
498 response = self.server.get_request_token(request)
499 self.assertTrue(isinstance(response, OAuthResponse))
500- self.assertEquals(response.status_code, 200)
501- self.assertEquals(response.parameters['oauth_callback_confirmed'],
502- 'true')
503+ self.assertEqual(response.status_code, 200)
504+ self.assertEqual(response.parameters['oauth_callback_confirmed'],
505+ 'true')
506
507 def test_authorize_request_token(self):
508 '''Test authorizing the request token.'''
509@@ -124,25 +125,26 @@
510 request = OAuthRequest(token=token)
511 response = self.server.authorize_request_token(request)
512 self.assertTrue(isinstance(response, OAuthResponse))
513- self.assertEquals(response.status_code, 200)
514+ self.assertEqual(response.status_code, 200)
515
516 def test_get_access_token(self):
517 '''Test getting an access token.'''
518- request_params = {'oauth_timestamp' : str(int(time.time())),
519- 'oauth_nonce' : 'nonce',
520- 'oauth_version' : oauth.OAUTH_VERSION,
521+ request_params = {'oauth_timestamp': str(int(time.time())),
522+ 'oauth_nonce': 'nonce',
523+ 'oauth_version': oauth.OAUTH_VERSION,
524 }
525 token = oauth.OAuthToken('request_key', 'request_secret',
526 verifier='verifier')
527- request=OAuthRequest(consumer=self.consumer, token=token,
528- parameters=request_params)
529+ request = OAuthRequest(consumer=self.consumer, token=token,
530+ parameters=request_params)
531 method = oauth.OAuthSignatureMethod_PLAINTEXT()
532 request.sign_request(method, self.consumer, token)
533 response = self.server.get_access_token(request)
534 self.assertTrue(isinstance(response, OAuthResponse))
535- self.assertEquals(response.status_code, 200)
536- self.assertEquals(response.token.key, 'access_key')
537- self.assertEquals(response.token.secret, 'access_secret')
538+ self.assertEqual(response.status_code, 200)
539+ self.assertEqual(response.token.key, 'access_key')
540+ self.assertEqual(response.token.secret, 'access_secret')
541+
542
543 class OAuthStorageTests(unittest.TestCase):
544 '''Test the OAuthStorage class.'''
545@@ -155,34 +157,34 @@
546 '''Test consumer validation.'''
547 consumer = self.storage.lookup_consumer('consumer_key')
548 self.assertTrue(isinstance(consumer, oauth.OAuthConsumer))
549- self.assertEquals('consumer_key', consumer.key)
550+ self.assertEqual('consumer_key', consumer.key)
551
552 def test_fetch_request_token(self):
553 '''Test fetching the request token.'''
554- parameters = {'oauth_consumer_key' : 'consumer_key',
555- 'oauth_signature_method' : 'PLAINTEXT',
556- 'oauth_signature' : '',
557- 'oauth_timestamp' : str(int(time.time())),
558- 'oauth_nonce' : 'nonce',
559- 'oauth_version' : oauth.OAUTH_VERSION,
560- 'oauth_callback' : 'oob',
561+ parameters = {'oauth_consumer_key': 'consumer_key',
562+ 'oauth_signature_method': 'PLAINTEXT',
563+ 'oauth_signature': '',
564+ 'oauth_timestamp': str(int(time.time())),
565+ 'oauth_nonce': 'nonce',
566+ 'oauth_version': oauth.OAUTH_VERSION,
567+ 'oauth_callback': 'oob',
568 }
569 response = self.storage.fetch_request_token(parameters)
570 self.assertTrue(isinstance(response, OAuthResponse))
571- self.assertEquals(response.token.key, 'request_key')
572+ self.assertEqual(response.token.key, 'request_key')
573
574 def test_fetch_request_token_compat(self):
575 '''Test fetching the request token.'''
576- parameters = {'oauth_consumer_key' : 'consumer_key',
577- 'oauth_signature_method' : 'PLAINTEXT',
578- 'oauth_signature' : '',
579- 'oauth_timestamp' : str(int(time.time())),
580- 'oauth_nonce' : 'nonce',
581- 'oauth_version' : oauth.OAUTH_VERSION,
582+ parameters = {'oauth_consumer_key': 'consumer_key',
583+ 'oauth_signature_method': 'PLAINTEXT',
584+ 'oauth_signature': '',
585+ 'oauth_timestamp': str(int(time.time())),
586+ 'oauth_nonce': 'nonce',
587+ 'oauth_version': oauth.OAUTH_VERSION,
588 }
589 response = self.storage.fetch_request_token(parameters)
590 self.assertTrue(isinstance(response, OAuthResponse))
591- self.assertEquals(response.token.key, 'request_key')
592+ self.assertEqual(response.token.key, 'request_key')
593
594 def test_authorize_request_token(self):
595 '''Test authorizing a request token.'''
596
597=== added file 'run-tests'
598--- run-tests 1970-01-01 00:00:00 +0000
599+++ run-tests 2012-05-21 13:12:18 +0000
600@@ -0,0 +1,31 @@
601+#!/bin/bash
602+#
603+# Copyright 2010-2012 Canonical Ltd.
604+#
605+# Permission is hereby granted, free of charge, to any person obtaining a copy
606+# of this software and associated documentation files (the "Software"), to deal
607+# in the Software without restriction, including without limitation the rights
608+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
609+# copies of the Software, and to permit persons to whom the Software is
610+# furnished to do so, subject to the following conditions:
611+#
612+# The above copyright notice and this permission notice shall be included in
613+# all copies or substantial portions of the Software.
614+#
615+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
616+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
617+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
618+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
619+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
620+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
621+# THE SOFTWARE.
622+
623+set -e -x
624+
625+# Run the tests with both python (2.x) and python3
626+./setup.py build test clean
627+python3 ./setup.py build test clean
628+
629+# Style checks
630+pyflakes poauth setup.py
631+pep8 --repeat . setup.py
632
633=== modified file 'setup.py'
634--- setup.py 2009-08-31 19:20:49 +0000
635+++ setup.py 2012-05-21 13:12:18 +0000
636@@ -1,9 +1,9 @@
637-#!/usr/bin/env python
638+#!/usr/bin/python
639 #
640 # The MIT License
641 #
642 # Copyright (c) 2007 Leah Culver
643-# Copyright (c) 2009 Canonical, Ltd.
644+# Copyright (c) 2009-2012 Canonical, Ltd.
645 #
646 # Permission is hereby granted, free of charge, to any person obtaining a copy
647 # of this software and associated documentation files (the "Software"), to deal
648@@ -34,5 +34,7 @@
649 license='MIT',
650 author='Rodney Dawes',
651 author_email='rodney.dawes@canonical.com',
652+ download_url='https://launchpad.net/poauth/+download',
653 packages=find_packages(),
654+ test_suite='poauth.tests',
655 )

Subscribers

People subscribed via source and target branches

to all changes: