Coverage, tests, secure ACCESS_TOKEN, update HISTORY
This commit is contained in:
parent
9813a4c8f5
commit
478c139af2
6 changed files with 50 additions and 4 deletions
|
|
@ -21,6 +21,10 @@ env:
|
|||
Y0M90wCpDWmSdBmgPCV2N9mMSaRMdEOis5r5sfUq/5aFTB/KDaSR9scM1g+L
|
||||
21OtvUBvaG1bdSzn0T+I5Fs/MkfbtTmuahogy83nsNDRpIZJmRIsHFmJw1fz
|
||||
nEHD2Kbm4iLMYzrKto77KpxYSQMnc3sQKZjreaI31NLu+7raCAk=
|
||||
- secure: |-
|
||||
j1gePLSZF8SRcpF1AU+cBK5MSih5MrM1iGE6N7VWI0wrl+xh7wr3QLtVkAar
|
||||
AeMFgwkz6QalfrKLsoUPFuNMv7vn+2CthC9pRv+NRk+4xV+37NysHFPR7JRo
|
||||
xK2EC+DCiw2eJECnk9IPGQTgkVnFAQ3GLnsBSzzJ+UAkG2NjZ88=
|
||||
- SCREEN_NAME=__twython__
|
||||
- PROTECTED_TWITTER_1=TwythonSecure1
|
||||
- PROTECTED_TWITTER_2=TwythonSecure2
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ History
|
|||
- Developers can now pass an array as a parameter to Twitter API methods and they will be automatically joined by a comma and converted to a string
|
||||
- ``endpoints.py`` now contains ``EndpointsMixin`` (rather than the previous ``api_table`` dict) for Twython, which enables Twython to use functions declared in the Mixin.
|
||||
- Added OAuth 2 authentication (Application Only) for when you want to make read-only calls to Twitter without having to go through the whole user authentication ritual (see docs for usage)
|
||||
- Added ``obtain_access_token`` to obtain an OAuth 2 Application Only read-only access token
|
||||
- ``construct_api_url`` now accepts keyword arguments like other Twython methods (e.g. instead of passing ``{'q': 'twitter', 'result_type': 'recent'}``, pass ``q='twitter', result_type='recent'``)
|
||||
- Pass ``client_args`` to the Twython ``__init__`` to manipulate request variables. ``client_args`` accepts a dictionary of keywords and values that accepted by ``requests`` (`Session API <http://docs.python-requests.org/en/latest/api/#sessionapi>`_) [ex. headers, proxies, verify(SSL verification)] and the "request" section directly below it.
|
||||
- Added ``get_application_rate_limit_status`` API method for returning the current rate limits for the specified source
|
||||
- Added ``invalidate_token`` API method which allows registed apps to revoke an access token presenting its client credentials
|
||||
|
||||
2.10.1 (2013-05-29)
|
||||
++++++++++++++++++
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ app_key = os.environ.get('APP_KEY')
|
|||
app_secret = os.environ.get('APP_SECRET')
|
||||
oauth_token = os.environ.get('OAUTH_TOKEN')
|
||||
oauth_token_secret = os.environ.get('OAUTH_TOKEN_SECRET')
|
||||
access_token = os.environ.get('ACCESS_TOKEN')
|
||||
|
||||
screen_name = os.environ.get('SCREEN_NAME', '__twython__')
|
||||
|
||||
|
|
|
|||
|
|
@ -43,3 +43,8 @@ class TwythonAuthTestCase(unittest.TestCase):
|
|||
def test_obtain_access_token(self):
|
||||
"""Test obtaining an Application Only OAuth 2 access token succeeds"""
|
||||
self.oauth2_api.obtain_access_token()
|
||||
|
||||
def test_obtain_access_token_raises_error_when_oauth1(self):
|
||||
"""Test when API is set for OAuth 1, obtain_access_token raises a
|
||||
TwythonError"""
|
||||
self.assertRaises(TwythonError, self.api.obtain_access_token)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from twython import Twython, TwythonError, TwythonAuthError
|
|||
from .config import (
|
||||
app_key, app_secret, oauth_token, oauth_token_secret,
|
||||
protected_twitter_1, protected_twitter_2, screen_name,
|
||||
test_tweet_id, test_list_id
|
||||
test_tweet_id, test_list_id, access_token
|
||||
)
|
||||
|
||||
import time
|
||||
|
|
@ -20,10 +20,17 @@ class TwythonAPITestCase(unittest.TestCase):
|
|||
'allow_redirects': False
|
||||
}
|
||||
|
||||
oauth2_client_args = {
|
||||
'headers': {} # This is so we can hit coverage that Twython sets User-Agent for us if none is supplied
|
||||
}
|
||||
|
||||
self.api = Twython(app_key, app_secret,
|
||||
oauth_token, oauth_token_secret,
|
||||
client_args=client_args)
|
||||
|
||||
self.oauth2_api = Twython(app_key, access_token=access_token,
|
||||
client_args=oauth2_client_args)
|
||||
|
||||
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'
|
||||
|
|
@ -198,7 +205,7 @@ class TwythonAPITestCase(unittest.TestCase):
|
|||
retweets='true')
|
||||
|
||||
self.api.update_friendship(screen_name=protected_twitter_1,
|
||||
retweets='false')
|
||||
retweets=False)
|
||||
|
||||
def test_show_friendships(self):
|
||||
"""Test showing specific friendship succeeds"""
|
||||
|
|
@ -335,11 +342,12 @@ class TwythonAPITestCase(unittest.TestCase):
|
|||
|
||||
self.api.update_list(list_id=list_id, name='Stuff Renamed')
|
||||
|
||||
screen_names = ['johncena', 'xbox']
|
||||
# Multi add/delete members
|
||||
self.api.create_list_members(list_id=list_id,
|
||||
screen_name='johncena,xbox')
|
||||
screen_name=screen_names)
|
||||
self.api.delete_list_members(list_id=list_id,
|
||||
screen_name='johncena,xbox')
|
||||
screen_name=screen_names)
|
||||
|
||||
# Single add/delete member
|
||||
self.api.add_list_member(list_id=list_id, screen_name='justinbieber')
|
||||
|
|
@ -430,3 +438,8 @@ class TwythonAPITestCase(unittest.TestCase):
|
|||
"""Test getting the locations that Twitter has trending topic
|
||||
information for, closest to a specified location succeeds"""
|
||||
self.api.get_closest_trends(lat='37', long='-122')
|
||||
|
||||
# Help
|
||||
def test_get_application_rate_limit_status(self):
|
||||
"""Test getting application rate limit status succeeds"""
|
||||
self.oauth2_api.get_application_rate_limit_status()
|
||||
|
|
|
|||
|
|
@ -756,6 +756,26 @@ class EndpointsMixin(object):
|
|||
"""
|
||||
return self.post('users/report_spam', params=params)
|
||||
|
||||
# OAuth
|
||||
def invalidate_token(self, **params):
|
||||
"""Allows a registered application to revoke an issued OAuth 2 Bearer
|
||||
Token by presenting its client credentials.
|
||||
|
||||
Docs: https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
|
||||
|
||||
"""
|
||||
return self.post('oauth2/invalidate_token', params=params)
|
||||
|
||||
# Help
|
||||
def get_application_rate_limit_status(self, **params):
|
||||
"""Returns the current rate limits for methods belonging to the
|
||||
specified resource families.
|
||||
|
||||
Docs: https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status
|
||||
|
||||
"""
|
||||
return self.get('application/rate_limit_status', params=params)
|
||||
|
||||
|
||||
# from https://dev.twitter.com/docs/error-codes-responses
|
||||
TWITTER_HTTP_STATUS_CODE = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue