Skip to content

Commit 478c139

Browse files
Coverage, tests, secure ACCESS_TOKEN, update HISTORY
1 parent 9813a4c commit 478c139

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ env:
2121
Y0M90wCpDWmSdBmgPCV2N9mMSaRMdEOis5r5sfUq/5aFTB/KDaSR9scM1g+L
2222
21OtvUBvaG1bdSzn0T+I5Fs/MkfbtTmuahogy83nsNDRpIZJmRIsHFmJw1fz
2323
nEHD2Kbm4iLMYzrKto77KpxYSQMnc3sQKZjreaI31NLu+7raCAk=
24+
- secure: |-
25+
j1gePLSZF8SRcpF1AU+cBK5MSih5MrM1iGE6N7VWI0wrl+xh7wr3QLtVkAar
26+
AeMFgwkz6QalfrKLsoUPFuNMv7vn+2CthC9pRv+NRk+4xV+37NysHFPR7JRo
27+
xK2EC+DCiw2eJECnk9IPGQTgkVnFAQ3GLnsBSzzJ+UAkG2NjZ88=
2428
- SCREEN_NAME=__twython__
2529
- PROTECTED_TWITTER_1=TwythonSecure1
2630
- PROTECTED_TWITTER_2=TwythonSecure2

HISTORY.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ History
1717
- 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
1818
- ``endpoints.py`` now contains ``EndpointsMixin`` (rather than the previous ``api_table`` dict) for Twython, which enables Twython to use functions declared in the Mixin.
1919
- 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)
20+
- Added ``obtain_access_token`` to obtain an OAuth 2 Application Only read-only access token
2021
- ``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'``)
2122
- 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.
23+
- Added ``get_application_rate_limit_status`` API method for returning the current rate limits for the specified source
24+
- Added ``invalidate_token`` API method which allows registed apps to revoke an access token presenting its client credentials
2225

2326
2.10.1 (2013-05-29)
2427
++++++++++++++++++

tests/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
app_secret = os.environ.get('APP_SECRET')
55
oauth_token = os.environ.get('OAUTH_TOKEN')
66
oauth_token_secret = os.environ.get('OAUTH_TOKEN_SECRET')
7+
access_token = os.environ.get('ACCESS_TOKEN')
78

89
screen_name = os.environ.get('SCREEN_NAME', '__twython__')
910

tests/test_auth.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ def test_get_authorization_tokens_raises_error_when_oauth2(self):
4343
def test_obtain_access_token(self):
4444
"""Test obtaining an Application Only OAuth 2 access token succeeds"""
4545
self.oauth2_api.obtain_access_token()
46+
47+
def test_obtain_access_token_raises_error_when_oauth1(self):
48+
"""Test when API is set for OAuth 1, obtain_access_token raises a
49+
TwythonError"""
50+
self.assertRaises(TwythonError, self.api.obtain_access_token)

tests/test_core.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .config import (
44
app_key, app_secret, oauth_token, oauth_token_secret,
55
protected_twitter_1, protected_twitter_2, screen_name,
6-
test_tweet_id, test_list_id
6+
test_tweet_id, test_list_id, access_token
77
)
88

99
import time
@@ -20,10 +20,17 @@ def setUp(self):
2020
'allow_redirects': False
2121
}
2222

23+
oauth2_client_args = {
24+
'headers': {} # This is so we can hit coverage that Twython sets User-Agent for us if none is supplied
25+
}
26+
2327
self.api = Twython(app_key, app_secret,
2428
oauth_token, oauth_token_secret,
2529
client_args=client_args)
2630

31+
self.oauth2_api = Twython(app_key, access_token=access_token,
32+
client_args=oauth2_client_args)
33+
2734
def test_construct_api_url(self):
2835
"""Test constructing a Twitter API url works as we expect"""
2936
url = 'https://api.twitter.com/1.1/search/tweets.json'
@@ -198,7 +205,7 @@ def test_update_friendship(self):
198205
retweets='true')
199206

200207
self.api.update_friendship(screen_name=protected_twitter_1,
201-
retweets='false')
208+
retweets=False)
202209

203210
def test_show_friendships(self):
204211
"""Test showing specific friendship succeeds"""
@@ -335,11 +342,12 @@ def test_create_update_destroy_list_add_remove_list_members(self):
335342

336343
self.api.update_list(list_id=list_id, name='Stuff Renamed')
337344

345+
screen_names = ['johncena', 'xbox']
338346
# Multi add/delete members
339347
self.api.create_list_members(list_id=list_id,
340-
screen_name='johncena,xbox')
348+
screen_name=screen_names)
341349
self.api.delete_list_members(list_id=list_id,
342-
screen_name='johncena,xbox')
350+
screen_name=screen_names)
343351

344352
# Single add/delete member
345353
self.api.add_list_member(list_id=list_id, screen_name='justinbieber')
@@ -430,3 +438,8 @@ def test_get_closest_trends(self):
430438
"""Test getting the locations that Twitter has trending topic
431439
information for, closest to a specified location succeeds"""
432440
self.api.get_closest_trends(lat='37', long='-122')
441+
442+
# Help
443+
def test_get_application_rate_limit_status(self):
444+
"""Test getting application rate limit status succeeds"""
445+
self.oauth2_api.get_application_rate_limit_status()

twython/endpoints.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,26 @@ def report_spam(self, **params):
756756
"""
757757
return self.post('users/report_spam', params=params)
758758

759+
# OAuth
760+
def invalidate_token(self, **params):
761+
"""Allows a registered application to revoke an issued OAuth 2 Bearer
762+
Token by presenting its client credentials.
763+
764+
Docs: https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
765+
766+
"""
767+
return self.post('oauth2/invalidate_token', params=params)
768+
769+
# Help
770+
def get_application_rate_limit_status(self, **params):
771+
"""Returns the current rate limits for methods belonging to the
772+
specified resource families.
773+
774+
Docs: https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status
775+
776+
"""
777+
return self.get('application/rate_limit_status', params=params)
778+
759779

760780
# from https://dev.twitter.com/docs/error-codes-responses
761781
TWITTER_HTTP_STATUS_CODE = {

0 commit comments

Comments
 (0)