2.10.1
- More test coverage! - Fix ``search_gen`` - Fixed ``get_lastfunction_header`` to actually do what its docstring says, returns ``None`` if header is not found - Updated some internal API code, ``__init__`` didn't need to have ``self.auth`` and ``self.headers`` because they were never used anywhere else but the ``__init__``
This commit is contained in:
parent
05ca86805f
commit
894e94a4cd
5 changed files with 102 additions and 24 deletions
|
|
@ -24,6 +24,7 @@ test_list_id = os.environ.get('TEST_LIST_ID', '574') # 574 is @twitter/team
|
|||
class TwythonAuthTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.api = Twython(app_key, app_secret)
|
||||
self.bad_api = Twython('BAD_APP_KEY', 'BAD_APP_SECRET')
|
||||
|
||||
def test_get_authentication_tokens(self):
|
||||
'''Test getting authentication tokens works'''
|
||||
|
|
@ -31,11 +32,76 @@ class TwythonAuthTestCase(unittest.TestCase):
|
|||
force_login=True,
|
||||
screen_name=screen_name)
|
||||
|
||||
def test_get_authentication_tokens_bad_tokens(self):
|
||||
'''Test getting authentication tokens with bad tokens
|
||||
raises TwythonAuthError'''
|
||||
self.assertRaises(TwythonAuthError, self.api.get_authentication_tokens,
|
||||
callback_url='http://google.com/')
|
||||
|
||||
def test_get_authorized_tokens_bad_tokens(self):
|
||||
'''Test getting final tokens fails with wrong tokens'''
|
||||
self.assertRaises(TwythonError, self.api.get_authorized_tokens,
|
||||
'BAD_OAUTH_VERIFIER')
|
||||
|
||||
|
||||
class TwythonAPITestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.api = Twython(app_key, app_secret,
|
||||
oauth_token, oauth_token_secret)
|
||||
oauth_token, oauth_token_secret,
|
||||
headers={'User-Agent': '__twython__ Test'})
|
||||
|
||||
def test_construct_api_url(self):
|
||||
'''Test constructing a Twitter API url works as we expect'''
|
||||
url = 'https://api.twitter.com/1.1/search/tweets.json'
|
||||
constructed_url = self.api.construct_api_url(url, {'q': '#twitter'})
|
||||
self.assertEqual(constructed_url, 'https://api.twitter.com/1.1/search/tweets.json?q=%23twitter')
|
||||
|
||||
def test_shorten_url(self):
|
||||
'''Test shortening a url works'''
|
||||
self.api.shorten_url('http://google.com')
|
||||
|
||||
def test_shorten_url_no_shortner(self):
|
||||
'''Test shortening a url with no shortener provided raises TwythonError'''
|
||||
self.assertRaises(TwythonError, self.api.shorten_url,
|
||||
'http://google.com', '')
|
||||
|
||||
def test_get(self):
|
||||
'''Test Twython generic GET request works'''
|
||||
self.api.get('account/verify_credentials')
|
||||
|
||||
def test_post(self):
|
||||
'''Test Twython generic POST request works, with a full url and
|
||||
with just an endpoint'''
|
||||
update_url = 'https://api.twitter.com/1.1/statuses/update.json'
|
||||
status = self.api.post(update_url, params={'status': 'I love Twython!'})
|
||||
self.api.post('statuses/destroy/%s' % status['id_str'])
|
||||
|
||||
def test_get_lastfunction_header(self):
|
||||
'''Test getting last specific header of the last API call works'''
|
||||
self.api.get('statuses/home_timeline')
|
||||
self.api.get_lastfunction_header('x-rate-limit-remaining')
|
||||
|
||||
def test_get_lastfunction_header_not_present(self):
|
||||
'''Test getting specific header that does not exist from the last call returns None'''
|
||||
self.api.get('statuses/home_timeline')
|
||||
header = self.api.get_lastfunction_header('does-not-exist')
|
||||
self.assertEqual(header, None)
|
||||
|
||||
def test_get_lastfunction_header_no_last_api_call(self):
|
||||
'''Test attempting to get a header when no API call was made raises a TwythonError'''
|
||||
self.assertRaises(TwythonError, self.api.get_lastfunction_header,
|
||||
'no-api-call-was-made')
|
||||
|
||||
def test_search_gen(self):
|
||||
'''Test looping through the generator results works, at least once that is'''
|
||||
search = self.api.search_gen('python')
|
||||
for result in search:
|
||||
if result:
|
||||
break
|
||||
|
||||
def test_encode(self):
|
||||
'''Test encoding UTF-8 works'''
|
||||
self.api.encode('Twython is awesome!')
|
||||
|
||||
# Timelines
|
||||
def test_get_mentions_timeline(self):
|
||||
|
|
@ -84,9 +150,11 @@ class TwythonAPITestCase(unittest.TestCase):
|
|||
|
||||
def test_retweet_twice(self):
|
||||
'''Test that trying to retweet a tweet twice raises a TwythonError'''
|
||||
retweet = self.api.retweet(id='99530515043983360')
|
||||
self.assertRaises(TwythonError, self.api.retweet,
|
||||
id='99530515043983360')
|
||||
tweets = self.api.search(q='twitter').get('statuses')
|
||||
if tweets:
|
||||
retweet = self.api.retweet(id=tweets[0]['id_str'])
|
||||
self.assertRaises(TwythonError, self.api.retweet,
|
||||
id=tweets[0]['id_str'])
|
||||
|
||||
# Then clean up
|
||||
self.api.destroy_status(id=retweet['id_str'])
|
||||
|
|
@ -132,7 +200,7 @@ class TwythonAPITestCase(unittest.TestCase):
|
|||
def test_get_user_ids_of_blocked_retweets(self):
|
||||
'''Test that collection of user_ids that the authenticated user does
|
||||
not want to receive retweets from succeeds'''
|
||||
self.api.get_user_ids_of_blocked_retweets(stringify_ids='true')
|
||||
self.api.get_user_ids_of_blocked_retweets(stringify_ids=True)
|
||||
|
||||
def test_get_friends_ids(self):
|
||||
'''Test returning ids of users the authenticated user and then a random
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue