Skip to content

Commit

Permalink
Fixed a minor spelling error, added tests for oauth2.Error.__str__(),…
Browse files Browse the repository at this point in the history
… and added a test for build_xoauth_string().
  • Loading branch information
joestump committed May 15, 2010
1 parent bac0c0c commit 8da2682
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion oauth2/__init__.py
Expand Up @@ -44,7 +44,7 @@
class Error(RuntimeError):
"""Generic exception class."""

def __init__(self, message='OAuth error occured.'):
def __init__(self, message='OAuth error occurred.'):
self._message = message

@property
Expand Down
31 changes: 30 additions & 1 deletion tests/test_oauth.py
Expand Up @@ -46,13 +46,20 @@ def test_message(self):
try:
raise oauth.Error
except oauth.Error, e:
self.assertEqual(e.message, 'OAuth error occured.')
self.assertEqual(e.message, 'OAuth error occurred.')

msg = 'OMG THINGS BROKE!!!!'
try:
raise oauth.Error(msg)
except oauth.Error, e:
self.assertEqual(e.message, msg)

def test_str(self):
try:
raise oauth.Error
except oauth.Error, e:
self.assertEquals(str(e), 'OAuth error occurred.')

class TestGenerateFunctions(unittest.TestCase):
def test_build_auth_header(self):
header = oauth.build_authenticate_header()
Expand All @@ -64,6 +71,28 @@ def test_build_auth_header(self):
realm)
self.assertEqual(len(header), 1)

def test_build_xoauth_string(self):
consumer = oauth.Consumer('consumer_token', 'consumer_secret')
token = oauth.Token('user_token', 'user_secret')
url = "https://mail.google.com/mail/b/joe@example.com/imap/"
xoauth_string = oauth.build_xoauth_string(url, consumer, token)

method, oauth_url, oauth_string = xoauth_string.split(' ')

self.assertEqual("GET", method)
self.assertEqual(url, oauth_url)

returned = {}
parts = oauth_string.split(',')
for part in parts:
var, val = part.split('=')
returned[var] = val.strip('"')

self.assertEquals('HMAC-SHA1', returned['oauth_signature_method'])
self.assertEquals('user_token', returned['oauth_token'])
self.assertEquals('consumer_token', returned['oauth_consumer_key'])
self.assertTrue('oauth_signature' in returned, 'oauth_signature')

def test_escape(self):
string = 'http://whatever.com/~someuser/?test=test&other=other'
self.assert_('~' in oauth.escape(string))
Expand Down

0 comments on commit 8da2682

Please sign in to comment.