Commit c1594632 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Added unit test for oauth.

parent 79a1e8ec
......@@ -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()
......@@ -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:
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment