Skip to content

Commit 2f5f496

Browse files
More test coverage
1 parent 6ce39f9 commit 2f5f496

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

tests/test_auth.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def test_get_authentication_tokens_raises_error_when_oauth2(self):
3535
self.assertRaises(TwythonError, self.oauth2_api.get_authentication_tokens)
3636

3737
def test_get_authorization_tokens_raises_error_when_oauth2(self):
38-
"""Test when API is set for OAuth 2, get_authentication_tokens raises
38+
"""Test when API is set for OAuth 2, get_authorized_tokens raises
3939
a TwythonError"""
4040
self.assertRaises(TwythonError, self.oauth2_api.get_authorized_tokens,
4141
'BAD_OAUTH_VERIFIER')
42+
43+
def test_obtain_access_token(self):
44+
"""Test obtaining an Application Only OAuth 2 access token succeeds"""
45+
self.oauth2_api.obtain_access_token()

tests/test_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def setUp(self):
1616
client_args = {
1717
'headers': {
1818
'User-Agent': '__twython__ Test'
19-
}
19+
},
20+
'allow_redirects': False
2021
}
2122

2223
self.api = Twython(app_key, app_secret,

twython/endpoints.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,23 @@ def get_retweets(self, **params):
5959
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/%3Aid
6060
6161
"""
62-
if not 'id' in params:
63-
raise TwythonError('Parameter "id" is required')
64-
return self.get('statuses/retweets/%s' % params['id'], params=params)
62+
return self.get('statuses/retweets/%s' % params.get('id'), params=params)
6563

6664
def show_status(self, **params):
6765
"""Returns a single Tweet, specified by the id parameter
6866
6967
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/show/%3Aid
7068
7169
"""
72-
if not 'id' in params:
73-
raise TwythonError('Parameter "id" is required')
74-
return self.get('statuses/show/%s' % params['id'], params=params)
70+
return self.get('statuses/show/%s' % params.get('id'), params=params)
7571

7672
def destroy_status(self, **params):
7773
"""Destroys the status specified by the required ID parameter
7874
7975
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid
8076
8177
"""
82-
if not 'id' in params:
83-
raise TwythonError('Parameter "id" is required')
84-
return self.post('statuses/destroy/%s' % params['id'])
78+
return self.post('statuses/destroy/%s' % params.get('id'))
8579

8680
def update_status(self, **params):
8781
"""Updates the authenticating user's current status, also known as tweeting
@@ -97,9 +91,7 @@ def retweet(self, **params):
9791
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid
9892
9993
"""
100-
if not 'id' in params:
101-
raise TwythonError('Parameter "id" is required')
102-
return self.post('statuses/retweet/%s' % params['id'])
94+
return self.post('statuses/retweet/%s' % params.get('id'))
10395

10496
def update_status_with_media(self, **params):
10597
"""Updates the authenticating user's current status and attaches media
@@ -462,7 +454,7 @@ def get_user_suggestions_by_slug(self, **params):
462454
Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug
463455
464456
"""
465-
return self.get('users/suggestions/%s' % params['slug'], params=params)
457+
return self.get('users/suggestions/%s' % params.get('slug'), params=params)
466458

467459
def get_user_suggestions(self, **params):
468460
"""Access to Twitter's suggested user list.
@@ -479,7 +471,7 @@ def get_user_suggestions_statuses_by_slug(self, **params):
479471
Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug/members
480472
481473
"""
482-
return self.get('users/suggestions/%s/members' % params['slug'], params=params)
474+
return self.get('users/suggestions/%s/members' % params.get('slug'), params=params)
483475

484476
# Favorites
485477
def get_favorites(self, **params):
@@ -668,7 +660,7 @@ def show_saved_search(self, **params):
668660
Docs: https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/%3Aid
669661
670662
"""
671-
return self.get('saved_searches/show/%s' % params['id'], params=params)
663+
return self.get('saved_searches/show/%s' % params.get('id'), params=params)
672664

673665
def create_saved_search(self, **params):
674666
"""Create a new saved search for the authenticated user.
@@ -684,7 +676,7 @@ def destroy_saved_search(self, **params):
684676
Docs: https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/%3Aid
685677
686678
"""
687-
return self.post('saved_searches/destroy/%s' % params['id'], params=params)
679+
return self.post('saved_searches/destroy/%s' % params.get('id'), params=params)
688680

689681
# Places & Geo
690682
def get_geo_info(self, **params):
@@ -693,7 +685,7 @@ def get_geo_info(self, **params):
693685
Docs: https://dev.twitter.com/docs/api/1.1/get/geo/id/%3Aplace_id
694686
695687
"""
696-
return self.get('geo/id/%s' % params['place_id'], params=params)
688+
return self.get('geo/id/%s' % params.get('place_id'), params=params)
697689

698690
def reverse_geocode(self, **params):
699691
"""Given a latitude and a longitude, searches for up to 20 places

0 commit comments

Comments
 (0)