From 2f5f496eadad15cc939a2aac2f9e2e0875dfff6d Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Tue, 11 Jun 2013 15:00:39 -0400 Subject: [PATCH] More test coverage --- tests/test_auth.py | 6 +++++- tests/test_core.py | 3 ++- twython/endpoints.py | 26 +++++++++----------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/tests/test_auth.py b/tests/test_auth.py index 4ec2506..bd0b3c5 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -35,7 +35,11 @@ class TwythonAuthTestCase(unittest.TestCase): self.assertRaises(TwythonError, self.oauth2_api.get_authentication_tokens) def test_get_authorization_tokens_raises_error_when_oauth2(self): - """Test when API is set for OAuth 2, get_authentication_tokens raises + """Test when API is set for OAuth 2, get_authorized_tokens raises a TwythonError""" self.assertRaises(TwythonError, self.oauth2_api.get_authorized_tokens, 'BAD_OAUTH_VERIFIER') + + def test_obtain_access_token(self): + """Test obtaining an Application Only OAuth 2 access token succeeds""" + self.oauth2_api.obtain_access_token() diff --git a/tests/test_core.py b/tests/test_core.py index d49f2ed..418b365 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -16,7 +16,8 @@ class TwythonAPITestCase(unittest.TestCase): client_args = { 'headers': { 'User-Agent': '__twython__ Test' - } + }, + 'allow_redirects': False } self.api = Twython(app_key, app_secret, diff --git a/twython/endpoints.py b/twython/endpoints.py index 3ca3c71..c55b7da 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -59,9 +59,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/%3Aid """ - if not 'id' in params: - raise TwythonError('Parameter "id" is required') - return self.get('statuses/retweets/%s' % params['id'], params=params) + return self.get('statuses/retweets/%s' % params.get('id'), params=params) def show_status(self, **params): """Returns a single Tweet, specified by the id parameter @@ -69,9 +67,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/show/%3Aid """ - if not 'id' in params: - raise TwythonError('Parameter "id" is required') - return self.get('statuses/show/%s' % params['id'], params=params) + return self.get('statuses/show/%s' % params.get('id'), params=params) def destroy_status(self, **params): """Destroys the status specified by the required ID parameter @@ -79,9 +75,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid """ - if not 'id' in params: - raise TwythonError('Parameter "id" is required') - return self.post('statuses/destroy/%s' % params['id']) + return self.post('statuses/destroy/%s' % params.get('id')) def update_status(self, **params): """Updates the authenticating user's current status, also known as tweeting @@ -97,9 +91,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid """ - if not 'id' in params: - raise TwythonError('Parameter "id" is required') - return self.post('statuses/retweet/%s' % params['id']) + return self.post('statuses/retweet/%s' % params.get('id')) def update_status_with_media(self, **params): """Updates the authenticating user's current status and attaches media @@ -462,7 +454,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug """ - return self.get('users/suggestions/%s' % params['slug'], params=params) + return self.get('users/suggestions/%s' % params.get('slug'), params=params) def get_user_suggestions(self, **params): """Access to Twitter's suggested user list. @@ -479,7 +471,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug/members """ - return self.get('users/suggestions/%s/members' % params['slug'], params=params) + return self.get('users/suggestions/%s/members' % params.get('slug'), params=params) # Favorites def get_favorites(self, **params): @@ -668,7 +660,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/%3Aid """ - return self.get('saved_searches/show/%s' % params['id'], params=params) + return self.get('saved_searches/show/%s' % params.get('id'), params=params) def create_saved_search(self, **params): """Create a new saved search for the authenticated user. @@ -684,7 +676,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/%3Aid """ - return self.post('saved_searches/destroy/%s' % params['id'], params=params) + return self.post('saved_searches/destroy/%s' % params.get('id'), params=params) # Places & Geo def get_geo_info(self, **params): @@ -693,7 +685,7 @@ class EndpointsMixin(object): Docs: https://dev.twitter.com/docs/api/1.1/get/geo/id/%3Aplace_id """ - return self.get('geo/id/%s' % params['place_id'], params=params) + return self.get('geo/id/%s' % params.get('place_id'), params=params) def reverse_geocode(self, **params): """Given a latitude and a longitude, searches for up to 20 places