diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 0baaa138..c4ee584a 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -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 diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 100f8038..57822dcd 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -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() @@ -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))