Skip to content

Commit 8da2682

Browse files
committed
Fixed a minor spelling error, added tests for oauth2.Error.__str__(), and added a test for build_xoauth_string().
1 parent bac0c0c commit 8da2682

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

oauth2/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
class Error(RuntimeError):
4545
"""Generic exception class."""
4646

47-
def __init__(self, message='OAuth error occured.'):
47+
def __init__(self, message='OAuth error occurred.'):
4848
self._message = message
4949

5050
@property

tests/test_oauth.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,20 @@ def test_message(self):
4646
try:
4747
raise oauth.Error
4848
except oauth.Error, e:
49-
self.assertEqual(e.message, 'OAuth error occured.')
49+
self.assertEqual(e.message, 'OAuth error occurred.')
50+
5051
msg = 'OMG THINGS BROKE!!!!'
5152
try:
5253
raise oauth.Error(msg)
5354
except oauth.Error, e:
5455
self.assertEqual(e.message, msg)
5556

57+
def test_str(self):
58+
try:
59+
raise oauth.Error
60+
except oauth.Error, e:
61+
self.assertEquals(str(e), 'OAuth error occurred.')
62+
5663
class TestGenerateFunctions(unittest.TestCase):
5764
def test_build_auth_header(self):
5865
header = oauth.build_authenticate_header()
@@ -64,6 +71,28 @@ def test_build_auth_header(self):
6471
realm)
6572
self.assertEqual(len(header), 1)
6673

74+
def test_build_xoauth_string(self):
75+
consumer = oauth.Consumer('consumer_token', 'consumer_secret')
76+
token = oauth.Token('user_token', 'user_secret')
77+
url = "https://mail.google.com/mail/b/[email protected]/imap/"
78+
xoauth_string = oauth.build_xoauth_string(url, consumer, token)
79+
80+
method, oauth_url, oauth_string = xoauth_string.split(' ')
81+
82+
self.assertEqual("GET", method)
83+
self.assertEqual(url, oauth_url)
84+
85+
returned = {}
86+
parts = oauth_string.split(',')
87+
for part in parts:
88+
var, val = part.split('=')
89+
returned[var] = val.strip('"')
90+
91+
self.assertEquals('HMAC-SHA1', returned['oauth_signature_method'])
92+
self.assertEquals('user_token', returned['oauth_token'])
93+
self.assertEquals('consumer_token', returned['oauth_consumer_key'])
94+
self.assertTrue('oauth_signature' in returned, 'oauth_signature')
95+
6796
def test_escape(self):
6897
string = 'http://whatever.com/~someuser/?test=test&other=other'
6998
self.assert_('~' in oauth.escape(string))

0 commit comments

Comments
 (0)