Added unit test for oauth.
authorJosh Roesslein <jroesslein@gmail.com>
Tue, 11 Aug 2009 19:34:44 +0000 (14:34 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Tue, 11 Aug 2009 19:34:44 +0000 (14:34 -0500)
tests.py
tweepy/auth.py
tweepy/binder.py

index 8ec31252706014122a6cfe7687e3a1fb225f12ed..f6f77d574914024b6471347b64306761355b5516 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -13,8 +13,8 @@ from tweepy import *
 class TweepyAPITests(unittest.TestCase):
 
   # Must supply twitter account credentials for tests
-  username = ''
-  password = ''
+  username = 'tweebly'
+  password = 'omega1987twitter'
 
   def setUp(self):
     self.api = API(BasicAuthHandler(self.username, self.password), self.username)
@@ -98,6 +98,24 @@ class TweepyAPITests(unittest.TestCase):
     self.assert_(isinstance(source, Friendship))
     self.assert_(isinstance(target, Friendship))
 
+class TweepyAuthTests(unittest.TestCase):
+
+  consumer_key = 'ZbzSsdQj7t68VYlqIFvdcA'
+  consumer_secret = '4yDWgrBiRs2WIx3bfvF9UWCRmtQ2YKpKJKBahtZcU'
+
+  def testoauth(self):
+    auth = OAuthHandler(self.consumer_key, self.consumer_secret)   
+    auth_url = auth.get_authorization_url()
+    self.assert_(auth_url.startswith('http://twitter.com/oauth/authorize?'))
+    print 'Please authorize: ' + auth_url
+    verifier = raw_input('PIN: ').strip()
+    self.assert_(len(verifier) > 0)
+    access_token = auth.get_access_token(verifier)
+    self.assert_(access_token is not None)
+
+    api = API(auth)
+    self.assertTrue(api.verify_credentials())
+
 if __name__ == '__main__':
   unittest.main()
     
index 4da0ce46b98dd8687ce937ca4d1b52c782bdc8ff..52aced56fd83726b4f349ddd6c1ba9e83202d8fd 100644 (file)
@@ -55,6 +55,9 @@ class OAuthHandler(AuthHandler):
     except Exception, e:
       raise TweepError(e)
 
+  def set_access_token(self, key, secret):
+    self.access_token = oauth.OAuthToken(key, secret)
+
   def get_authorization_url(self):
     """Get the authorization URL to redirect the user"""
     try:
index 028324b9377f4131548d4a42f34595b37b4f1c62..47a27319a30ca0a29ac3a5ed21a440734ebf83f7 100644 (file)
@@ -67,9 +67,9 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
 
     # Open connection
     if api.secure:
-      conn = httplib.HTTPSConnection(_host)
+      conn = httplib.HTTPSConnection(_host, timeout=10.0)
     else:
-      conn = httplib.HTTPConnection(_host)
+      conn = httplib.HTTPConnection(_host, timeout=10.0)
 
     # Build request
     conn.request(method, url, headers=headers)