From: Josh Roesslein Date: Tue, 11 Aug 2009 19:34:44 +0000 (-0500) Subject: Added unit test for oauth. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c1594632dcb36e73f8acdc1e39ba32b062fafa1d;p=tweepy.git Added unit test for oauth. --- diff --git a/tests.py b/tests.py index 8ec3125..f6f77d5 100644 --- 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() diff --git a/tweepy/auth.py b/tweepy/auth.py index 4da0ce4..52aced5 100644 --- a/tweepy/auth.py +++ b/tweepy/auth.py @@ -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: diff --git a/tweepy/binder.py b/tweepy/binder.py index 028324b..47a2731 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -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)