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
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2012-05-21 13:12:18 +0000
@@ -0,0 +1,7 @@
1__pycache__/
2build/
3dist/
4*.egg-info/
5
6MANIFEST
7
08
=== modified file 'COPYING'
--- COPYING 2009-08-28 18:58:58 +0000
+++ COPYING 2012-05-21 13:12:18 +0000
@@ -1,7 +1,7 @@
1The MIT License1The MIT License
22
3Copyright (c) 2007 Leah Culver3Copyright (c) 2007 Leah Culver
4Copyright (c) 2009 Canonical, Ltd.4Copyright (c) 2009-2012 Canonical, Ltd.
55
6Permission is hereby granted, free of charge, to any person obtaining a copy6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal7of this software and associated documentation files (the "Software"), to deal
88
=== modified file 'MANIFEST.in'
--- MANIFEST.in 2009-08-31 14:26:36 +0000
+++ MANIFEST.in 2012-05-21 13:12:18 +0000
@@ -1,1 +1,2 @@
1include COPYING README1include COPYING README
2include run-tests
23
=== modified file 'poauth/client.py'
--- poauth/client.py 2009-08-31 18:54:22 +0000
+++ poauth/client.py 2012-05-21 13:12:18 +0000
@@ -24,35 +24,46 @@
24OAuth Client interface24OAuth Client interface
25'''25'''
26import random26import random
27import urllib27
28import urlparse28quoteurl = None
29parseurl = None
30try:
31 import urllib.parse
32 quoteurl = urllib.parse.quote
33 parseurl = urllib.parse.urlparse
34except ImportError:
35 import urllib
36 import urlparse
37 quoteurl = urllib.quote
38 parseurl = urlparse.urlparse
2939
30from warnings import warn40from warnings import warn
3141
42
32def escape(s):43def escape(s):
33 '''Escape a URL including any /.'''44 '''Escape a URL including any /.'''
34 return urllib.quote(s, safe='~')45 return quoteurl(s, safe='~')
46
3547
36def generate_nonce(length=8):48def generate_nonce(length=8):
37 '''Generate pseudorandom number.'''49 '''Generate pseudorandom number.'''
38 return ''.join([str(random.randint(0, 9)) for i in range(length)])50 return ''.join([str(random.randint(0, 9)) for i in range(length)])
3951
52
40def _utf8_str(s):53def _utf8_str(s):
41 """Convert unicode to utf-8."""54 """Convert unicode to utf-8."""
42 if isinstance(s, unicode):55 return s.encode("utf-8")
43 return s.encode("utf-8")56
44 else:
45 return str(s)
4657
47class OAuthRequest(object):58class OAuthRequest(object):
48 '''OAuthRequest represents the request and can be serialized.59 '''OAuthRequest represents the request and can be serialized.
4960
50 OAuth parameters:61 OAuth parameters:
51 - oauth_consumer_key 62 - oauth_consumer_key
52 - oauth_token63 - oauth_token
53 - oauth_signature_method64 - oauth_signature_method
54 - oauth_signature 65 - oauth_signature
55 - oauth_timestamp 66 - oauth_timestamp
56 - oauth_nonce67 - oauth_nonce
57 - oauth_version68 - oauth_version
58 ... any additional parameters, as defined by the Service Provider.69 ... any additional parameters, as defined by the Service Provider.
@@ -77,7 +88,7 @@
77 self.parameters['oauth_verifier'] = self.verifier88 self.parameters['oauth_verifier'] = self.verifier
78 if self.callback:89 if self.callback:
79 self.parameters['oauth_callback'] = self.callback90 self.parameters['oauth_callback'] = self.callback
80 91
81 def set_parameter(self, parameter, value):92 def set_parameter(self, parameter, value):
82 self.parameters[parameter] = value93 self.parameters[parameter] = value
8394
@@ -98,7 +109,7 @@
98 pass109 pass
99 # Escape key values before sorting.110 # Escape key values before sorting.
100 key_values = [(escape(_utf8_str(k)), escape(_utf8_str(v))) \111 key_values = [(escape(_utf8_str(k)), escape(_utf8_str(v))) \
101 for k,v in params.items()]112 for k, v in params.items()]
102 # Sort lexicographically, first after key, then after value.113 # Sort lexicographically, first after key, then after value.
103 key_values.sort()114 key_values.sort()
104 # Combine key value pairs into a string.115 # Combine key value pairs into a string.
@@ -110,7 +121,7 @@
110121
111 def get_normalized_http_url(self):122 def get_normalized_http_url(self):
112 """Parses the URL and rebuilds it to be scheme://host/path."""123 """Parses the URL and rebuilds it to be scheme://host/path."""
113 parts = urlparse.urlparse(self.http_url)124 parts = parseurl(self.http_url)
114 scheme, netloc, path = parts[:3]125 scheme, netloc, path = parts[:3]
115 # Exclude default port numbers.126 # Exclude default port numbers.
116 if scheme == 'http' and netloc[-3:] == ':80':127 if scheme == 'http' and netloc[-3:] == ':80':
@@ -135,7 +146,7 @@
135 auth_header = 'OAuth realm="%s"' % realm146 auth_header = 'OAuth realm="%s"' % realm
136 # Add the oauth parameters.147 # Add the oauth parameters.
137 if self.parameters:148 if self.parameters:
138 for k, v in self.parameters.iteritems():149 for k, v in self.parameters.items():
139 if k.startswith('oauth_'):150 if k.startswith('oauth_'):
140 auth_header += ', %s="%s"' % (k, escape(str(v)))151 auth_header += ', %s="%s"' % (k, escape(str(v)))
141 return {'Authorization': auth_header}152 return {'Authorization': auth_header}
@@ -143,7 +154,7 @@
143 def to_postdata(self):154 def to_postdata(self):
144 """Serialize as post data for a POST request."""155 """Serialize as post data for a POST request."""
145 return '&'.join(['%s=%s' % (escape(str(k)), escape(str(v))) \156 return '&'.join(['%s=%s' % (escape(str(k)), escape(str(v))) \
146 for k, v in self.parameters.iteritems()])157 for k, v in self.parameters.items()])
147158
148 def to_url(self):159 def to_url(self):
149 """Serialize as a URL for a GET request."""160 """Serialize as a URL for a GET request."""
@@ -193,7 +204,6 @@
193 return OAuthRequest(token=token, *args, **newargs)204 return OAuthRequest(token=token, *args, **newargs)
194205
195206
196
197class OAuthClient(object):207class OAuthClient(object):
198 '''OAuthClient is a worker to attempt to execute a request.'''208 '''OAuthClient is a worker to attempt to execute a request.'''
199209
200210
=== modified file 'poauth/oauth.py'
--- poauth/oauth.py 2009-09-24 14:54:57 +0000
+++ poauth/oauth.py 2012-05-21 13:12:18 +0000
@@ -1,7 +1,7 @@
1# The MIT License1# The MIT License
2#2#
3# Copyright (c) 2007 Leah Culver3# Copyright (c) 2007 Leah Culver
4# Copyright (c) 2009 Canonical, Ltd.4# Copyright (c) 2009-2012 Canonical, Ltd.
5#5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal7# of this software and associated documentation files (the "Software"), to deal
@@ -20,13 +20,18 @@
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.22# THE SOFTWARE.
23'''23"""OAuth common interface."""
24OAuth common interface
25'''
26import binascii24import binascii
27import cgi25import cgi
28import hmac26import hmac
29import urllib27
28encodeurl = None
29try:
30 from urllib.parse import urlencode
31 encodeurl = urlencode
32except ImportError:
33 import urllib
34 encodeurl = urllib.urlencode
3035
31# For compatibility36# For compatibility
32from poauth import client37from poauth import client
@@ -45,6 +50,7 @@
45 self.key = key50 self.key = key
46 self.secret = secret51 self.secret = secret
4752
53
48class OAuthToken(object):54class OAuthToken(object):
49 '''55 '''
50 OAuthToken is the data type for storing the token in memory.56 OAuthToken is the data type for storing the token in memory.
@@ -59,9 +65,9 @@
59 '''65 '''
60 Returns a form encoded string with the token and secret66 Returns a form encoded string with the token and secret
61 '''67 '''
62 return urllib.urlencode({'oauth_token': self.key,68 return encodeurl({'oauth_token': self.key,
63 'oauth_token_secret': self.secret})69 'oauth_token_secret': self.secret})
64 70
65 @staticmethod71 @staticmethod
66 def from_string(s):72 def from_string(s):
67 '''73 '''
@@ -71,8 +77,8 @@
71 params = cgi.parse_qs(s, keep_blank_values=False)77 params = cgi.parse_qs(s, keep_blank_values=False)
72 key = params['oauth_token'][0]78 key = params['oauth_token'][0]
73 secret = params['oauth_token_secret'][0]79 secret = params['oauth_token_secret'][0]
74 verifier = params.get('oauth_verifier', [None])[0]80 # verifier = params.get('oauth_verifier', [None])[0]
75 callback = params.get('oauth_callback', [None])[0]81 # callback = params.get('oauth_callback', [None])[0]
76 return OAuthToken(key, secret)82 return OAuthToken(key, secret)
7783
78 def __str__(self):84 def __str__(self):
@@ -86,7 +92,8 @@
86 """-> str."""92 """-> str."""
87 raise NotImplementedError93 raise NotImplementedError
8894
89 def build_signature_base_string(self, oauth_request, oauth_consumer, oauth_token):95 def build_signature_base_string(self, oauth_request,
96 oauth_consumer, oauth_token):
90 """-> str key, str raw."""97 """-> str key, str raw."""
91 raise NotImplementedError98 raise NotImplementedError
9299
@@ -104,7 +111,7 @@
104111
105 def get_name(self):112 def get_name(self):
106 return 'HMAC-SHA1'113 return 'HMAC-SHA1'
107 114
108 def build_signature_base_string(self, oauth_request, consumer, token):115 def build_signature_base_string(self, oauth_request, consumer, token):
109 sig = (116 sig = (
110 escape(oauth_request.get_normalized_http_method()),117 escape(oauth_request.get_normalized_http_method()),
@@ -125,10 +132,11 @@
125132
126 # HMAC object.133 # HMAC object.
127 try:134 try:
128 import hashlib # 2.5135 import hashlib # 2.5
129 hashed = hmac.new(key, raw, hashlib.sha1)136 hashed = hmac.new(bytes(key.encode('ascii')),
137 bytes(raw.encode('ascii')), hashlib.sha1)
130 except:138 except:
131 import sha # Deprecated139 import sha # Deprecated
132 hashed = hmac.new(key, raw, sha)140 hashed = hmac.new(key, raw, sha)
133 return hashed.digest()141 return hashed.digest()
134142
135143
=== modified file 'poauth/server.py'
--- poauth/server.py 2009-09-02 14:20:00 +0000
+++ poauth/server.py 2012-05-21 13:12:18 +0000
@@ -1,7 +1,7 @@
1# The MIT License1# The MIT License
2#2#
3# Copyright (c) 2007 Leah Culver3# Copyright (c) 2007 Leah Culver
4# Copyright (c) 2009 Canonical, Ltd.4# Copyright (c) 2009-2012 Canonical, Ltd.
5#5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal7# of this software and associated documentation files (the "Software"), to deal
@@ -20,14 +20,12 @@
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.22# THE SOFTWARE.
23'''23"""OAuth Server interface."""
24OAuth Server interface
25'''
26import urlparse
2724
28from poauth.client import OAuthRequest25from poauth.client import OAuthRequest
29from poauth.oauth import OAuthToken, OAUTH_VERSION26from poauth.oauth import OAuthToken, OAUTH_VERSION
3027
28
31class OAuthResponse(OAuthRequest):29class OAuthResponse(OAuthRequest):
32 '''Class to manage OAuthServer response data.'''30 '''Class to manage OAuthServer response data.'''
3331
@@ -38,12 +36,12 @@
38 self.realm = kwargs.get('realm', None)36 self.realm = kwargs.get('realm', None)
39 self.header = {}37 self.header = {}
40 if self.status_code != 200:38 if self.status_code != 200:
41 self.header = {'WWW-Authenticate' : 'OAuth realm="%s"' % self.realm}39 self.header = {'WWW-Authenticate': 'OAuth realm="%s"' % self.realm}
4240
43 self.callback = kwargs.pop('callback', None)41 self.callback = kwargs.pop('callback', None)
44 if self.callback:42 if self.callback:
45 self.status_code = 30743 self.status_code = 307
46 self.header = {'Location' : self.callback}44 self.header = {'Location': self.callback}
4745
48 self.parameters = kwargs.get('parameters', {})46 self.parameters = kwargs.get('parameters', {})
49 try:47 try:
@@ -55,7 +53,7 @@
55 def headers(self):53 def headers(self):
56 '''Return the set of headers to respond with.'''54 '''Return the set of headers to respond with.'''
57 return self.header55 return self.header
58 56
5957
60class OAuthServer(object):58class OAuthServer(object):
61 '''Class for building an OAuth server.'''59 '''Class for building an OAuth server.'''
@@ -80,7 +78,7 @@
80 'oauth_timestamp',78 'oauth_timestamp',
81 'oauth_nonce',79 'oauth_nonce',
82 'oauth_callback']80 'oauth_callback']
83 supported_params = ['oauth_version']81 # supported_params = ['oauth_version']
8482
85 bad_request = OAuthResponse(status=400, message="Bad Request",83 bad_request = OAuthResponse(status=400, message="Bad Request",
86 realm=self.realm)84 realm=self.realm)
@@ -100,7 +98,7 @@
100 response_params['oauth_callback_confirmed'] = 'true'98 response_params['oauth_callback_confirmed'] = 'true'
101 else:99 else:
102 try:100 try:
103 parts = urlparse.urlparse(callback)101 # parts = urlparse.urlparse(callback)
104 response_params['oauth_callback_confirmed'] = 'true'102 response_params['oauth_callback_confirmed'] = 'true'
105 except:103 except:
106 return bad_request104 return bad_request
@@ -142,7 +140,7 @@
142 'oauth_timestamp',140 'oauth_timestamp',
143 'oauth_nonce',141 'oauth_nonce',
144 'oauth_verifier']142 'oauth_verifier']
145 supported_params = ['oauth_version']143 # supported_params = ['oauth_version']
146144
147 parameters = request.parameters145 parameters = request.parameters
148146
@@ -174,9 +172,7 @@
174 def __validate_required_params(self, required_params, parameters):172 def __validate_required_params(self, required_params, parameters):
175 '''Validate that all the required parameters are there.'''173 '''Validate that all the required parameters are there.'''
176 for param in required_params:174 for param in required_params:
177 try:175 if parameters.get(param, None) is None:
178 exists = parameters[param]
179 except KeyError:
180 return False176 return False
181 return True177 return True
182178
183179
=== modified file 'poauth/tests/test_client.py'
--- poauth/tests/test_client.py 2009-08-31 18:54:22 +0000
+++ poauth/tests/test_client.py 2012-05-21 13:12:18 +0000
@@ -1,7 +1,7 @@
1#1#
2# The MIT License2# The MIT License
3#3#
4# Copyright 2009 Canonical Ltd.4# Copyright 2009-2012 Canonical Ltd.
5#5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal7# of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
27from poauth.oauth import OAuthConsumer, OAuthToken27from poauth.oauth import OAuthConsumer, OAuthToken
28from poauth.client import OAuthRequest28from poauth.client import OAuthRequest
2929
30
30class OAuthRequestTests(unittest.TestCase):31class OAuthRequestTests(unittest.TestCase):
31 '''Tests for OAuthRequest'''32 '''Tests for OAuthRequest'''
3233
3334
=== modified file 'poauth/tests/test_oauth.py'
--- poauth/tests/test_oauth.py 2009-09-24 14:54:57 +0000
+++ poauth/tests/test_oauth.py 2012-05-21 13:12:18 +0000
@@ -1,7 +1,7 @@
1#1#
2# The MIT License2# The MIT License
3#3#
4# Copyright 2009 Canonical Ltd.4# Copyright 2009-2012 Canonical Ltd.
5#5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal7# of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
27from poauth import oauth27from poauth import oauth
28from poauth.client import OAuthRequest28from poauth.client import OAuthRequest
2929
30
30class OAuthSignatureTests(unittest.TestCase):31class OAuthSignatureTests(unittest.TestCase):
31 '''Tests for OAuthSignatureMethod'''32 '''Tests for OAuthSignatureMethod'''
3233
@@ -37,15 +38,16 @@
37 http_url='http://example.com/request',38 http_url='http://example.com/request',
38 consumer=self.consumer,39 consumer=self.consumer,
39 callback='oob')40 callback='oob')
41
40 def test_PLAINTEXT(self):42 def test_PLAINTEXT(self):
41 '''Test the PLAINTEXT signature method.'''43 '''Test the PLAINTEXT signature method.'''
42 method = oauth.OAuthSignatureMethod_PLAINTEXT()44 method = oauth.OAuthSignatureMethod_PLAINTEXT()
43 self.assertEquals('PLAINTEXT', method.get_name())45 self.assertEqual('PLAINTEXT', method.get_name())
44 self.request.sign_request(method, self.consumer, None)46 self.request.sign_request(method, self.consumer, None)
45 self.assertEquals(self.request.get_parameter('oauth_signature_method'),47 self.assertEqual(self.request.get_parameter('oauth_signature_method'),
46 'PLAINTEXT')48 'PLAINTEXT')
47 signature = self.request.get_parameter('oauth_signature')49 signature = self.request.get_parameter('oauth_signature')
48 self.assertEquals('secret&', signature)50 self.assertEqual('secret&', signature)
49 self.assertTrue(method.check_signature(self.request,51 self.assertTrue(method.check_signature(self.request,
50 self.consumer, None,52 self.consumer, None,
51 signature))53 signature))
@@ -53,10 +55,10 @@
53 def test_HMACSHA1(self):55 def test_HMACSHA1(self):
54 '''Test the HMAC-SHA1 signature method.'''56 '''Test the HMAC-SHA1 signature method.'''
55 method = oauth.OAuthSignatureMethod_HMAC_SHA1()57 method = oauth.OAuthSignatureMethod_HMAC_SHA1()
56 self.assertEquals('HMAC-SHA1', method.get_name())58 self.assertEqual('HMAC-SHA1', method.get_name())
57 self.request.sign_request(method, self.consumer, None)59 self.request.sign_request(method, self.consumer, None)
58 self.assertEquals(self.request.get_parameter('oauth_signature_method'),60 self.assertEqual(self.request.get_parameter('oauth_signature_method'),
59 'HMAC-SHA1')61 'HMAC-SHA1')
60 signature = self.request.get_parameter('oauth_signature')62 signature = self.request.get_parameter('oauth_signature')
61 self.assertTrue(method.check_signature(self.request,63 self.assertTrue(method.check_signature(self.request,
62 self.consumer, None,64 self.consumer, None,
@@ -64,9 +66,9 @@
64 import binascii66 import binascii
65 digest = method._build_digest(self.request, self.consumer, None)67 digest = method._build_digest(self.request, self.consumer, None)
6668
67 self.assertEquals(digest, binascii.a2b_base64(signature))69 self.assertEqual(digest, binascii.a2b_base64(signature))
6870
69 def test_RSASHA1(self):71 def test_RSASHA1(self):
70 '''Test the RSA-SHA1 signature method.'''72 '''Test the RSA-SHA1 signature method.'''
71 method = oauth.OAuthSignatureMethod_RSA_SHA1()73 method = oauth.OAuthSignatureMethod_RSA_SHA1()
72 self.assertEquals('RSA-SHA1', method.get_name())74 self.assertEqual('RSA-SHA1', method.get_name())
7375
=== modified file 'poauth/tests/test_server.py'
--- poauth/tests/test_server.py 2009-09-02 14:20:00 +0000
+++ poauth/tests/test_server.py 2012-05-21 13:12:18 +0000
@@ -1,7 +1,7 @@
1#1#
2# The MIT License2# The MIT License
3#3#
4# Copyright 2009 Canonical Ltd.4# Copyright 2009-2012 Canonical Ltd.
5#5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal7# of this software and associated documentation files (the "Software"), to deal
@@ -29,6 +29,7 @@
29from poauth.client import OAuthRequest29from poauth.client import OAuthRequest
30from poauth.server import OAuthServer, OAuthStorage, OAuthResponse30from poauth.server import OAuthServer, OAuthStorage, OAuthResponse
3131
32
32class FakeOAuthStorage(OAuthStorage):33class FakeOAuthStorage(OAuthStorage):
33 '''Fake storage for testing.'''34 '''Fake storage for testing.'''
3435
@@ -57,8 +58,8 @@
5758
58 def fetch_request_token(self, parameters):59 def fetch_request_token(self, parameters):
59 '''Get a request token.'''60 '''Get a request token.'''
60 response_params = {'oauth_token' : self.request_token.key,61 response_params = {'oauth_token': self.request_token.key,
61 'oauth_token_secret' : self.request_token.secret,62 'oauth_token_secret': self.request_token.secret,
62 }63 }
6364
64 if parameters['oauth_nonce'] != self.nonce:65 if parameters['oauth_nonce'] != self.nonce:
@@ -71,8 +72,8 @@
7172
72 def authorize_request_token(self, token, parameters):73 def authorize_request_token(self, token, parameters):
73 '''Authorize the token.'''74 '''Authorize the token.'''
74 response_params = {'oauth_token' : self.request_token.key,75 response_params = {'oauth_token': self.request_token.key,
75 'oauth_verifier' : self.verifier,76 'oauth_verifier': self.verifier,
76 }77 }
77 if parameters['oauth_token'] == self.request_token.key:78 if parameters['oauth_token'] == self.request_token.key:
78 return OAuthResponse(status=200, parameters=response_params)79 return OAuthResponse(status=200, parameters=response_params)
@@ -80,8 +81,8 @@
8081
81 def fetch_access_token(self, token, parameters):82 def fetch_access_token(self, token, parameters):
82 '''Fetch the access token.'''83 '''Fetch the access token.'''
83 response_params = {'oauth_token' : self.access_token.key,84 response_params = {'oauth_token': self.access_token.key,
84 'oauth_token_secret' : self.access_token.secret,85 'oauth_token_secret': self.access_token.secret,
85 }86 }
86 verifier = parameters.get('oauth_verifier', self.verifier)87 verifier = parameters.get('oauth_verifier', self.verifier)
87 if verifier == self.verifier:88 if verifier == self.verifier:
@@ -104,9 +105,9 @@
104105
105 def test_get_request_token(self):106 def test_get_request_token(self):
106 '''Test the creation of a request token.'''107 '''Test the creation of a request token.'''
107 request_params = {'oauth_timestamp' : str(int(time.time())),108 request_params = {'oauth_timestamp': str(int(time.time())),
108 'oauth_nonce' : 'nonce',109 'oauth_nonce': 'nonce',
109 'oauth_version' : oauth.OAUTH_VERSION,110 'oauth_version': oauth.OAUTH_VERSION,
110 }111 }
111 request = OAuthRequest(callback="oob", consumer=self.consumer,112 request = OAuthRequest(callback="oob", consumer=self.consumer,
112 parameters=request_params)113 parameters=request_params)
@@ -114,9 +115,9 @@
114 request.sign_request(method, self.consumer, None)115 request.sign_request(method, self.consumer, None)
115 response = self.server.get_request_token(request)116 response = self.server.get_request_token(request)
116 self.assertTrue(isinstance(response, OAuthResponse))117 self.assertTrue(isinstance(response, OAuthResponse))
117 self.assertEquals(response.status_code, 200)118 self.assertEqual(response.status_code, 200)
118 self.assertEquals(response.parameters['oauth_callback_confirmed'],119 self.assertEqual(response.parameters['oauth_callback_confirmed'],
119 'true')120 'true')
120121
121 def test_authorize_request_token(self):122 def test_authorize_request_token(self):
122 '''Test authorizing the request token.'''123 '''Test authorizing the request token.'''
@@ -124,25 +125,26 @@
124 request = OAuthRequest(token=token)125 request = OAuthRequest(token=token)
125 response = self.server.authorize_request_token(request)126 response = self.server.authorize_request_token(request)
126 self.assertTrue(isinstance(response, OAuthResponse))127 self.assertTrue(isinstance(response, OAuthResponse))
127 self.assertEquals(response.status_code, 200)128 self.assertEqual(response.status_code, 200)
128129
129 def test_get_access_token(self):130 def test_get_access_token(self):
130 '''Test getting an access token.'''131 '''Test getting an access token.'''
131 request_params = {'oauth_timestamp' : str(int(time.time())),132 request_params = {'oauth_timestamp': str(int(time.time())),
132 'oauth_nonce' : 'nonce',133 'oauth_nonce': 'nonce',
133 'oauth_version' : oauth.OAUTH_VERSION,134 'oauth_version': oauth.OAUTH_VERSION,
134 }135 }
135 token = oauth.OAuthToken('request_key', 'request_secret',136 token = oauth.OAuthToken('request_key', 'request_secret',
136 verifier='verifier')137 verifier='verifier')
137 request=OAuthRequest(consumer=self.consumer, token=token,138 request = OAuthRequest(consumer=self.consumer, token=token,
138 parameters=request_params)139 parameters=request_params)
139 method = oauth.OAuthSignatureMethod_PLAINTEXT()140 method = oauth.OAuthSignatureMethod_PLAINTEXT()
140 request.sign_request(method, self.consumer, token)141 request.sign_request(method, self.consumer, token)
141 response = self.server.get_access_token(request)142 response = self.server.get_access_token(request)
142 self.assertTrue(isinstance(response, OAuthResponse))143 self.assertTrue(isinstance(response, OAuthResponse))
143 self.assertEquals(response.status_code, 200)144 self.assertEqual(response.status_code, 200)
144 self.assertEquals(response.token.key, 'access_key')145 self.assertEqual(response.token.key, 'access_key')
145 self.assertEquals(response.token.secret, 'access_secret')146 self.assertEqual(response.token.secret, 'access_secret')
147
146148
147class OAuthStorageTests(unittest.TestCase):149class OAuthStorageTests(unittest.TestCase):
148 '''Test the OAuthStorage class.'''150 '''Test the OAuthStorage class.'''
@@ -155,34 +157,34 @@
155 '''Test consumer validation.'''157 '''Test consumer validation.'''
156 consumer = self.storage.lookup_consumer('consumer_key')158 consumer = self.storage.lookup_consumer('consumer_key')
157 self.assertTrue(isinstance(consumer, oauth.OAuthConsumer))159 self.assertTrue(isinstance(consumer, oauth.OAuthConsumer))
158 self.assertEquals('consumer_key', consumer.key)160 self.assertEqual('consumer_key', consumer.key)
159161
160 def test_fetch_request_token(self):162 def test_fetch_request_token(self):
161 '''Test fetching the request token.'''163 '''Test fetching the request token.'''
162 parameters = {'oauth_consumer_key' : 'consumer_key',164 parameters = {'oauth_consumer_key': 'consumer_key',
163 'oauth_signature_method' : 'PLAINTEXT',165 'oauth_signature_method': 'PLAINTEXT',
164 'oauth_signature' : '',166 'oauth_signature': '',
165 'oauth_timestamp' : str(int(time.time())),167 'oauth_timestamp': str(int(time.time())),
166 'oauth_nonce' : 'nonce',168 'oauth_nonce': 'nonce',
167 'oauth_version' : oauth.OAUTH_VERSION,169 'oauth_version': oauth.OAUTH_VERSION,
168 'oauth_callback' : 'oob',170 'oauth_callback': 'oob',
169 }171 }
170 response = self.storage.fetch_request_token(parameters)172 response = self.storage.fetch_request_token(parameters)
171 self.assertTrue(isinstance(response, OAuthResponse))173 self.assertTrue(isinstance(response, OAuthResponse))
172 self.assertEquals(response.token.key, 'request_key')174 self.assertEqual(response.token.key, 'request_key')
173175
174 def test_fetch_request_token_compat(self):176 def test_fetch_request_token_compat(self):
175 '''Test fetching the request token.'''177 '''Test fetching the request token.'''
176 parameters = {'oauth_consumer_key' : 'consumer_key',178 parameters = {'oauth_consumer_key': 'consumer_key',
177 'oauth_signature_method' : 'PLAINTEXT',179 'oauth_signature_method': 'PLAINTEXT',
178 'oauth_signature' : '',180 'oauth_signature': '',
179 'oauth_timestamp' : str(int(time.time())),181 'oauth_timestamp': str(int(time.time())),
180 'oauth_nonce' : 'nonce',182 'oauth_nonce': 'nonce',
181 'oauth_version' : oauth.OAUTH_VERSION,183 'oauth_version': oauth.OAUTH_VERSION,
182 }184 }
183 response = self.storage.fetch_request_token(parameters)185 response = self.storage.fetch_request_token(parameters)
184 self.assertTrue(isinstance(response, OAuthResponse))186 self.assertTrue(isinstance(response, OAuthResponse))
185 self.assertEquals(response.token.key, 'request_key')187 self.assertEqual(response.token.key, 'request_key')
186188
187 def test_authorize_request_token(self):189 def test_authorize_request_token(self):
188 '''Test authorizing a request token.'''190 '''Test authorizing a request token.'''
189191
=== added file 'run-tests'
--- run-tests 1970-01-01 00:00:00 +0000
+++ run-tests 2012-05-21 13:12:18 +0000
@@ -0,0 +1,31 @@
1#!/bin/bash
2#
3# Copyright 2010-2012 Canonical Ltd.
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22
23set -e -x
24
25# Run the tests with both python (2.x) and python3
26./setup.py build test clean
27python3 ./setup.py build test clean
28
29# Style checks
30pyflakes poauth setup.py
31pep8 --repeat . setup.py
032
=== modified file 'setup.py'
--- setup.py 2009-08-31 19:20:49 +0000
+++ setup.py 2012-05-21 13:12:18 +0000
@@ -1,9 +1,9 @@
1#!/usr/bin/env python1#!/usr/bin/python
2#2#
3# The MIT License3# The MIT License
4#4#
5# Copyright (c) 2007 Leah Culver5# Copyright (c) 2007 Leah Culver
6# Copyright (c) 2009 Canonical, Ltd.6# Copyright (c) 2009-2012 Canonical, Ltd.
7#7#
8# Permission is hereby granted, free of charge, to any person obtaining a copy8# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and associated documentation files (the "Software"), to deal9# of this software and associated documentation files (the "Software"), to deal
@@ -34,5 +34,7 @@
34 license='MIT',34 license='MIT',
35 author='Rodney Dawes',35 author='Rodney Dawes',
36 author_email='rodney.dawes@canonical.com',36 author_email='rodney.dawes@canonical.com',
37 download_url='https://launchpad.net/poauth/+download',
37 packages=find_packages(),38 packages=find_packages(),
39 test_suite='poauth.tests',
38)40)

Subscribers

People subscribed via source and target branches

to all changes: