Skip to content

Commit

Permalink
pep8 finished
Browse files Browse the repository at this point in the history
  • Loading branch information
greedo committed Jul 26, 2014
1 parent 6206c0b commit a0fec2f
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 77 deletions.
3 changes: 2 additions & 1 deletion examples/follow_user.py
Expand Up @@ -9,7 +9,8 @@
if len(sys.argv) >= 2:
target = sys.argv[1]
else:
target = raw_input("User to follow: ") # For Python 3.x use: target = input("User to follow: ")
target = raw_input("User to follow: ")
# For Python 3.x use: target = input("User to follow: ")

# Requires Authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
Expand Down
4 changes: 3 additions & 1 deletion examples/search_results.py
Expand Up @@ -8,5 +8,7 @@
print e

for tweet in search_results['statuses']:
print 'Tweet from @%s Date: %s' % (tweet['user']['screen_name'].encode('utf-8'), tweet['created_at'])
print 'Tweet from @%s Date: %s' % (tweet['user']['screen_nam\
e'].encode('utf-8'),
tweet['created_at'])
print tweet['text'].encode('utf-8'), '\n'
6 changes: 4 additions & 2 deletions examples/stream.py
Expand Up @@ -16,5 +16,7 @@ def on_error(self, status_code, data):
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

stream.statuses.filter(track='twitter')
#stream.user() # Read the authenticated users home timeline (what they see on Twitter) in real-time
#stream.site(follow='twitter')
# stream.user()
# Read the authenticated users home timeline
# (what they see on Twitter) in real-time
# stream.site(follow='twitter')
5 changes: 3 additions & 2 deletions setup.py
Expand Up @@ -29,9 +29,10 @@
license=open('LICENSE').read(),
url='https://github.com/ryanmcgrath/twython/tree/master',
keywords='twitter search api tweet twython stream',
description='Actively maintained, pure Python wrapper for the Twitter API. Supports both normal and streaming Twitter APIs',
description='Actively maintained, pure Python wrapper for the \
Twitter API. Supports both normal and streaming Twitter APIs',
long_description=open('README.rst').read() + '\n\n' +
open('HISTORY.rst').read(),
open('HISTORY.rst').read(),
include_package_data=True,
packages=packages,
classifiers=[
Expand Down
3 changes: 2 additions & 1 deletion tests/config.py
Expand Up @@ -23,7 +23,8 @@
# Test Ids
test_tweet_id = os.environ.get('TEST_TWEET_ID', '318577428610031617')
test_list_slug = os.environ.get('TEST_LIST_SLUG', 'team')
test_list_owner_screen_name = os.environ.get('TEST_LIST_OWNER_SCREEN_NAME', 'twitterapi')
test_list_owner_screen_name = os.environ.get('TEST_LIST_OWNER_SCREEN_NAME',
'twitterapi')

test_tweet_object = {u'contributors': None, u'truncated': False, u'text': u'http://t.co/FCmXyI6VHd is a #cool site, lol! @mikehelmick should #checkitout. If you can! #thanks Love, @__twython__ https://t.co/67pwRvY6z9', u'in_reply_to_status_id': None, u'id': 349683012054683648, u'favorite_count': 0, u'source': u'web', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [{u'id': 29251354, u'indices': [45, 57], u'id_str': u'29251354', u'screen_name': u'mikehelmick', u'name': u'Mike Helmick'}, {u'id': 1431865928, u'indices': [104, 116], u'id_str': u'1431865928', u'screen_name': u'__twython__', u'name': u'Twython'}], u'hashtags': [{u'indices': [28, 33], u'text': u'cool'}, {u'indices': [65, 76], u'text': u'checkitout'}, {u'indices': [90, 97], u'text': u'thanks'}], u'urls': [{u'url': u'http://t.co/FCmXyI6VHd', u'indices': [0, 22], u'expanded_url': u'http://google.com', u'display_url': u'google.com'}, {u'url': u'https://t.co/67pwRvY6z9', u'indices': [117, 140], u'expanded_url': u'https://github.com', u'display_url': u'github.com'}]}, u'in_reply_to_screen_name': None, u'id_str': u'349683012054683648', u'retweet_count': 0, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': False, u'profile_use_background_image': True, u'default_profile_image': True, u'id': 1431865928, u'verified': False, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://si0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png', u'profile_sidebar_fill_color': u'DDEEF6', u'entities': {u'description': {u'urls': []}}, u'followers_count': 1, u'profile_sidebar_border_color': u'C0DEED', u'id_str': u'1431865928', u'profile_background_color': u'3D3D3D', u'listed_count': 0, u'profile_background_image_url_https': u'https://si0.twimg.com/images/themes/theme1/bg.png', u'utc_offset': None, u'statuses_count': 2, u'description': u'', u'friends_count': 1, u'location': u'', u'profile_link_color': u'0084B4', u'profile_image_url': u'http://a0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png', u'following': False, u'geo_enabled': False, u'profile_background_image_url': u'http://a0.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'__twython__', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 0, u'name': u'Twython', u'notifications': False, u'url': None, u'created_at': u'Thu May 16 01:11:09 +0000 2013', u'contributors_enabled': False, u'time_zone': None, u'protected': False, u'default_profile': False, u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'lang': u'en', u'created_at': u'Wed Jun 26 00:18:21 +0000 2013', u'in_reply_to_status_id_str': None, u'place': None}
test_tweet_html = '<a href="http://t.co/FCmXyI6VHd" class="twython-url">google.com</a> is a <a href="https://twitter.com/search?q=%23cool" class="twython-hashtag">#cool</a> site, lol! <a href="https://twitter.com/mikehelmick" class="twython-mention">@mikehelmick</a> should <a href="https://twitter.com/search?q=%23checkitout" class="twython-hashtag">#checkitout</a>. If you can! <a href="https://twitter.com/search?q=%23thanks" class="twython-hashtag">#thanks</a> Love, <a href="https://twitter.com/__twython__" class="twython-mention">@__twython__</a> <a href="https://t.co/67pwRvY6z9" class="twython-url">github.com</a>'
12 changes: 6 additions & 6 deletions tests/test_core.py
Expand Up @@ -28,16 +28,16 @@ def get_url(self, endpoint):
return '%s/%s.json' % (self.api.api_url % self.api.api_version, endpoint)

def register_response(self, method, url, body='{}', match_querystring=False,
status=200, adding_headers=None, stream=False,
content_type='application/json; charset=utf-8'):
status=200, adding_headers=None, stream=False,
content_type='application/json; charset=utf-8'):
"""Wrapper function for responses for simpler unit tests"""

# responses uses BytesIO to hold the body so it needs to be in bytes
if not is_py2:
body = bytes(body, 'UTF-8')

responses.add(method, url, body, match_querystring,
status, adding_headers, stream, content_type)
status, adding_headers, stream, content_type)

@responses.activate
def test_request_should_handle_full_endpoint(self):
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_request_should_post_request_regardless_of_case(self):
@responses.activate
def test_request_should_throw_exception_with_invalid_http_method(self):
"""Test that request() throws an exception when an invalid HTTP method is passed"""
#TODO(cash): should Twython catch the AttributeError and throw a TwythonError
# TODO(cash): should Twython catch the AttributeError and throw a TwythonError
self.assertRaises(AttributeError, self.api.request, endpoint='search/tweets', method='INVALID')

@responses.activate
Expand Down Expand Up @@ -315,5 +315,5 @@ def test_html_for_tweet_short_url(self):
"""Test using expanded url in HTML for Tweet displays full urls"""
tweet_text = self.api.html_for_tweet(test_tweet_object, False)
# Make sure HTML doesn't contain the display OR expanded url
self.assertTrue(not 'http://google.com' in tweet_text)
self.assertTrue(not 'google.com' in tweet_text)
self.assertTrue('http://google.com' not in tweet_text)
self.assertTrue('google.com' not in tweet_text)
22 changes: 15 additions & 7 deletions tests/test_endpoints.py
Expand Up @@ -20,8 +20,10 @@ def setUp(self):
'allow_redirects': False
}

# This is so we can hit coverage that Twython sets
# User-Agent for us if none is supplied
oauth2_client_args = {
'headers': {} # This is so we can hit coverage that Twython sets User-Agent for us if none is supplied
'headers': {}
}

self.api = Twython(app_key, app_secret,
Expand All @@ -42,7 +44,8 @@ def test_get_user_timeline(self):
"""Test returning timeline for authenticated user and random user
succeeds"""
self.api.get_user_timeline() # Authenticated User Timeline
self.api.get_user_timeline(screen_name='twitter') # Random User Timeline
self.api.get_user_timeline(screen_name='twitter')
# Random User Timeline

@unittest.skip('skipping non-updated test')
def test_get_protected_user_timeline_following(self):
Expand Down Expand Up @@ -82,7 +85,8 @@ def test_show_status(self):
@unittest.skip('skipping non-updated test')
def test_update_and_destroy_status(self):
"""Test updating and deleting a status succeeds"""
status = self.api.update_status(status='Test post just to get deleted :( %s' % int(time.time()))
status = self.api.update_status(status='Test post just to get \
deleted :( %s' % int(time.time()))
self.api.destroy_status(id=status['id_str'])

@unittest.skip('skipping non-updated test')
Expand Down Expand Up @@ -117,7 +121,8 @@ def test_get_sent_messages(self):
def test_send_get_and_destroy_direct_message(self):
"""Test sending, getting, then destory a direct message succeeds"""
message = self.api.send_direct_message(screen_name=protected_twitter_1,
text='Hey d00d! %s' % int(time.time()))
text='Hey d00d! %s\
' % int(time.time()))

self.api.get_direct_message(id=message['id_str'])
self.api.destroy_direct_message(id=message['id_str'])
Expand All @@ -127,7 +132,8 @@ def test_send_direct_message_to_non_follower(self):
"""Test sending a direct message to someone who doesn't follow you
fails"""
self.assertRaises(TwythonError, self.api.send_direct_message,
screen_name=protected_twitter_2, text='Yo, man! %s' % int(time.time()))
screen_name=protected_twitter_2, text='Yo, man! \
%s' % int(time.time()))

# Friends & Followers
@unittest.skip('skipping non-updated test')
Expand Down Expand Up @@ -348,7 +354,8 @@ def test_create_update_destroy_list_add_remove_list_members(self):
the_list = self.api.create_list(name='Stuff %s' % int(time.time()))
list_id = the_list['id_str']

self.api.update_list(list_id=list_id, name='Stuff Renamed %s' % int(time.time()))
self.api.update_list(list_id=list_id, name='Stuff Renamed \
%s' % int(time.time()))

screen_names = ['johncena', 'xbox']
# Multi add/delete members
Expand All @@ -359,7 +366,8 @@ def test_create_update_destroy_list_add_remove_list_members(self):

# Single add/delete member
self.api.add_list_member(list_id=list_id, screen_name='justinbieber')
self.api.delete_list_member(list_id=list_id, screen_name='justinbieber')
self.api.delete_list_member(list_id=list_id,
screen_name='justinbieber')

self.api.delete_list(list_id=list_id)

Expand Down

0 comments on commit a0fec2f

Please sign in to comment.