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)
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()
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:
# 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)