From 1511ee7b4d983c27292f9cb6060c011366cc7ac1 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Sat, 7 Oct 2017 18:08:01 +0100 Subject: [PATCH 1/8] Split test_html_for_tweet() tests into their own file --- tests/test_core.py | 68 +-------------------------------- tests/test_html_for_tweet.py | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 66 deletions(-) create mode 100644 tests/test_html_for_tweet.py diff --git a/tests/test_core.py b/tests/test_core.py index b824f86..4c215d4 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,12 +1,7 @@ # -*- coding: utf-8 -*- from twython import Twython, TwythonError, TwythonAuthError, TwythonRateLimitError -from .config import ( - test_tweet_object, test_tweet_html, test_tweet_symbols_object, - test_tweet_compat_object, test_tweet_extended_object, - test_tweet_extended_html, test_tweet_identical_urls, test_tweet_reply, - unittest -) +from .config import unittest import responses import requests @@ -303,66 +298,6 @@ class TwythonAPITestCase(unittest.TestCase): """Test encoding UTF-8 works""" self.api.encode('Twython is awesome!') - def test_html_for_tweet(self): - """Test HTML for Tweet returns what we want""" - tweet_text = self.api.html_for_tweet(test_tweet_object) - self.assertEqual(test_tweet_html, tweet_text) - - def test_html_for_tweet_reply(self): - """Test HTML for Tweet links the replied-to username.""" - tweet_text = self.api.html_for_tweet(test_tweet_reply) - self.assertEqual(tweet_text, - u'@philgyford Here’s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr') - - def test_html_for_tweet_expanded_url(self): - """Test using expanded url in HTML for Tweet displays full urls""" - tweet_text = self.api.html_for_tweet(test_tweet_object, - use_expanded_url=True) - # Make sure full url is in HTML - self.assertTrue('http://google.com' in tweet_text) - - 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('http://google.com' not in tweet_text) - self.assertTrue('google.com' not in tweet_text) - - def test_html_for_tweet_identical_urls(self): - """If the 'url's for different url entities are identical, they should link correctly.""" - tweet_text = self.api.html_for_tweet(test_tweet_identical_urls) - self.assertEqual(tweet_text, - u'Use Cases, Trials and Making 5G a Reality buff.ly/2sEhrgO #5G #innovation via @5GWorldSeries buff.ly/2sEhrgO') - - def test_html_for_tweet_symbols(self): - tweet_text = self.api.html_for_tweet(test_tweet_symbols_object) - # Should only link symbols listed in entities: - self.assertTrue('$AAPL' in tweet_text) - self.assertTrue('$ANOTHER' not in tweet_text) - - def test_html_for_tweet_no_symbols(self): - """Should still work if tweet object has no symbols list""" - tweet = test_tweet_symbols_object - # Save a copy: - symbols = tweet['entities']['symbols'] - del tweet['entities']['symbols'] - tweet_text = self.api.html_for_tweet(tweet) - self.assertTrue('symbols: $AAPL and' in tweet_text) - self.assertTrue('and $ANOTHER and $A.' in tweet_text) - # Put the symbols back: - test_tweet_symbols_object['entities']['symbols'] = symbols - - def test_html_for_tweet_compatmode(self): - tweet_text = self.api.html_for_tweet(test_tweet_compat_object) - # link to compat web status link - self.assertTrue( - u'twitter.com/i/web/status/7…' in tweet_text) - - def test_html_for_tweet_extendedmode(self): - tweet_text = self.api.html_for_tweet(test_tweet_extended_object) - # full tweet rendered with suffix - self.assertEqual(test_tweet_extended_html, tweet_text) - def test_cursor_requires_twython_function(self): """Test that cursor() raises when called without a Twython function""" def init_and_iterate_cursor(*args, **kwargs): @@ -374,3 +309,4 @@ class TwythonAPITestCase(unittest.TestCase): self.assertRaises(TypeError, init_and_iterate_cursor, non_function) self.assertRaises(TwythonError, init_and_iterate_cursor, non_twython_function) + diff --git a/tests/test_html_for_tweet.py b/tests/test_html_for_tweet.py new file mode 100644 index 0000000..b8b5dc4 --- /dev/null +++ b/tests/test_html_for_tweet.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +from twython import Twython, TwythonError + +from .config import ( + test_tweet_object, test_tweet_html, test_tweet_symbols_object, + test_tweet_compat_object, test_tweet_extended_object, + test_tweet_extended_html, test_tweet_identical_urls, test_tweet_reply, + unittest +) + + +class TestHtmlForTweetTestCase(unittest.TestCase): + def setUp(self): + self.api = Twython('', '', '', '') + + def test_basic(self): + """Test HTML for Tweet returns what we want""" + tweet_text = self.api.html_for_tweet(test_tweet_object) + self.assertEqual(test_tweet_html, tweet_text) + + def test_reply(self): + """Test HTML for Tweet links the replied-to username.""" + tweet_text = self.api.html_for_tweet(test_tweet_reply) + self.assertEqual(tweet_text, + u'@philgyford Here’s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr') + + def test_expanded_url(self): + """Test using expanded url in HTML for Tweet displays full urls""" + tweet_text = self.api.html_for_tweet(test_tweet_object, + use_expanded_url=True) + # Make sure full url is in HTML + self.assertTrue('http://google.com' in tweet_text) + + def test_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('http://google.com' not in tweet_text) + self.assertTrue('google.com' not in tweet_text) + + def test_identical_urls(self): + """If the 'url's for different url entities are identical, they should link correctly.""" + tweet_text = self.api.html_for_tweet(test_tweet_identical_urls) + self.assertEqual(tweet_text, + u'Use Cases, Trials and Making 5G a Reality buff.ly/2sEhrgO #5G #innovation via @5GWorldSeries buff.ly/2sEhrgO') + + def test_symbols(self): + tweet_text = self.api.html_for_tweet(test_tweet_symbols_object) + # Should only link symbols listed in entities: + self.assertTrue('$AAPL' in tweet_text) + self.assertTrue('$ANOTHER' not in tweet_text) + + def test_no_symbols(self): + """Should still work if tweet object has no symbols list""" + tweet = test_tweet_symbols_object + # Save a copy: + symbols = tweet['entities']['symbols'] + del tweet['entities']['symbols'] + tweet_text = self.api.html_for_tweet(tweet) + self.assertTrue('symbols: $AAPL and' in tweet_text) + self.assertTrue('and $ANOTHER and $A.' in tweet_text) + # Put the symbols back: + test_tweet_symbols_object['entities']['symbols'] = symbols + + def test_compatmode(self): + tweet_text = self.api.html_for_tweet(test_tweet_compat_object) + # link to compat web status link + self.assertTrue( + u'twitter.com/i/web/status/7…' in tweet_text) + + def test_extendedmode(self): + tweet_text = self.api.html_for_tweet(test_tweet_extended_object) + # full tweet rendered with suffix + self.assertEqual(test_tweet_extended_html, tweet_text) From a27efd9da8b6eb7350d650c0fc14aca80c32b466 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Sat, 7 Oct 2017 18:38:20 +0100 Subject: [PATCH 2/8] Fix html_for_tweet()s handling of media URLs We were trying to link to each media item using its `url`/`expanded_url`. But there is only one of these, shared across all of a tweet's media items. So attempting to put it in several times, in the same location, was a bit of a mess! So it now only puts the `url`/`expanded_url` in once, no matter how many media items there are. --- tests/config.py | 1 + tests/test_html_for_tweet.py | 9 +++ tweet.json | 142 +++++++++++++++++++++++++++++++++++ twython/api.py | 38 +++++----- 4 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 tweet.json diff --git a/tests/config.py b/tests/config.py index c3ea809..07ca96d 100644 --- a/tests/config.py +++ b/tests/config.py @@ -39,3 +39,4 @@ test_tweet_identical_urls = {u'entities': {u'hashtags': [], u'user_mentions': [] test_tweet_reply = { u'display_text_range': [12,114], u'in_reply_to_status_id_str':u'742374355531923456', u'source':u'web', u'geo':None, u'full_text':u'@philgyford Here\u2019s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr', u'extended_entities':{ u'media':[] }, u'id_str':u'300', u'in_reply_to_status_id':742374355531923456, u'id':300, u'in_reply_to_screen_name':u'philgyford', u'retweet_count':0, u'user':{ }, u'created_at':u'Mon Jun 13 15:48:06 +0000 2016', u'lang':u'en', u'favorite_count':0, u'coordinates':None, u'place':None, u'contributors':None, u'in_reply_to_user_id':12552, u'in_reply_to_user_id_str':u'12552', u'retweeted':False, u'favorited':False, u'truncated':False, u'entities':{ u'user_mentions':[ { u'id_str':u'12552', u'id':12552, u'screen_name':u'philgyford', u'name':u'Phil Gyford', u'indices':[ 0, 11 ] } ], u'media':[ ], u'hashtags':[ ], u'symbols':[ ], u'urls':[ ] }, u'is_quote_status':False, u'possibly_sensitive':False } +test_tweet_media = {'user': {'name': 'Phil Gyford', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', 'verified': False, 'screen_name': 'philgyford', 'id': 12552, 'id_str': '12552', 'protected': False}, 'geo': {}, 'id': 905105588279013377, 'text': 'I made some D3.js charts showing the years covered by books in a series compared to their publishing dates https://t.co/2yUmmn3TOc https://t.co/OwNc6uJklg', 'entities': {'user_mentions': [], 'hashtags': [], 'media': [{'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'id': 905105571765944320, 'media_url': 'http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'sizes': [{'h': 256, 'w': 680, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105571765944320'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'id': 905105572529393668, 'media_url': 'http://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'sizes': [{'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 271, 'w': 680, 'resize': 'fit'}, {'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 399, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105572529393668'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'id': 905105573255016448, 'media_url': 'http://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'sizes': [{'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 195, 'w': 680, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 287, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105573255016448'}], 'urls': [{'display_url': 'gyford.com/phil/writing/2…', 'url': 'https://t.co/2yUmmn3TOc', 'indices': [107, 130], 'expanded_url': 'http://www.gyford.com/phil/writing/2017/09/05/book-series-charts.php'}]}, 'source': 'web', 'created_at': '2017-09-05 16:29:22 +0000', 'id_str': '905105588279013377'} diff --git a/tests/test_html_for_tweet.py b/tests/test_html_for_tweet.py index b8b5dc4..dc44047 100644 --- a/tests/test_html_for_tweet.py +++ b/tests/test_html_for_tweet.py @@ -5,6 +5,7 @@ from .config import ( test_tweet_object, test_tweet_html, test_tweet_symbols_object, test_tweet_compat_object, test_tweet_extended_object, test_tweet_extended_html, test_tweet_identical_urls, test_tweet_reply, + test_tweet_media, unittest ) @@ -72,3 +73,11 @@ class TestHtmlForTweetTestCase(unittest.TestCase): tweet_text = self.api.html_for_tweet(test_tweet_extended_object) # full tweet rendered with suffix self.assertEqual(test_tweet_extended_html, tweet_text) + + def test_media(self): + tweet_text = self.api.html_for_tweet(test_tweet_media) + + self.assertEqual( + """I made some D3.js charts showing the years covered by books in a series compared to their publishing dates gyford.com/phil/writing/2… pic.twitter.com/OwNc6uJklg""", + tweet_text) + diff --git a/tweet.json b/tweet.json new file mode 100644 index 0000000..5e61ed8 --- /dev/null +++ b/tweet.json @@ -0,0 +1,142 @@ +{ + "source":"web", + "entities":{ + "user_mentions":[ ], + "media":[ + { + "expanded_url":"https://twitter.com/philgyford/status/905105588279013377/photo/1", + "indices":[ 131, 154 ], + "url":"https://t.co/OwNc6uJklg", + "media_url":"http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg", + "id_str":"905105571765944320", + "id":905105571765944320, + "media_url_https":"https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg", + "sizes":[ + { + "h":256, + "resize":"fit", + "w":680 + }, + { + "h":376, + "resize":"fit", + "w":1000 + }, + { + "h":150, + "resize":"crop", + "w":150 + }, + { + "h":376, + "resize":"fit", + "w":1000 + }, + { + "h":376, + "resize":"fit", + "w":1000 + } + ], + "display_url":"pic.twitter.com/OwNc6uJklg" + }, + { + "expanded_url":"https://twitter.com/philgyford/status/905105588279013377/photo/1", + "indices":[ 131, 154 ], + "url":"https://t.co/OwNc6uJklg", + "media_url":"http://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg", + "id_str":"905105572529393668", + "id":905105572529393668, + "media_url_https":"https://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg", + "sizes":[ + { + "h":399, + "resize":"fit", + "w":1000 + }, + { + "h":271, + "resize":"fit", + "w":680 + }, + { + "h":399, + "resize":"fit", + "w":1000 + }, + { + "h":150, + "resize":"crop", + "w":150 + }, + { + "h":399, + "resize":"fit", + "w":1000 + } + ], + "display_url":"pic.twitter.com/OwNc6uJklg" + }, + { + "expanded_url":"https://twitter.com/philgyford/status/905105588279013377/photo/1", + "indices":[ 131, 154 ], + "url":"https://t.co/OwNc6uJklg", + "media_url":"http://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg", + "id_str":"905105573255016448", + "id":905105573255016448, + "media_url_https":"https://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg", + "sizes":[ + { + "h":287, + "resize":"fit", + "w":1000 + }, + { + "h":195, + "resize":"fit", + "w":680 + }, + { + "h":150, + "resize":"crop", + "w":150 + }, + { + "h":287, + "resize":"fit", + "w":1000 + }, + { + "h":287, + "resize":"fit", + "w":1000 + } + ], + "display_url":"pic.twitter.com/OwNc6uJklg" + } + ], + "hashtags":[ ], + "urls":[ + { + "indices":[ 107, 130 ], + "url":"https://t.co/2yUmmn3TOc", + "expanded_url":"http://www.gyford.com/phil/writing/2017/09/05/book-series-charts.php", + "display_url":"gyford.com/phil/writing/2\u2026" + } + ] + }, + "geo":{ }, + "id_str":"905105588279013377", + "text":"I made some D3.js charts showing the years covered by books in a series compared to their publishing dates https://t.co/2yUmmn3TOc https://t.co/OwNc6uJklg", + "id":905105588279013377, + "created_at":"2017-09-05 16:29:22 +0000", + "user":{ + "name":"Phil Gyford", + "screen_name":"philgyford", + "protected":false, + "id_str":"12552", + "profile_image_url_https":"https://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg", + "id":12552, + "verified":false + } +} diff --git a/twython/api.py b/twython/api.py index 2782168..fac7928 100644 --- a/twython/api.py +++ b/twython/api.py @@ -629,26 +629,30 @@ class Twython(EndpointsMixin, object): else: suffix_text = suffix_text.replace(orig_tweet_text[temp['start']:temp['end']], url_html) - if 'media' in tweet['entities']: - for entity in tweet['entities']['media']: - temp = {} - temp['start'] = entity['indices'][0] - temp['end'] = entity['indices'][1] + if 'media' in tweet['entities'] and len(tweet['entities']['media']) > 0: + # We just link to the overall URL for the tweet's media, + # rather than to each individual item. + # So, we get the URL from the first media item: + entity = tweet['entities']['media'][0] - if use_display_url and entity.get('display_url') and not use_expanded_url: - shown_url = entity['display_url'] - elif use_expanded_url and entity.get('expanded_url'): - shown_url = entity['expanded_url'] - else: - shown_url = entity['url'] + temp = {} + temp['start'] = entity['indices'][0] + temp['end'] = entity['indices'][1] - url_html = '%s' % (entity['url'], shown_url) + if use_display_url and entity.get('display_url') and not use_expanded_url: + shown_url = entity['display_url'] + elif use_expanded_url and entity.get('expanded_url'): + shown_url = entity['expanded_url'] + else: + shown_url = entity['url'] - if display_text_start <= temp['start'] <= display_text_end: - temp['replacement'] = url_html - entities.append(temp) - else: - suffix_text = suffix_text.replace(orig_tweet_text[temp['start']:temp['end']], url_html) + url_html = '%s' % (entity['url'], shown_url) + + if display_text_start <= temp['start'] <= display_text_end: + temp['replacement'] = url_html + entities.append(temp) + else: + suffix_text = suffix_text.replace(orig_tweet_text[temp['start']:temp['end']], url_html) # Now do all the replacements, starting from the end, so that the # start/end indices still work: From 13fd0a868436a1b38b7422c04da1755d94e6e1a8 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Tue, 10 Oct 2017 11:57:03 +0100 Subject: [PATCH 3/8] Define encoding for tests config file --- tests/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/config.py b/tests/config.py index 07ca96d..7fc4759 100644 --- a/tests/config.py +++ b/tests/config.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import os import sys From 9ade0946b58c4243759a393e35f87bd499134e5f Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Tue, 10 Oct 2017 12:24:09 +0100 Subject: [PATCH 4/8] Add test for html_for_tweet() for quoted tweets --- tests/config.py | 5 +++++ tests/test_html_for_tweet.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/config.py b/tests/config.py index 7fc4759..795ba07 100644 --- a/tests/config.py +++ b/tests/config.py @@ -34,10 +34,15 @@ test_tweet_symbols_object = {u'text': u'Some symbols: $AAPL and $PEP and $ANOTHE test_tweet_compat_object = {u'contributors': None, u'truncated': True, u'text': u"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count tow\u2026 https://t.co/SRmsuks2ru", u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 777915304261193728, u'favorite_count': 13856, u'source': u'Twitter Web Client', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/SRmsuks2ru', u'indices': [117, 140], u'expanded_url': u'https://twitter.com/i/web/status/777915304261193728', u'display_url': u'twitter.com/i/web/status/7\u2026'}]}, u'in_reply_to_screen_name': None, u'id_str': u'777915304261193728', u'retweet_count': 14767, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'id': 783214, u'verified': True, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'profile_sidebar_fill_color': u'F6F6F6', u'is_translator': False, u'geo_enabled': True, u'entities': {u'url': {u'urls': [{u'url': u'http://t.co/5iRhy7wTgu', u'indices': [0, 22], u'expanded_url': u'http://blog.twitter.com/', u'display_url': u'blog.twitter.com'}]}, u'description': {u'urls': [{u'url': u'https://t.co/qq1HEzvnrA', u'indices': [84, 107], u'expanded_url': u'http://support.twitter.com', u'display_url': u'support.twitter.com'}]}}, u'followers_count': 56827498, u'protected': False, u'location': u'San Francisco, CA', u'default_profile_image': False, u'id_str': u'783214', u'lang': u'en', u'utc_offset': -25200, u'statuses_count': 3161, u'description': u'Your official source for news, updates and tips from Twitter, Inc. Need help? Visit https://t.co/qq1HEzvnrA.', u'friends_count': 145, u'profile_link_color': u'226699', u'profile_image_url': u'http://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'notifications': False, u'profile_background_image_url_https': u'https://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'profile_background_color': u'ACDED6', u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/783214/1471929200', u'profile_background_image_url': u'http://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'name': u'Twitter', u'is_translation_enabled': False, u'profile_background_tile': True, u'favourites_count': 2332, u'screen_name': u'twitter', u'url': u'http://t.co/5iRhy7wTgu', u'created_at': u'Tue Feb 20 14:35:54 +0000 2007', u'contributors_enabled': False, u'time_zone': u'Pacific Time (US & Canada)', u'profile_sidebar_border_color': u'FFFFFF', u'default_profile': False, u'following': False, u'listed_count': 90445}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Mon Sep 19 17:00:36 +0000 2016', u'in_reply_to_status_id_str': None, u'place': None} test_tweet_extended_object = {u'full_text': u"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. https://t.co/I9pUC0NdZC", u'truncated': False, u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 777915304261193728, u'favorite_count': 13856, u'contributors': None, u'source': u'Twitter Web Client', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [], u'media': [{u'expanded_url': u'https://twitter.com/twitter/status/777915304261193728/photo/1', u'sizes': {u'small': {u'h': 340, u'w': 340, u'resize': u'fit'}, u'large': {u'h': 700, u'w': 700, u'resize': u'fit'}, u'medium': {u'h': 600, u'w': 600, u'resize': u'fit'}, u'thumb': {u'h': 150, u'w': 150, u'resize': u'crop'}}, u'url': u'https://t.co/I9pUC0NdZC', u'media_url_https': u'https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'id_str': u'777914712382058496', u'indices': [140, 163], u'media_url': u'http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'type': u'photo', u'id': 777914712382058496, u'display_url': u'pic.twitter.com/I9pUC0NdZC'}]}, u'in_reply_to_screen_name': None, u'id_str': u'777915304261193728', u'display_text_range': [0, 139], u'retweet_count': 14767, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'id': 783214, u'verified': True, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'profile_sidebar_fill_color': u'F6F6F6', u'is_translator': False, u'geo_enabled': True, u'entities': {u'url': {u'urls': [{u'url': u'http://t.co/5iRhy7wTgu', u'indices': [0, 22], u'expanded_url': u'http://blog.twitter.com/', u'display_url': u'blog.twitter.com'}]}, u'description': {u'urls': [{u'url': u'https://t.co/qq1HEzvnrA', u'indices': [84, 107], u'expanded_url': u'http://support.twitter.com', u'display_url': u'support.twitter.com'}]}}, u'followers_count': 56827498, u'protected': False, u'location': u'San Francisco, CA', u'default_profile_image': False, u'id_str': u'783214', u'lang': u'en', u'utc_offset': -25200, u'statuses_count': 3161, u'description': u'Your official source for news, updates and tips from Twitter, Inc. Need help? Visit https://t.co/qq1HEzvnrA.', u'friends_count': 145, u'profile_link_color': u'226699', u'profile_image_url': u'http://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'notifications': False, u'profile_background_image_url_https': u'https://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'profile_background_color': u'ACDED6', u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/783214/1471929200', u'profile_background_image_url': u'http://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'name': u'Twitter', u'is_translation_enabled': False, u'profile_background_tile': True, u'favourites_count': 2332, u'screen_name': u'twitter', u'url': u'http://t.co/5iRhy7wTgu', u'created_at': u'Tue Feb 20 14:35:54 +0000 2007', u'contributors_enabled': False, u'time_zone': u'Pacific Time (US & Canada)', u'profile_sidebar_border_color': u'FFFFFF', u'default_profile': False, u'following': False, u'listed_count': 90445}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Mon Sep 19 17:00:36 +0000 2016', u'in_reply_to_status_id_str': None, u'place': None, u'extended_entities': {u'media': [{u'expanded_url': u'https://twitter.com/twitter/status/777915304261193728/photo/1', u'display_url': u'pic.twitter.com/I9pUC0NdZC', u'url': u'https://t.co/I9pUC0NdZC', u'media_url_https': u'https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'video_info': {u'aspect_ratio': [1, 1], u'variants': [{u'url': u'https://pbs.twimg.com/tweet_video/Csu1TzEVMAAAEv7.mp4', u'bitrate': 0, u'content_type': u'video/mp4'}]}, u'id_str': u'777914712382058496', u'sizes': {u'small': {u'h': 340, u'w': 340, u'resize': u'fit'}, u'large': {u'h': 700, u'w': 700, u'resize': u'fit'}, u'medium': {u'h': 600, u'w': 600, u'resize': u'fit'}, u'thumb': {u'h': 150, u'w': 150, u'resize': u'crop'}}, u'indices': [140, 163], u'type': u'animated_gif', u'id': 777914712382058496, u'media_url': u'http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg'}]}} + test_tweet_extended_html = 'Say more about what\'s happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. pic.twitter.com/I9pUC0NdZC' test_tweet_identical_urls = {u'entities': {u'hashtags': [], u'user_mentions': [], u'symbols': [], u'urls': [{u'display_url': u'buff.ly/2sEhrgO', u'expanded_url': u'http://buff.ly/2sEhrgO', u'indices': [42, 65], u'url': u'https://t.co/W0uArTMk9N'}, {u'display_url': u'buff.ly/2sEhrgO', u'expanded_url': u'http://buff.ly/2sEhrgO', u'indices': [101, 124], u'url': u'https://t.co/W0uArTMk9N'}]}, u'full_text': u'Use Cases, Trials and Making 5G a Reality https://t.co/W0uArTMk9N #5G #innovation via @5GWorldSeries https://t.co/W0uArTMk9N'} test_tweet_reply = { u'display_text_range': [12,114], u'in_reply_to_status_id_str':u'742374355531923456', u'source':u'web', u'geo':None, u'full_text':u'@philgyford Here\u2019s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr', u'extended_entities':{ u'media':[] }, u'id_str':u'300', u'in_reply_to_status_id':742374355531923456, u'id':300, u'in_reply_to_screen_name':u'philgyford', u'retweet_count':0, u'user':{ }, u'created_at':u'Mon Jun 13 15:48:06 +0000 2016', u'lang':u'en', u'favorite_count':0, u'coordinates':None, u'place':None, u'contributors':None, u'in_reply_to_user_id':12552, u'in_reply_to_user_id_str':u'12552', u'retweeted':False, u'favorited':False, u'truncated':False, u'entities':{ u'user_mentions':[ { u'id_str':u'12552', u'id':12552, u'screen_name':u'philgyford', u'name':u'Phil Gyford', u'indices':[ 0, 11 ] } ], u'media':[ ], u'hashtags':[ ], u'symbols':[ ], u'urls':[ ] }, u'is_quote_status':False, u'possibly_sensitive':False } + test_tweet_media = {'user': {'name': 'Phil Gyford', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', 'verified': False, 'screen_name': 'philgyford', 'id': 12552, 'id_str': '12552', 'protected': False}, 'geo': {}, 'id': 905105588279013377, 'text': 'I made some D3.js charts showing the years covered by books in a series compared to their publishing dates https://t.co/2yUmmn3TOc https://t.co/OwNc6uJklg', 'entities': {'user_mentions': [], 'hashtags': [], 'media': [{'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'id': 905105571765944320, 'media_url': 'http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'sizes': [{'h': 256, 'w': 680, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105571765944320'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'id': 905105572529393668, 'media_url': 'http://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'sizes': [{'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 271, 'w': 680, 'resize': 'fit'}, {'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 399, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105572529393668'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'id': 905105573255016448, 'media_url': 'http://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'sizes': [{'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 195, 'w': 680, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 287, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105573255016448'}], 'urls': [{'display_url': 'gyford.com/phil/writing/2…', 'url': 'https://t.co/2yUmmn3TOc', 'indices': [107, 130], 'expanded_url': 'http://www.gyford.com/phil/writing/2017/09/05/book-series-charts.php'}]}, 'source': 'web', 'created_at': '2017-09-05 16:29:22 +0000', 'id_str': '905105588279013377'} + +test_tweet_quoted = {u'contributors': None, u'truncated': False, u'text': u'Here\u2019s a quoted tweet. https://t.co/3neKzof0gT', u'is_quote_status': True, u'in_reply_to_status_id': None, u'id': 917706313785905157, u'favorite_count': 0, u'source': u'Tweetbot for Mac', u'quoted_status_id': 917699069916729344, u'retweeted': False, u'coordinates': None, u'quoted_status': {u'contributors': None, u'truncated': False, u'text': u'The quoted tweet text.', u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 917699069916729344, u'favorite_count': 1, u'source': u'web', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': []}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917699069916729344', u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': False, u'default_profile_image': False, u'id': 12552, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'verified': False, u'translator_type': u'none', u'profile_text_color': u'000000', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', u'profile_sidebar_fill_color': u'EEEEEE', u'entities': {u'url': {u'urls': [{u'url': u'https://t.co/FsYzXrATit', u'indices': [0, 23], u'expanded_url': u'http://www.gyford.com', u'display_url': u'gyford.com'}]}, u'description': {u'urls': []}}, u'followers_count': 2615, u'profile_sidebar_border_color': u'FFFFFF', u'id_str': u'12552', u'profile_background_color': u'C0C0C0', u'listed_count': 130, u'is_translation_enabled': False, u'utc_offset': 3600, u'statuses_count': 19182, u'description': u'Revised and updated edition for 2004.', u'friends_count': 308, u'location': u'London, UK', u'profile_link_color': u'0000FF', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', u'following': False, u'geo_enabled': True, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'philgyford', u'lang': u'en-gb', u'profile_background_tile': False, u'favourites_count': 2203, u'name': u'Phil Gyford', u'notifications': False, u'url': u'https://t.co/FsYzXrATit', u'created_at': u'Wed Nov 15 16:55:59 +0000 2006', u'contributors_enabled': False, u'time_zone': u'London', u'protected': False, u'default_profile': False, u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'lang': u'ht', u'created_at': u'Tue Oct 10 10:31:22 +0000 2017', u'in_reply_to_status_id_str': None, u'place': None}, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/3neKzof0gT', u'indices': [23, 46], u'expanded_url': u'https://twitter.com/philgyford/status/917699069916729344', u'display_url': u'twitter.com/philgyford/sta\u2026'}]}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917706313785905157', u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'default_profile_image': True, u'id': 2030131, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'verified': False, u'translator_type': u'none', u'profile_text_color': u'000000', u'profile_image_url_https': u'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', u'profile_sidebar_fill_color': u'E0FF92', u'entities': {u'description': {u'urls': [{u'url': u'https://t.co/FsYzXrATit', u'indices': [17, 40], u'expanded_url': u'http://www.gyford.com', u'display_url': u'gyford.com'}]}}, u'followers_count': 12, u'profile_sidebar_border_color': u'000000', u'id_str': u'2030131', u'profile_background_color': u'9AE4E8', u'listed_count': 4, u'is_translation_enabled': False, u'utc_offset': 3600, u'statuses_count': 497, u'description': u'Testing #testing https://t.co/FsYzXrATit $IBM #test @philgyford', u'friends_count': 18, u'location': u'', u'profile_link_color': u'0000FF', u'profile_image_url': u'http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', u'following': True, u'geo_enabled': True, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'philgyfordtest', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 0, u'name': u'Phil Gyford Test', u'notifications': False, u'url': None, u'created_at': u'Fri Mar 23 16:56:52 +0000 2007', u'contributors_enabled': False, u'time_zone': u'London', 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'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Tue Oct 10 11:00:10 +0000 2017', u'quoted_status_id_str': u'917699069916729344', u'in_reply_to_status_id_str': None, u'place': None} + diff --git a/tests/test_html_for_tweet.py b/tests/test_html_for_tweet.py index dc44047..6f1ffea 100644 --- a/tests/test_html_for_tweet.py +++ b/tests/test_html_for_tweet.py @@ -5,7 +5,7 @@ from .config import ( test_tweet_object, test_tweet_html, test_tweet_symbols_object, test_tweet_compat_object, test_tweet_extended_object, test_tweet_extended_html, test_tweet_identical_urls, test_tweet_reply, - test_tweet_media, + test_tweet_media, test_tweet_quoted, unittest ) @@ -81,3 +81,12 @@ class TestHtmlForTweetTestCase(unittest.TestCase): """I made some D3.js charts showing the years covered by books in a series compared to their publishing dates gyford.com/phil/writing/2… pic.twitter.com/OwNc6uJklg""", tweet_text) + def test_quoted(self): + "With expand_quoted_status=True it should include a quoted tweet." + tweet_text = self.api.html_for_tweet(test_tweet_quoted, + expand_quoted_status=True) + + self.assertEqual( + u"""Here\u2019s a quoted tweet. twitter.com/philgyford/sta\u2026
The quoted tweet text.Phil Gyford@philgyford
""", + tweet_text) + From 9ccdb48248c6ed033da60fc740fcfd8b808a94a3 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Tue, 10 Oct 2017 12:31:57 +0100 Subject: [PATCH 5/8] Add test for html_for_tweet() for retweets --- tests/config.py | 2 ++ tests/test_html_for_tweet.py | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/config.py b/tests/config.py index 795ba07..d4fc471 100644 --- a/tests/config.py +++ b/tests/config.py @@ -46,3 +46,5 @@ test_tweet_media = {'user': {'name': 'Phil Gyford', 'profile_image_url_https': ' test_tweet_quoted = {u'contributors': None, u'truncated': False, u'text': u'Here\u2019s a quoted tweet. https://t.co/3neKzof0gT', u'is_quote_status': True, u'in_reply_to_status_id': None, u'id': 917706313785905157, u'favorite_count': 0, u'source': u'Tweetbot for Mac', u'quoted_status_id': 917699069916729344, u'retweeted': False, u'coordinates': None, u'quoted_status': {u'contributors': None, u'truncated': False, u'text': u'The quoted tweet text.', u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 917699069916729344, u'favorite_count': 1, u'source': u'web', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': []}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917699069916729344', u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': False, u'default_profile_image': False, u'id': 12552, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'verified': False, u'translator_type': u'none', u'profile_text_color': u'000000', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', u'profile_sidebar_fill_color': u'EEEEEE', u'entities': {u'url': {u'urls': [{u'url': u'https://t.co/FsYzXrATit', u'indices': [0, 23], u'expanded_url': u'http://www.gyford.com', u'display_url': u'gyford.com'}]}, u'description': {u'urls': []}}, u'followers_count': 2615, u'profile_sidebar_border_color': u'FFFFFF', u'id_str': u'12552', u'profile_background_color': u'C0C0C0', u'listed_count': 130, u'is_translation_enabled': False, u'utc_offset': 3600, u'statuses_count': 19182, u'description': u'Revised and updated edition for 2004.', u'friends_count': 308, u'location': u'London, UK', u'profile_link_color': u'0000FF', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', u'following': False, u'geo_enabled': True, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'philgyford', u'lang': u'en-gb', u'profile_background_tile': False, u'favourites_count': 2203, u'name': u'Phil Gyford', u'notifications': False, u'url': u'https://t.co/FsYzXrATit', u'created_at': u'Wed Nov 15 16:55:59 +0000 2006', u'contributors_enabled': False, u'time_zone': u'London', u'protected': False, u'default_profile': False, u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'lang': u'ht', u'created_at': u'Tue Oct 10 10:31:22 +0000 2017', u'in_reply_to_status_id_str': None, u'place': None}, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/3neKzof0gT', u'indices': [23, 46], u'expanded_url': u'https://twitter.com/philgyford/status/917699069916729344', u'display_url': u'twitter.com/philgyford/sta\u2026'}]}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917706313785905157', u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'default_profile_image': True, u'id': 2030131, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'verified': False, u'translator_type': u'none', u'profile_text_color': u'000000', u'profile_image_url_https': u'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', u'profile_sidebar_fill_color': u'E0FF92', u'entities': {u'description': {u'urls': [{u'url': u'https://t.co/FsYzXrATit', u'indices': [17, 40], u'expanded_url': u'http://www.gyford.com', u'display_url': u'gyford.com'}]}}, u'followers_count': 12, u'profile_sidebar_border_color': u'000000', u'id_str': u'2030131', u'profile_background_color': u'9AE4E8', u'listed_count': 4, u'is_translation_enabled': False, u'utc_offset': 3600, u'statuses_count': 497, u'description': u'Testing #testing https://t.co/FsYzXrATit $IBM #test @philgyford', u'friends_count': 18, u'location': u'', u'profile_link_color': u'0000FF', u'profile_image_url': u'http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', u'following': True, u'geo_enabled': True, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'philgyfordtest', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 0, u'name': u'Phil Gyford Test', u'notifications': False, u'url': None, u'created_at': u'Fri Mar 23 16:56:52 +0000 2007', u'contributors_enabled': False, u'time_zone': u'London', 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'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Tue Oct 10 11:00:10 +0000 2017', u'quoted_status_id_str': u'917699069916729344', u'in_reply_to_status_id_str': None, u'place': None} +test_tweet_retweet = {'coordinates': None, 'source': 'Tweetbot for Mac', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 0, 'user': {'has_extended_profile': False, 'following': True, 'url': None, 'profile_background_tile': False, 'geo_enabled': True, 'favourites_count': 0, 'lang': 'en', 'follow_request_sent': False, 'utc_offset': 3600, 'time_zone': 'London', 'profile_sidebar_border_color': '000000', 'verified': False, 'profile_use_background_image': True, 'name': 'Phil Gyford Test', 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png', 'default_profile_image': True, 'friends_count': 18, 'profile_image_url': 'http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', 'profile_image_url_https': 'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', 'default_profile': False, 'screen_name': 'philgyfordtest', 'profile_link_color': '0000FF', 'profile_text_color': '000000', 'id_str': '2030131', 'profile_background_color': '9AE4E8', 'followers_count': 12, 'entities': {'description': {'urls': [{'indices': [17, 40], 'url': 'https://t.co/FsYzXrATit', 'expanded_url': 'http://www.gyford.com', 'display_url': 'gyford.com'}]}}, 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png', 'protected': False, 'notifications': False, 'description': 'Testing #testing https://t.co/FsYzXrATit $IBM #test @philgyford', 'is_translation_enabled': False, 'is_translator': False, 'translator_type': 'none', 'contributors_enabled': False, 'statuses_count': 498, 'listed_count': 4, 'created_at': 'Fri Mar 23 16:56:52 +0000 2007', 'profile_sidebar_fill_color': 'E0FF92', 'id': 2030131, 'location': ''}, 'favorited': False, 'retweeted_status': {'coordinates': None, 'source': 'Pepys\' Diary', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 21, 'user': {'has_extended_profile': False, 'following': True, 'url': 'https://t.co/b5ZyzWwQQA', 'profile_background_tile': False, 'geo_enabled': False, 'favourites_count': 1, 'lang': 'en', 'follow_request_sent': False, 'utc_offset': 3600, 'time_zone': 'London', 'profile_sidebar_border_color': 'CCCCCC', 'verified': False, 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/14475268/1432652170', 'profile_use_background_image': False, 'name': 'Samuel Pepys', 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png', 'default_profile_image': False, 'friends_count': 14, 'profile_image_url': 'http://pbs.twimg.com/profile_images/629231884304695296/VZ-9FQ28_normal.jpg', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/629231884304695296/VZ-9FQ28_normal.jpg', 'default_profile': False, 'screen_name': 'samuelpepys', 'profile_link_color': '549355', 'profile_text_color': '333333', 'id_str': '14475268', 'profile_background_color': 'F1F4EB', 'followers_count': 55980, 'entities': {'description': {'urls': []}, 'url': {'urls': [{'indices': [0, 23], 'url': 'https://t.co/b5ZyzWwQQA', 'expanded_url': 'http://www.pepysdiary.com/', 'display_url': 'pepysdiary.com'}]}}, 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png', 'protected': False, 'notifications': False, 'description': 'The diaries of Samuel Pepys in real time, 1660-69. Currently tweeting the events of 1664. Run by @philgyford.', 'is_translation_enabled': False, 'is_translator': False, 'translator_type': 'none', 'contributors_enabled': False, 'statuses_count': 11060, 'listed_count': 1223, 'created_at': 'Tue Apr 22 14:39:20 +0000 2008', 'profile_sidebar_fill_color': 'E8E7DC', 'id': 14475268, 'location': 'London, UK'}, 'favorited': False, 'id': 917459832885653506, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917459832885653506', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Mon Oct 09 18:40:44 +0000 2017', 'is_quote_status': False, 'retweeted': False}, 'id': 917712989649801216, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917712989649801216', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [{'id_str': '14475268', 'indices': [3, 15], 'name': 'Samuel Pepys', 'id': 14475268, 'screen_name': 'samuelpepys'}], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'RT @samuelpepys: My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Tue Oct 10 11:26:41 +0000 2017', 'is_quote_status': False, 'retweeted': False} + diff --git a/tests/test_html_for_tweet.py b/tests/test_html_for_tweet.py index 6f1ffea..9ba25c6 100644 --- a/tests/test_html_for_tweet.py +++ b/tests/test_html_for_tweet.py @@ -5,7 +5,7 @@ from .config import ( test_tweet_object, test_tweet_html, test_tweet_symbols_object, test_tweet_compat_object, test_tweet_extended_object, test_tweet_extended_html, test_tweet_identical_urls, test_tweet_reply, - test_tweet_media, test_tweet_quoted, + test_tweet_media, test_tweet_quoted, test_tweet_retweet, unittest ) @@ -90,3 +90,11 @@ class TestHtmlForTweetTestCase(unittest.TestCase): u"""Here\u2019s a quoted tweet. twitter.com/philgyford/sta\u2026
The quoted tweet text.Phil Gyford@philgyford
""", tweet_text) + def test_retweet(self): + "With expand_quoted_status=True it should include a quoted tweet." + tweet_text = self.api.html_for_tweet(test_tweet_retweet) + + self.assertEqual( + u"""My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.""", + tweet_text) + From 5c55aa88449a7110da1e1c4fea130d9109f303a6 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Tue, 10 Oct 2017 12:41:00 +0100 Subject: [PATCH 6/8] Cut some un-needed data out of the test tweet objects --- tests/config.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/config.py b/tests/config.py index d4fc471..4d76d1c 100644 --- a/tests/config.py +++ b/tests/config.py @@ -28,11 +28,12 @@ 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 shd #checkitout. Love, @__twython__ https://t.co/67pwRvY6z9 http://t.co/N6InAO4B71', 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': [81, 93], 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': [62, 73], u'text': u'checkitout'}], 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': [94, 117], u'expanded_url': u'https://github.com', u'display_url': u'github.com'}], u'media': [{u'id': 537884378513162240, u'id_str': u'537884378513162240', u'indices': [118, 140], u'media_url': u'http://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg', u'media_url_https': u'https://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg', u'url': u'http://t.co/N6InAO4B71', u'display_url': u'pic.twitter.com/N6InAO4B71', u'expanded_url': u'http://twitter.com/pingofglitch/status/537884380060844032/photo/1', u'type': u'photo', u'sizes': {u'large': {u'w': 1024, u'h': 640, u'resize': u'fit'}, u'thumb': {u'w': 150, u'h': 150, u'resize': u'crop'}, u'medium': {u'w': 600, u'h': 375, u'resize': u'fit'}, u'small': {u'w': 340, u'h': 212, u'resize': u'fit'}}}]}, 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 = 'google.com is a #cool site, lol! @mikehelmick shd #checkitout. Love, @__twython__ github.com pic.twitter.com/N6InAO4B71' -test_tweet_symbols_object = {u'text': u'Some symbols: $AAPL and $PEP and $ANOTHER and $A.', u'contributors': None, u'geo': None, u'favorited': True, u'in_reply_to_user_id_str': None, u'user': {u'location': u'', u'id_str': u'2030131', u'protected': False, u'profile_background_tile': False, u'friends_count': 18, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'entities': {u'description': {u'urls': []}}, u'lang': u'en', u'listed_count': 5, u'default_profile_image': True, u'default_profile': False, u'statuses_count': 447, u'notifications': False, u'profile_background_color': u'9AE4E8', u'profile_sidebar_fill_color': u'E0FF92', u'profile_link_color': u'0000FF', u'profile_image_url_https': u'https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png', u'followers_count': 8, u'geo_enabled': True, u'following': True, u'has_extended_profile': False, u'profile_use_background_image': True, u'profile_text_color': u'000000', u'screen_name': u'philgyfordtest', u'contributors_enabled': False, u'verified': False, u'name': u'Phil Gyford Test', u'profile_sidebar_border_color': u'000000', u'utc_offset': 0, u'profile_image_url': u'http://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png', u'id': 2030131, u'favourites_count': 0, u'time_zone': u'London', u'url': None, u'is_translation_enabled': False, u'is_translator': False, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'description': u'', u'created_at': u'Fri Mar 23 16:56:52 +0000 2007', u'follow_request_sent': False}, u'in_reply_to_user_id': None, u'retweeted': False, u'coordinates': None, u'place': None, u'in_reply_to_status_id': None, u'lang': u'en', u'in_reply_to_status_id_str': None, u'truncated': False, u'retweet_count': 0, u'is_quote_status': False, u'id': 662694880657989632, u'id_str': u'662694880657989632', u'in_reply_to_screen_name': None, u'favorite_count': 1, u'entities': {u'hashtags': [], u'user_mentions': [], u'symbols': [{u'indices': [14, 19], u'text': u'AAPL'}, {u'indices': [24, 28], u'text': u'PEP'}, {u'indices': [46, 48], u'text': u'A'}], u'urls': []}, u'created_at': u'Fri Nov 06 18:15:46 +0000 2015', u'source': u'Tweetbot for Mac'} +test_tweet_symbols_object = {u'text': u'Some symbols: $AAPL and $PEP and $ANOTHER and $A.', u'contributors': None, u'geo': None, u'favorited': True, u'in_reply_to_user_id_str': None, u'user': {u'screen_name': u'philgyfordtest', u'name': u'Phil Gyford Test'}, u'in_reply_to_user_id': None, u'retweeted': False, u'coordinates': None, u'place': None, u'in_reply_to_status_id': None, u'lang': u'en', u'in_reply_to_status_id_str': None, u'truncated': False, u'retweet_count': 0, u'is_quote_status': False, u'id': 662694880657989632, u'id_str': u'662694880657989632', u'in_reply_to_screen_name': None, u'favorite_count': 1, u'entities': {u'hashtags': [], u'user_mentions': [], u'symbols': [{u'indices': [14, 19], u'text': u'AAPL'}, {u'indices': [24, 28], u'text': u'PEP'}, {u'indices': [46, 48], u'text': u'A'}], u'urls': []}, u'created_at': u'Fri Nov 06 18:15:46 +0000 2015', u'source': u'web'} -test_tweet_compat_object = {u'contributors': None, u'truncated': True, u'text': u"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count tow\u2026 https://t.co/SRmsuks2ru", u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 777915304261193728, u'favorite_count': 13856, u'source': u'Twitter Web Client', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/SRmsuks2ru', u'indices': [117, 140], u'expanded_url': u'https://twitter.com/i/web/status/777915304261193728', u'display_url': u'twitter.com/i/web/status/7\u2026'}]}, u'in_reply_to_screen_name': None, u'id_str': u'777915304261193728', u'retweet_count': 14767, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'id': 783214, u'verified': True, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'profile_sidebar_fill_color': u'F6F6F6', u'is_translator': False, u'geo_enabled': True, u'entities': {u'url': {u'urls': [{u'url': u'http://t.co/5iRhy7wTgu', u'indices': [0, 22], u'expanded_url': u'http://blog.twitter.com/', u'display_url': u'blog.twitter.com'}]}, u'description': {u'urls': [{u'url': u'https://t.co/qq1HEzvnrA', u'indices': [84, 107], u'expanded_url': u'http://support.twitter.com', u'display_url': u'support.twitter.com'}]}}, u'followers_count': 56827498, u'protected': False, u'location': u'San Francisco, CA', u'default_profile_image': False, u'id_str': u'783214', u'lang': u'en', u'utc_offset': -25200, u'statuses_count': 3161, u'description': u'Your official source for news, updates and tips from Twitter, Inc. Need help? Visit https://t.co/qq1HEzvnrA.', u'friends_count': 145, u'profile_link_color': u'226699', u'profile_image_url': u'http://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'notifications': False, u'profile_background_image_url_https': u'https://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'profile_background_color': u'ACDED6', u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/783214/1471929200', u'profile_background_image_url': u'http://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'name': u'Twitter', u'is_translation_enabled': False, u'profile_background_tile': True, u'favourites_count': 2332, u'screen_name': u'twitter', u'url': u'http://t.co/5iRhy7wTgu', u'created_at': u'Tue Feb 20 14:35:54 +0000 2007', u'contributors_enabled': False, u'time_zone': u'Pacific Time (US & Canada)', u'profile_sidebar_border_color': u'FFFFFF', u'default_profile': False, u'following': False, u'listed_count': 90445}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Mon Sep 19 17:00:36 +0000 2016', u'in_reply_to_status_id_str': None, u'place': None} +test_tweet_compat_object = {u'contributors': None, u'truncated': True, u'text': u"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count tow\u2026 https://t.co/SRmsuks2ru", u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 777915304261193728, u'favorite_count': 13856, u'source': u'Twitter Web Client', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/SRmsuks2ru', u'indices': [117, 140], u'expanded_url': u'https://twitter.com/i/web/status/777915304261193728', u'display_url': u'twitter.com/i/web/status/7\u2026'}]}, u'in_reply_to_screen_name': None, u'id_str': u'777915304261193728', u'retweet_count': 14767, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'name': u'Twitter', u'screen_name': u'twitter'}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Mon Sep 19 17:00:36 +0000 2016', u'in_reply_to_status_id_str': None, u'place': None} test_tweet_extended_object = {u'full_text': u"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. https://t.co/I9pUC0NdZC", u'truncated': False, u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 777915304261193728, u'favorite_count': 13856, u'contributors': None, u'source': u'Twitter Web Client', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [], u'media': [{u'expanded_url': u'https://twitter.com/twitter/status/777915304261193728/photo/1', u'sizes': {u'small': {u'h': 340, u'w': 340, u'resize': u'fit'}, u'large': {u'h': 700, u'w': 700, u'resize': u'fit'}, u'medium': {u'h': 600, u'w': 600, u'resize': u'fit'}, u'thumb': {u'h': 150, u'w': 150, u'resize': u'crop'}}, u'url': u'https://t.co/I9pUC0NdZC', u'media_url_https': u'https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'id_str': u'777914712382058496', u'indices': [140, 163], u'media_url': u'http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'type': u'photo', u'id': 777914712382058496, u'display_url': u'pic.twitter.com/I9pUC0NdZC'}]}, u'in_reply_to_screen_name': None, u'id_str': u'777915304261193728', u'display_text_range': [0, 139], u'retweet_count': 14767, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'id': 783214, u'verified': True, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'profile_sidebar_fill_color': u'F6F6F6', u'is_translator': False, u'geo_enabled': True, u'entities': {u'url': {u'urls': [{u'url': u'http://t.co/5iRhy7wTgu', u'indices': [0, 22], u'expanded_url': u'http://blog.twitter.com/', u'display_url': u'blog.twitter.com'}]}, u'description': {u'urls': [{u'url': u'https://t.co/qq1HEzvnrA', u'indices': [84, 107], u'expanded_url': u'http://support.twitter.com', u'display_url': u'support.twitter.com'}]}}, u'followers_count': 56827498, u'protected': False, u'location': u'San Francisco, CA', u'default_profile_image': False, u'id_str': u'783214', u'lang': u'en', u'utc_offset': -25200, u'statuses_count': 3161, u'description': u'Your official source for news, updates and tips from Twitter, Inc. Need help? Visit https://t.co/qq1HEzvnrA.', u'friends_count': 145, u'profile_link_color': u'226699', u'profile_image_url': u'http://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'notifications': False, u'profile_background_image_url_https': u'https://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'profile_background_color': u'ACDED6', u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/783214/1471929200', u'profile_background_image_url': u'http://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'name': u'Twitter', u'is_translation_enabled': False, u'profile_background_tile': True, u'favourites_count': 2332, u'screen_name': u'twitter', u'url': u'http://t.co/5iRhy7wTgu', u'created_at': u'Tue Feb 20 14:35:54 +0000 2007', u'contributors_enabled': False, u'time_zone': u'Pacific Time (US & Canada)', u'profile_sidebar_border_color': u'FFFFFF', u'default_profile': False, u'following': False, u'listed_count': 90445}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Mon Sep 19 17:00:36 +0000 2016', u'in_reply_to_status_id_str': None, u'place': None, u'extended_entities': {u'media': [{u'expanded_url': u'https://twitter.com/twitter/status/777915304261193728/photo/1', u'display_url': u'pic.twitter.com/I9pUC0NdZC', u'url': u'https://t.co/I9pUC0NdZC', u'media_url_https': u'https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'video_info': {u'aspect_ratio': [1, 1], u'variants': [{u'url': u'https://pbs.twimg.com/tweet_video/Csu1TzEVMAAAEv7.mp4', u'bitrate': 0, u'content_type': u'video/mp4'}]}, u'id_str': u'777914712382058496', u'sizes': {u'small': {u'h': 340, u'w': 340, u'resize': u'fit'}, u'large': {u'h': 700, u'w': 700, u'resize': u'fit'}, u'medium': {u'h': 600, u'w': 600, u'resize': u'fit'}, u'thumb': {u'h': 150, u'w': 150, u'resize': u'crop'}}, u'indices': [140, 163], u'type': u'animated_gif', u'id': 777914712382058496, u'media_url': u'http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg'}]}} test_tweet_extended_html = 'Say more about what\'s happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. pic.twitter.com/I9pUC0NdZC' @@ -42,9 +43,10 @@ test_tweet_identical_urls = {u'entities': {u'hashtags': [], u'user_mentions': [] test_tweet_reply = { u'display_text_range': [12,114], u'in_reply_to_status_id_str':u'742374355531923456', u'source':u'web', u'geo':None, u'full_text':u'@philgyford Here\u2019s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr', u'extended_entities':{ u'media':[] }, u'id_str':u'300', u'in_reply_to_status_id':742374355531923456, u'id':300, u'in_reply_to_screen_name':u'philgyford', u'retweet_count':0, u'user':{ }, u'created_at':u'Mon Jun 13 15:48:06 +0000 2016', u'lang':u'en', u'favorite_count':0, u'coordinates':None, u'place':None, u'contributors':None, u'in_reply_to_user_id':12552, u'in_reply_to_user_id_str':u'12552', u'retweeted':False, u'favorited':False, u'truncated':False, u'entities':{ u'user_mentions':[ { u'id_str':u'12552', u'id':12552, u'screen_name':u'philgyford', u'name':u'Phil Gyford', u'indices':[ 0, 11 ] } ], u'media':[ ], u'hashtags':[ ], u'symbols':[ ], u'urls':[ ] }, u'is_quote_status':False, u'possibly_sensitive':False } -test_tweet_media = {'user': {'name': 'Phil Gyford', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', 'verified': False, 'screen_name': 'philgyford', 'id': 12552, 'id_str': '12552', 'protected': False}, 'geo': {}, 'id': 905105588279013377, 'text': 'I made some D3.js charts showing the years covered by books in a series compared to their publishing dates https://t.co/2yUmmn3TOc https://t.co/OwNc6uJklg', 'entities': {'user_mentions': [], 'hashtags': [], 'media': [{'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'id': 905105571765944320, 'media_url': 'http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'sizes': [{'h': 256, 'w': 680, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105571765944320'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'id': 905105572529393668, 'media_url': 'http://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'sizes': [{'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 271, 'w': 680, 'resize': 'fit'}, {'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 399, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105572529393668'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'id': 905105573255016448, 'media_url': 'http://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'sizes': [{'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 195, 'w': 680, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 287, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105573255016448'}], 'urls': [{'display_url': 'gyford.com/phil/writing/2…', 'url': 'https://t.co/2yUmmn3TOc', 'indices': [107, 130], 'expanded_url': 'http://www.gyford.com/phil/writing/2017/09/05/book-series-charts.php'}]}, 'source': 'web', 'created_at': '2017-09-05 16:29:22 +0000', 'id_str': '905105588279013377'} +test_tweet_media = {'user': {'name': 'Phil Gyford', 'screen_name': 'philgyford'}, 'geo': {}, 'id': 905105588279013377, 'text': 'I made some D3.js charts showing the years covered by books in a series compared to their publishing dates https://t.co/2yUmmn3TOc https://t.co/OwNc6uJklg', 'entities': {'user_mentions': [], 'hashtags': [], 'media': [{'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'id': 905105571765944320, 'media_url': 'http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'sizes': [{'h': 256, 'w': 680, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105571765944320'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'id': 905105572529393668, 'media_url': 'http://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'sizes': [{'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 271, 'w': 680, 'resize': 'fit'}, {'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 399, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105572529393668'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'id': 905105573255016448, 'media_url': 'http://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'sizes': [{'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 195, 'w': 680, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 287, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105573255016448'}], 'urls': [{'display_url': 'gyford.com/phil/writing/2…', 'url': 'https://t.co/2yUmmn3TOc', 'indices': [107, 130], 'expanded_url': 'http://www.gyford.com/phil/writing/2017/09/05/book-series-charts.php'}]}, 'source': 'web', 'created_at': '2017-09-05 16:29:22 +0000', 'id_str': '905105588279013377'} -test_tweet_quoted = {u'contributors': None, u'truncated': False, u'text': u'Here\u2019s a quoted tweet. https://t.co/3neKzof0gT', u'is_quote_status': True, u'in_reply_to_status_id': None, u'id': 917706313785905157, u'favorite_count': 0, u'source': u'Tweetbot for Mac', u'quoted_status_id': 917699069916729344, u'retweeted': False, u'coordinates': None, u'quoted_status': {u'contributors': None, u'truncated': False, u'text': u'The quoted tweet text.', u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 917699069916729344, u'favorite_count': 1, u'source': u'web', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': []}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917699069916729344', u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': False, u'default_profile_image': False, u'id': 12552, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'verified': False, u'translator_type': u'none', u'profile_text_color': u'000000', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', u'profile_sidebar_fill_color': u'EEEEEE', u'entities': {u'url': {u'urls': [{u'url': u'https://t.co/FsYzXrATit', u'indices': [0, 23], u'expanded_url': u'http://www.gyford.com', u'display_url': u'gyford.com'}]}, u'description': {u'urls': []}}, u'followers_count': 2615, u'profile_sidebar_border_color': u'FFFFFF', u'id_str': u'12552', u'profile_background_color': u'C0C0C0', u'listed_count': 130, u'is_translation_enabled': False, u'utc_offset': 3600, u'statuses_count': 19182, u'description': u'Revised and updated edition for 2004.', u'friends_count': 308, u'location': u'London, UK', u'profile_link_color': u'0000FF', u'profile_image_url': u'http://pbs.twimg.com/profile_images/1167616130/james_200208_300x300_normal.jpg', u'following': False, u'geo_enabled': True, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'philgyford', u'lang': u'en-gb', u'profile_background_tile': False, u'favourites_count': 2203, u'name': u'Phil Gyford', u'notifications': False, u'url': u'https://t.co/FsYzXrATit', u'created_at': u'Wed Nov 15 16:55:59 +0000 2006', u'contributors_enabled': False, u'time_zone': u'London', u'protected': False, u'default_profile': False, u'is_translator': False}, u'geo': None, u'in_reply_to_user_id_str': None, u'lang': u'ht', u'created_at': u'Tue Oct 10 10:31:22 +0000 2017', u'in_reply_to_status_id_str': None, u'place': None}, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/3neKzof0gT', u'indices': [23, 46], u'expanded_url': u'https://twitter.com/philgyford/status/917699069916729344', u'display_url': u'twitter.com/philgyford/sta\u2026'}]}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917706313785905157', u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'default_profile_image': True, u'id': 2030131, u'profile_background_image_url_https': u'https://abs.twimg.com/images/themes/theme1/bg.png', u'verified': False, u'translator_type': u'none', u'profile_text_color': u'000000', u'profile_image_url_https': u'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', u'profile_sidebar_fill_color': u'E0FF92', u'entities': {u'description': {u'urls': [{u'url': u'https://t.co/FsYzXrATit', u'indices': [17, 40], u'expanded_url': u'http://www.gyford.com', u'display_url': u'gyford.com'}]}}, u'followers_count': 12, u'profile_sidebar_border_color': u'000000', u'id_str': u'2030131', u'profile_background_color': u'9AE4E8', u'listed_count': 4, u'is_translation_enabled': False, u'utc_offset': 3600, u'statuses_count': 497, u'description': u'Testing #testing https://t.co/FsYzXrATit $IBM #test @philgyford', u'friends_count': 18, u'location': u'', u'profile_link_color': u'0000FF', u'profile_image_url': u'http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', u'following': True, u'geo_enabled': True, u'profile_background_image_url': u'http://abs.twimg.com/images/themes/theme1/bg.png', u'screen_name': u'philgyfordtest', u'lang': u'en', u'profile_background_tile': False, u'favourites_count': 0, u'name': u'Phil Gyford Test', u'notifications': False, u'url': None, u'created_at': u'Fri Mar 23 16:56:52 +0000 2007', u'contributors_enabled': False, u'time_zone': u'London', 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'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Tue Oct 10 11:00:10 +0000 2017', u'quoted_status_id_str': u'917699069916729344', u'in_reply_to_status_id_str': None, u'place': None} +test_tweet_quoted = {u'contributors': None, u'truncated': False, u'text': u'Here\u2019s a quoted tweet. https://t.co/3neKzof0gT', u'is_quote_status': True, u'in_reply_to_status_id': None, u'id': 917706313785905157, u'favorite_count': 0, u'source': u'web', u'quoted_status_id': 917699069916729344, u'retweeted': False, u'coordinates': None, u'quoted_status': {u'contributors': None, u'truncated': False, u'text': u'The quoted tweet text.', u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 917699069916729344, u'favorite_count': 1, u'source': u'web', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': []}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917699069916729344', u'favorited': False, u'user': {u'screen_name': u'philgyford', u'name': u'Phil Gyford'}, u'geo': None, u'in_reply_to_user_id_str': None, u'lang': u'ht', u'created_at': u'Tue Oct 10 10:31:22 +0000 2017', u'in_reply_to_status_id_str': None, u'place': None}, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/3neKzof0gT', u'indices': [23, 46], u'expanded_url': u'https://twitter.com/philgyford/status/917699069916729344', u'display_url': u'twitter.com/philgyford/sta\u2026'}]}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917706313785905157', u'favorited': False, u'user': {u'screen_name': u'philgyfordtest', u'name': u'Phil Gyford Test'}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Tue Oct 10 11:00:10 +0000 2017', u'quoted_status_id_str': u'917699069916729344', u'in_reply_to_status_id_str': None, u'place': None} + +test_tweet_retweet = {'coordinates': None, 'source': 'web', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 0, 'user': {'name': 'Phil Gyford Test', 'screen_name': 'philgyfordtest'}, 'favorited': False, 'retweeted_status': {'coordinates': None, 'source': 'web', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 21, 'user': {'name': 'Samuel Pepys', 'screen_name': 'samuelpepys'}, 'favorited': False, 'id': 917459832885653506, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917459832885653506', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Mon Oct 09 18:40:44 +0000 2017', 'is_quote_status': False, 'retweeted': False}, 'id': 917712989649801216, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917712989649801216', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [{'id_str': '14475268', 'indices': [3, 15], 'name': 'Samuel Pepys', 'id': 14475268, 'screen_name': 'samuelpepys'}], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'RT @samuelpepys: My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Tue Oct 10 11:26:41 +0000 2017', 'is_quote_status': False, 'retweeted': False} -test_tweet_retweet = {'coordinates': None, 'source': 'Tweetbot for Mac', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 0, 'user': {'has_extended_profile': False, 'following': True, 'url': None, 'profile_background_tile': False, 'geo_enabled': True, 'favourites_count': 0, 'lang': 'en', 'follow_request_sent': False, 'utc_offset': 3600, 'time_zone': 'London', 'profile_sidebar_border_color': '000000', 'verified': False, 'profile_use_background_image': True, 'name': 'Phil Gyford Test', 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png', 'default_profile_image': True, 'friends_count': 18, 'profile_image_url': 'http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', 'profile_image_url_https': 'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png', 'default_profile': False, 'screen_name': 'philgyfordtest', 'profile_link_color': '0000FF', 'profile_text_color': '000000', 'id_str': '2030131', 'profile_background_color': '9AE4E8', 'followers_count': 12, 'entities': {'description': {'urls': [{'indices': [17, 40], 'url': 'https://t.co/FsYzXrATit', 'expanded_url': 'http://www.gyford.com', 'display_url': 'gyford.com'}]}}, 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png', 'protected': False, 'notifications': False, 'description': 'Testing #testing https://t.co/FsYzXrATit $IBM #test @philgyford', 'is_translation_enabled': False, 'is_translator': False, 'translator_type': 'none', 'contributors_enabled': False, 'statuses_count': 498, 'listed_count': 4, 'created_at': 'Fri Mar 23 16:56:52 +0000 2007', 'profile_sidebar_fill_color': 'E0FF92', 'id': 2030131, 'location': ''}, 'favorited': False, 'retweeted_status': {'coordinates': None, 'source': 'Pepys\' Diary', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 21, 'user': {'has_extended_profile': False, 'following': True, 'url': 'https://t.co/b5ZyzWwQQA', 'profile_background_tile': False, 'geo_enabled': False, 'favourites_count': 1, 'lang': 'en', 'follow_request_sent': False, 'utc_offset': 3600, 'time_zone': 'London', 'profile_sidebar_border_color': 'CCCCCC', 'verified': False, 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/14475268/1432652170', 'profile_use_background_image': False, 'name': 'Samuel Pepys', 'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png', 'default_profile_image': False, 'friends_count': 14, 'profile_image_url': 'http://pbs.twimg.com/profile_images/629231884304695296/VZ-9FQ28_normal.jpg', 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/629231884304695296/VZ-9FQ28_normal.jpg', 'default_profile': False, 'screen_name': 'samuelpepys', 'profile_link_color': '549355', 'profile_text_color': '333333', 'id_str': '14475268', 'profile_background_color': 'F1F4EB', 'followers_count': 55980, 'entities': {'description': {'urls': []}, 'url': {'urls': [{'indices': [0, 23], 'url': 'https://t.co/b5ZyzWwQQA', 'expanded_url': 'http://www.pepysdiary.com/', 'display_url': 'pepysdiary.com'}]}}, 'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png', 'protected': False, 'notifications': False, 'description': 'The diaries of Samuel Pepys in real time, 1660-69. Currently tweeting the events of 1664. Run by @philgyford.', 'is_translation_enabled': False, 'is_translator': False, 'translator_type': 'none', 'contributors_enabled': False, 'statuses_count': 11060, 'listed_count': 1223, 'created_at': 'Tue Apr 22 14:39:20 +0000 2008', 'profile_sidebar_fill_color': 'E8E7DC', 'id': 14475268, 'location': 'London, UK'}, 'favorited': False, 'id': 917459832885653506, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917459832885653506', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Mon Oct 09 18:40:44 +0000 2017', 'is_quote_status': False, 'retweeted': False}, 'id': 917712989649801216, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917712989649801216', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [{'id_str': '14475268', 'indices': [3, 15], 'name': 'Samuel Pepys', 'id': 14475268, 'screen_name': 'samuelpepys'}], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'RT @samuelpepys: My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Tue Oct 10 11:26:41 +0000 2017', 'is_quote_status': False, 'retweeted': False} From 5a008e7e77eec0016af938d833827332ebfaedc7 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Wed, 11 Oct 2017 18:27:53 +0100 Subject: [PATCH 7/8] Move all the raw tweets for tests into their own JSON files Seems better to have the raw data as JSON, like it comes from the API, then load it into python objects for each test. --- tests/config.py | 23 ---- tests/test_endpoints.py | 2 +- tests/test_html_for_tweet.py | 62 ++++++---- tests/tweets/basic.json | 170 +++++++++++++++++++++++++ tests/tweets/compat.json | 51 ++++++++ tests/tweets/extended.json | 204 ++++++++++++++++++++++++++++++ tests/tweets/identical_urls.json | 34 +++++ tests/tweets/media.json | 205 +++++++++++++++++++++++++++++++ tests/tweets/quoted.json | 94 ++++++++++++++ tests/tweets/reply.json | 62 ++++++++++ tests/tweets/retweet.json | 91 ++++++++++++++ tests/tweets/symbols.json | 61 +++++++++ 12 files changed, 1010 insertions(+), 49 deletions(-) create mode 100644 tests/tweets/basic.json create mode 100644 tests/tweets/compat.json create mode 100644 tests/tweets/extended.json create mode 100644 tests/tweets/identical_urls.json create mode 100644 tests/tweets/media.json create mode 100644 tests/tweets/quoted.json create mode 100644 tests/tweets/reply.json create mode 100644 tests/tweets/retweet.json create mode 100644 tests/tweets/symbols.json diff --git a/tests/config.py b/tests/config.py index 4d76d1c..8812b81 100644 --- a/tests/config.py +++ b/tests/config.py @@ -27,26 +27,3 @@ 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_tweet_object = {u'contributors': None, u'truncated': False, u'text': u'http://t.co/FCmXyI6VHd is a #cool site, lol! @mikehelmick shd #checkitout. Love, @__twython__ https://t.co/67pwRvY6z9 http://t.co/N6InAO4B71', 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': [81, 93], 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': [62, 73], u'text': u'checkitout'}], 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': [94, 117], u'expanded_url': u'https://github.com', u'display_url': u'github.com'}], u'media': [{u'id': 537884378513162240, u'id_str': u'537884378513162240', u'indices': [118, 140], u'media_url': u'http://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg', u'media_url_https': u'https://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg', u'url': u'http://t.co/N6InAO4B71', u'display_url': u'pic.twitter.com/N6InAO4B71', u'expanded_url': u'http://twitter.com/pingofglitch/status/537884380060844032/photo/1', u'type': u'photo', u'sizes': {u'large': {u'w': 1024, u'h': 640, u'resize': u'fit'}, u'thumb': {u'w': 150, u'h': 150, u'resize': u'crop'}, u'medium': {u'w': 600, u'h': 375, u'resize': u'fit'}, u'small': {u'w': 340, u'h': 212, u'resize': u'fit'}}}]}, 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 = 'google.com is a #cool site, lol! @mikehelmick shd #checkitout. Love, @__twython__ github.com pic.twitter.com/N6InAO4B71' - -test_tweet_symbols_object = {u'text': u'Some symbols: $AAPL and $PEP and $ANOTHER and $A.', u'contributors': None, u'geo': None, u'favorited': True, u'in_reply_to_user_id_str': None, u'user': {u'screen_name': u'philgyfordtest', u'name': u'Phil Gyford Test'}, u'in_reply_to_user_id': None, u'retweeted': False, u'coordinates': None, u'place': None, u'in_reply_to_status_id': None, u'lang': u'en', u'in_reply_to_status_id_str': None, u'truncated': False, u'retweet_count': 0, u'is_quote_status': False, u'id': 662694880657989632, u'id_str': u'662694880657989632', u'in_reply_to_screen_name': None, u'favorite_count': 1, u'entities': {u'hashtags': [], u'user_mentions': [], u'symbols': [{u'indices': [14, 19], u'text': u'AAPL'}, {u'indices': [24, 28], u'text': u'PEP'}, {u'indices': [46, 48], u'text': u'A'}], u'urls': []}, u'created_at': u'Fri Nov 06 18:15:46 +0000 2015', u'source': u'web'} - -test_tweet_compat_object = {u'contributors': None, u'truncated': True, u'text': u"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count tow\u2026 https://t.co/SRmsuks2ru", u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 777915304261193728, u'favorite_count': 13856, u'source': u'Twitter Web Client', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/SRmsuks2ru', u'indices': [117, 140], u'expanded_url': u'https://twitter.com/i/web/status/777915304261193728', u'display_url': u'twitter.com/i/web/status/7\u2026'}]}, u'in_reply_to_screen_name': None, u'id_str': u'777915304261193728', u'retweet_count': 14767, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'name': u'Twitter', u'screen_name': u'twitter'}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Mon Sep 19 17:00:36 +0000 2016', u'in_reply_to_status_id_str': None, u'place': None} -test_tweet_extended_object = {u'full_text': u"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. https://t.co/I9pUC0NdZC", u'truncated': False, u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 777915304261193728, u'favorite_count': 13856, u'contributors': None, u'source': u'Twitter Web Client', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [], u'media': [{u'expanded_url': u'https://twitter.com/twitter/status/777915304261193728/photo/1', u'sizes': {u'small': {u'h': 340, u'w': 340, u'resize': u'fit'}, u'large': {u'h': 700, u'w': 700, u'resize': u'fit'}, u'medium': {u'h': 600, u'w': 600, u'resize': u'fit'}, u'thumb': {u'h': 150, u'w': 150, u'resize': u'crop'}}, u'url': u'https://t.co/I9pUC0NdZC', u'media_url_https': u'https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'id_str': u'777914712382058496', u'indices': [140, 163], u'media_url': u'http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'type': u'photo', u'id': 777914712382058496, u'display_url': u'pic.twitter.com/I9pUC0NdZC'}]}, u'in_reply_to_screen_name': None, u'id_str': u'777915304261193728', u'display_text_range': [0, 139], u'retweet_count': 14767, u'in_reply_to_user_id': None, u'favorited': False, u'user': {u'follow_request_sent': False, u'has_extended_profile': False, u'profile_use_background_image': True, u'id': 783214, u'verified': True, u'profile_text_color': u'333333', u'profile_image_url_https': u'https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'profile_sidebar_fill_color': u'F6F6F6', u'is_translator': False, u'geo_enabled': True, u'entities': {u'url': {u'urls': [{u'url': u'http://t.co/5iRhy7wTgu', u'indices': [0, 22], u'expanded_url': u'http://blog.twitter.com/', u'display_url': u'blog.twitter.com'}]}, u'description': {u'urls': [{u'url': u'https://t.co/qq1HEzvnrA', u'indices': [84, 107], u'expanded_url': u'http://support.twitter.com', u'display_url': u'support.twitter.com'}]}}, u'followers_count': 56827498, u'protected': False, u'location': u'San Francisco, CA', u'default_profile_image': False, u'id_str': u'783214', u'lang': u'en', u'utc_offset': -25200, u'statuses_count': 3161, u'description': u'Your official source for news, updates and tips from Twitter, Inc. Need help? Visit https://t.co/qq1HEzvnrA.', u'friends_count': 145, u'profile_link_color': u'226699', u'profile_image_url': u'http://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg', u'notifications': False, u'profile_background_image_url_https': u'https://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'profile_background_color': u'ACDED6', u'profile_banner_url': u'https://pbs.twimg.com/profile_banners/783214/1471929200', u'profile_background_image_url': u'http://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png', u'name': u'Twitter', u'is_translation_enabled': False, u'profile_background_tile': True, u'favourites_count': 2332, u'screen_name': u'twitter', u'url': u'http://t.co/5iRhy7wTgu', u'created_at': u'Tue Feb 20 14:35:54 +0000 2007', u'contributors_enabled': False, u'time_zone': u'Pacific Time (US & Canada)', u'profile_sidebar_border_color': u'FFFFFF', u'default_profile': False, u'following': False, u'listed_count': 90445}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Mon Sep 19 17:00:36 +0000 2016', u'in_reply_to_status_id_str': None, u'place': None, u'extended_entities': {u'media': [{u'expanded_url': u'https://twitter.com/twitter/status/777915304261193728/photo/1', u'display_url': u'pic.twitter.com/I9pUC0NdZC', u'url': u'https://t.co/I9pUC0NdZC', u'media_url_https': u'https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg', u'video_info': {u'aspect_ratio': [1, 1], u'variants': [{u'url': u'https://pbs.twimg.com/tweet_video/Csu1TzEVMAAAEv7.mp4', u'bitrate': 0, u'content_type': u'video/mp4'}]}, u'id_str': u'777914712382058496', u'sizes': {u'small': {u'h': 340, u'w': 340, u'resize': u'fit'}, u'large': {u'h': 700, u'w': 700, u'resize': u'fit'}, u'medium': {u'h': 600, u'w': 600, u'resize': u'fit'}, u'thumb': {u'h': 150, u'w': 150, u'resize': u'crop'}}, u'indices': [140, 163], u'type': u'animated_gif', u'id': 777914712382058496, u'media_url': u'http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg'}]}} - -test_tweet_extended_html = 'Say more about what\'s happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. pic.twitter.com/I9pUC0NdZC' - -test_tweet_identical_urls = {u'entities': {u'hashtags': [], u'user_mentions': [], u'symbols': [], u'urls': [{u'display_url': u'buff.ly/2sEhrgO', u'expanded_url': u'http://buff.ly/2sEhrgO', u'indices': [42, 65], u'url': u'https://t.co/W0uArTMk9N'}, {u'display_url': u'buff.ly/2sEhrgO', u'expanded_url': u'http://buff.ly/2sEhrgO', u'indices': [101, 124], u'url': u'https://t.co/W0uArTMk9N'}]}, u'full_text': u'Use Cases, Trials and Making 5G a Reality https://t.co/W0uArTMk9N #5G #innovation via @5GWorldSeries https://t.co/W0uArTMk9N'} - -test_tweet_reply = { u'display_text_range': [12,114], u'in_reply_to_status_id_str':u'742374355531923456', u'source':u'web', u'geo':None, u'full_text':u'@philgyford Here\u2019s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr', u'extended_entities':{ u'media':[] }, u'id_str':u'300', u'in_reply_to_status_id':742374355531923456, u'id':300, u'in_reply_to_screen_name':u'philgyford', u'retweet_count':0, u'user':{ }, u'created_at':u'Mon Jun 13 15:48:06 +0000 2016', u'lang':u'en', u'favorite_count':0, u'coordinates':None, u'place':None, u'contributors':None, u'in_reply_to_user_id':12552, u'in_reply_to_user_id_str':u'12552', u'retweeted':False, u'favorited':False, u'truncated':False, u'entities':{ u'user_mentions':[ { u'id_str':u'12552', u'id':12552, u'screen_name':u'philgyford', u'name':u'Phil Gyford', u'indices':[ 0, 11 ] } ], u'media':[ ], u'hashtags':[ ], u'symbols':[ ], u'urls':[ ] }, u'is_quote_status':False, u'possibly_sensitive':False } - - -test_tweet_media = {'user': {'name': 'Phil Gyford', 'screen_name': 'philgyford'}, 'geo': {}, 'id': 905105588279013377, 'text': 'I made some D3.js charts showing the years covered by books in a series compared to their publishing dates https://t.co/2yUmmn3TOc https://t.co/OwNc6uJklg', 'entities': {'user_mentions': [], 'hashtags': [], 'media': [{'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'id': 905105571765944320, 'media_url': 'http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg', 'sizes': [{'h': 256, 'w': 680, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 376, 'w': 1000, 'resize': 'fit'}, {'h': 376, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105571765944320'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'id': 905105572529393668, 'media_url': 'http://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg', 'sizes': [{'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 271, 'w': 680, 'resize': 'fit'}, {'h': 399, 'w': 1000, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 399, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105572529393668'}, {'url': 'https://t.co/OwNc6uJklg', 'display_url': 'pic.twitter.com/OwNc6uJklg', 'media_url_https': 'https://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'id': 905105573255016448, 'media_url': 'http://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg', 'sizes': [{'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 195, 'w': 680, 'resize': 'fit'}, {'h': 150, 'w': 150, 'resize': 'crop'}, {'h': 287, 'w': 1000, 'resize': 'fit'}, {'h': 287, 'w': 1000, 'resize': 'fit'}], 'indices': [131, 154], 'expanded_url': 'https://twitter.com/philgyford/status/905105588279013377/photo/1', 'id_str': '905105573255016448'}], 'urls': [{'display_url': 'gyford.com/phil/writing/2…', 'url': 'https://t.co/2yUmmn3TOc', 'indices': [107, 130], 'expanded_url': 'http://www.gyford.com/phil/writing/2017/09/05/book-series-charts.php'}]}, 'source': 'web', 'created_at': '2017-09-05 16:29:22 +0000', 'id_str': '905105588279013377'} - -test_tweet_quoted = {u'contributors': None, u'truncated': False, u'text': u'Here\u2019s a quoted tweet. https://t.co/3neKzof0gT', u'is_quote_status': True, u'in_reply_to_status_id': None, u'id': 917706313785905157, u'favorite_count': 0, u'source': u'web', u'quoted_status_id': 917699069916729344, u'retweeted': False, u'coordinates': None, u'quoted_status': {u'contributors': None, u'truncated': False, u'text': u'The quoted tweet text.', u'is_quote_status': False, u'in_reply_to_status_id': None, u'id': 917699069916729344, u'favorite_count': 1, u'source': u'web', u'retweeted': False, u'coordinates': None, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': []}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917699069916729344', u'favorited': False, u'user': {u'screen_name': u'philgyford', u'name': u'Phil Gyford'}, u'geo': None, u'in_reply_to_user_id_str': None, u'lang': u'ht', u'created_at': u'Tue Oct 10 10:31:22 +0000 2017', u'in_reply_to_status_id_str': None, u'place': None}, u'entities': {u'symbols': [], u'user_mentions': [], u'hashtags': [], u'urls': [{u'url': u'https://t.co/3neKzof0gT', u'indices': [23, 46], u'expanded_url': u'https://twitter.com/philgyford/status/917699069916729344', u'display_url': u'twitter.com/philgyford/sta\u2026'}]}, u'in_reply_to_screen_name': None, u'in_reply_to_user_id': None, u'retweet_count': 0, u'id_str': u'917706313785905157', u'favorited': False, u'user': {u'screen_name': u'philgyfordtest', u'name': u'Phil Gyford Test'}, u'geo': None, u'in_reply_to_user_id_str': None, u'possibly_sensitive': False, u'possibly_sensitive_appealable': False, u'lang': u'en', u'created_at': u'Tue Oct 10 11:00:10 +0000 2017', u'quoted_status_id_str': u'917699069916729344', u'in_reply_to_status_id_str': None, u'place': None} - -test_tweet_retweet = {'coordinates': None, 'source': 'web', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 0, 'user': {'name': 'Phil Gyford Test', 'screen_name': 'philgyfordtest'}, 'favorited': False, 'retweeted_status': {'coordinates': None, 'source': 'web', 'in_reply_to_user_id_str': None, 'truncated': False, 'in_reply_to_user_id': None, 'favorite_count': 21, 'user': {'name': 'Samuel Pepys', 'screen_name': 'samuelpepys'}, 'favorited': False, 'id': 917459832885653506, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917459832885653506', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Mon Oct 09 18:40:44 +0000 2017', 'is_quote_status': False, 'retweeted': False}, 'id': 917712989649801216, 'contributors': None, 'in_reply_to_screen_name': None, 'geo': None, 'in_reply_to_status_id_str': None, 'id_str': '917712989649801216', 'entities': {'hashtags': [], 'symbols': [], 'user_mentions': [{'id_str': '14475268', 'indices': [3, 15], 'name': 'Samuel Pepys', 'id': 14475268, 'screen_name': 'samuelpepys'}], 'urls': []}, 'in_reply_to_status_id': None, 'text': 'RT @samuelpepys: My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.', 'retweet_count': 3, 'place': None, 'lang': 'en', 'created_at': 'Tue Oct 10 11:26:41 +0000 2017', 'is_quote_status': False, 'retweeted': False} - - diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index aa79998..ecdd553 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -4,7 +4,7 @@ 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_slug, test_list_owner_screen_name, - access_token, test_tweet_object, test_tweet_html, unittest + access_token, unittest ) import time diff --git a/tests/test_html_for_tweet.py b/tests/test_html_for_tweet.py index 9ba25c6..cc49121 100644 --- a/tests/test_html_for_tweet.py +++ b/tests/test_html_for_tweet.py @@ -1,98 +1,110 @@ # -*- coding: utf-8 -*- +import json + from twython import Twython, TwythonError -from .config import ( - test_tweet_object, test_tweet_html, test_tweet_symbols_object, - test_tweet_compat_object, test_tweet_extended_object, - test_tweet_extended_html, test_tweet_identical_urls, test_tweet_reply, - test_tweet_media, test_tweet_quoted, test_tweet_retweet, - unittest -) +from .config import unittest class TestHtmlForTweetTestCase(unittest.TestCase): def setUp(self): self.api = Twython('', '', '', '') + def load_tweet(self, name): + f = open('tests/tweets/%s.json' % name) + tweet = json.load(f) + f.close() + return tweet + def test_basic(self): """Test HTML for Tweet returns what we want""" - tweet_text = self.api.html_for_tweet(test_tweet_object) - self.assertEqual(test_tweet_html, tweet_text) + tweet_object = self.load_tweet('basic') + tweet_text = self.api.html_for_tweet(tweet_object) + self.assertEqual(tweet_text, + 'google.com is a #cool site, lol! @mikehelmick shd #checkitout. Love, @__twython__ github.com pic.twitter.com/N6InAO4B71') def test_reply(self): """Test HTML for Tweet links the replied-to username.""" - tweet_text = self.api.html_for_tweet(test_tweet_reply) + tweet_object = self.load_tweet('reply') + tweet_text = self.api.html_for_tweet(tweet_object) self.assertEqual(tweet_text, u'@philgyford Here’s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr') def test_expanded_url(self): """Test using expanded url in HTML for Tweet displays full urls""" - tweet_text = self.api.html_for_tweet(test_tweet_object, + tweet_object = self.load_tweet('basic') + tweet_text = self.api.html_for_tweet(tweet_object, use_expanded_url=True) # Make sure full url is in HTML self.assertTrue('http://google.com' in tweet_text) def test_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) + tweet_object = self.load_tweet('basic') + tweet_text = self.api.html_for_tweet(tweet_object, False) # Make sure HTML doesn't contain the display OR expanded url self.assertTrue('http://google.com' not in tweet_text) self.assertTrue('google.com' not in tweet_text) def test_identical_urls(self): """If the 'url's for different url entities are identical, they should link correctly.""" - tweet_text = self.api.html_for_tweet(test_tweet_identical_urls) + tweet_object = self.load_tweet('identical_urls') + tweet_text = self.api.html_for_tweet(tweet_object) self.assertEqual(tweet_text, u'Use Cases, Trials and Making 5G a Reality buff.ly/2sEhrgO #5G #innovation via @5GWorldSeries buff.ly/2sEhrgO') def test_symbols(self): - tweet_text = self.api.html_for_tweet(test_tweet_symbols_object) + tweet_object = self.load_tweet('symbols') + tweet_text = self.api.html_for_tweet(tweet_object) # Should only link symbols listed in entities: self.assertTrue('$AAPL' in tweet_text) self.assertTrue('$ANOTHER' not in tweet_text) def test_no_symbols(self): """Should still work if tweet object has no symbols list""" - tweet = test_tweet_symbols_object + tweet = self.load_tweet('symbols') # Save a copy: symbols = tweet['entities']['symbols'] del tweet['entities']['symbols'] tweet_text = self.api.html_for_tweet(tweet) self.assertTrue('symbols: $AAPL and' in tweet_text) self.assertTrue('and $ANOTHER and $A.' in tweet_text) - # Put the symbols back: - test_tweet_symbols_object['entities']['symbols'] = symbols def test_compatmode(self): - tweet_text = self.api.html_for_tweet(test_tweet_compat_object) + tweet_object = self.load_tweet('compat') + tweet_text = self.api.html_for_tweet(tweet_object) # link to compat web status link self.assertTrue( u'twitter.com/i/web/status/7…' in tweet_text) def test_extendedmode(self): - tweet_text = self.api.html_for_tweet(test_tweet_extended_object) + tweet_object = self.load_tweet('extended') + tweet_text = self.api.html_for_tweet(tweet_object) # full tweet rendered with suffix - self.assertEqual(test_tweet_extended_html, tweet_text) + self.assertEqual(tweet_text, + 'Say more about what\'s happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. pic.twitter.com/I9pUC0NdZC') def test_media(self): - tweet_text = self.api.html_for_tweet(test_tweet_media) + tweet_object = self.load_tweet('media') + tweet_text = self.api.html_for_tweet(tweet_object) self.assertEqual( - """I made some D3.js charts showing the years covered by books in a series compared to their publishing dates gyford.com/phil/writing/2… pic.twitter.com/OwNc6uJklg""", + u"""I made some D3.js charts showing the years covered by books in a series compared to their publishing dates gyford.com/phil/writing/2\u2026 pic.twitter.com/OwNc6uJklg""", tweet_text) def test_quoted(self): "With expand_quoted_status=True it should include a quoted tweet." - tweet_text = self.api.html_for_tweet(test_tweet_quoted, + tweet_object = self.load_tweet('quoted') + tweet_text = self.api.html_for_tweet(tweet_object, expand_quoted_status=True) - self.assertEqual( u"""Here\u2019s a quoted tweet. twitter.com/philgyford/sta\u2026
The quoted tweet text.Phil Gyford@philgyford
""", tweet_text) def test_retweet(self): "With expand_quoted_status=True it should include a quoted tweet." - tweet_text = self.api.html_for_tweet(test_tweet_retweet) + tweet_object = self.load_tweet('retweet') + tweet_text = self.api.html_for_tweet(tweet_object) self.assertEqual( u"""My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.""", diff --git a/tests/tweets/basic.json b/tests/tweets/basic.json new file mode 100644 index 0000000..7243cd8 --- /dev/null +++ b/tests/tweets/basic.json @@ -0,0 +1,170 @@ +{ + "contributors":null, + "truncated":false, + "text":"http://t.co/FCmXyI6VHd is a #cool site, lol! @mikehelmick shd #checkitout. Love, @__twython__ https://t.co/67pwRvY6z9 http://t.co/N6InAO4B71", + "in_reply_to_status_id":null, + "id":349683012054683648, + "favorite_count":0, + "source":"Twitter Web Client", + "retweeted":false, + "coordinates":null, + "entities":{ + "symbols":[ + + ], + "user_mentions":[ + { + "id":29251354, + "indices":[ + 45, + 57 + ], + "id_str":"29251354", + "screen_name":"mikehelmick", + "name":"Mike Helmick" + }, + { + "id":1431865928, + "indices":[ + 81, + 93 + ], + "id_str":"1431865928", + "screen_name":"__twython__", + "name":"Twython" + } + ], + "hashtags":[ + { + "indices":[ + 28, + 33 + ], + "text":"cool" + }, + { + "indices":[ + 62, + 73 + ], + "text":"checkitout" + } + ], + "urls":[ + { + "url":"http://t.co/FCmXyI6VHd", + "indices":[ + 0, + 22 + ], + "expanded_url":"http://google.com", + "display_url":"google.com" + }, + { + "url":"https://t.co/67pwRvY6z9", + "indices":[ + 94, + 117 + ], + "expanded_url":"https://github.com", + "display_url":"github.com" + } + ], + "media":[ + { + "id":537884378513162240, + "id_str":"537884378513162240", + "indices":[ + 118, + 140 + ], + "media_url":"http://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg", + "media_url_https":"https://pbs.twimg.com/media/B3by_g-CQAAhrO5.jpg", + "url":"http://t.co/N6InAO4B71", + "display_url":"pic.twitter.com/N6InAO4B71", + "expanded_url":"http://twitter.com/pingofglitch/status/537884380060844032/photo/1", + "type":"photo", + "sizes":{ + "large":{ + "w":1024, + "h":640, + "resize":"fit" + }, + "thumb":{ + "w":150, + "h":150, + "resize":"crop" + }, + "medium":{ + "w":600, + "h":375, + "resize":"fit" + }, + "small":{ + "w":340, + "h":212, + "resize":"fit" + } + } + } + ] + }, + "in_reply_to_screen_name":null, + "id_str":"349683012054683648", + "retweet_count":0, + "in_reply_to_user_id":null, + "favorited":false, + "user":{ + "follow_request_sent":false, + "profile_use_background_image":true, + "default_profile_image":true, + "id":1431865928, + "verified":false, + "profile_text_color":"333333", + "profile_image_url_https":"https://si0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", + "profile_sidebar_fill_color":"DDEEF6", + "entities":{ + "description":{ + "urls":[ + + ] + } + }, + "followers_count":1, + "profile_sidebar_border_color":"C0DEED", + "id_str":"1431865928", + "profile_background_color":"3D3D3D", + "listed_count":0, + "profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png", + "utc_offset":null, + "statuses_count":2, + "description":"", + "friends_count":1, + "location":"", + "profile_link_color":"0084B4", + "profile_image_url":"http://a0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png", + "following":false, + "geo_enabled":false, + "profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png", + "screen_name":"__twython__", + "lang":"en", + "profile_background_tile":false, + "favourites_count":0, + "name":"Twython", + "notifications":false, + "url":null, + "created_at":"Thu May 16 01:11:09 +0000 2013", + "contributors_enabled":false, + "time_zone":null, + "protected":false, + "default_profile":false, + "is_translator":false + }, + "geo":null, + "in_reply_to_user_id_str":null, + "possibly_sensitive":false, + "lang":"en", + "created_at":"Wed Jun 26 00:18:21 +0000 2013", + "in_reply_to_status_id_str":null, + "place":null +} diff --git a/tests/tweets/compat.json b/tests/tweets/compat.json new file mode 100644 index 0000000..b01b358 --- /dev/null +++ b/tests/tweets/compat.json @@ -0,0 +1,51 @@ +{ + "contributors":null, + "truncated":true, + "text":"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count tow\u2026 https://t.co/SRmsuks2ru", + "is_quote_status":false, + "in_reply_to_status_id":null, + "id":777915304261193728, + "favorite_count":13856, + "source":"Twitter Web Client", + "retweeted":false, + "coordinates":null, + "entities":{ + "symbols":[ + + ], + "user_mentions":[ + + ], + "hashtags":[ + + ], + "urls":[ + { + "url":"https://t.co/SRmsuks2ru", + "indices":[ + 117, + 140 + ], + "expanded_url":"https://twitter.com/i/web/status/777915304261193728", + "display_url":"twitter.com/i/web/status/7\u2026" + } + ] + }, + "in_reply_to_screen_name":null, + "id_str":"777915304261193728", + "retweet_count":14767, + "in_reply_to_user_id":null, + "favorited":false, + "user":{ + "name":"Twitter", + "screen_name":"twitter" + }, + "geo":null, + "in_reply_to_user_id_str":null, + "possibly_sensitive":false, + "possibly_sensitive_appealable":false, + "lang":"en", + "created_at":"Mon Sep 19 17:00:36 +0000 2016", + "in_reply_to_status_id_str":null, + "place":null +} diff --git a/tests/tweets/extended.json b/tests/tweets/extended.json new file mode 100644 index 0000000..105700a --- /dev/null +++ b/tests/tweets/extended.json @@ -0,0 +1,204 @@ +{ + "full_text":"Say more about what's happening! Rolling out now: photos, videos, GIFs, polls, and Quote Tweets no longer count toward your 140 characters. https://t.co/I9pUC0NdZC", + "truncated":false, + "is_quote_status":false, + "in_reply_to_status_id":null, + "id":777915304261193728, + "favorite_count":13856, + "contributors":null, + "source":"Twitter Web Client", + "retweeted":false, + "coordinates":null, + "entities":{ + "symbols":[ + + ], + "user_mentions":[ + + ], + "hashtags":[ + + ], + "urls":[ + + ], + "media":[ + { + "expanded_url":"https://twitter.com/twitter/status/777915304261193728/photo/1", + "sizes":{ + "small":{ + "h":340, + "w":340, + "resize":"fit" + }, + "large":{ + "h":700, + "w":700, + "resize":"fit" + }, + "medium":{ + "h":600, + "w":600, + "resize":"fit" + }, + "thumb":{ + "h":150, + "w":150, + "resize":"crop" + } + }, + "url":"https://t.co/I9pUC0NdZC", + "media_url_https":"https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg", + "id_str":"777914712382058496", + "indices":[ + 140, + 163 + ], + "media_url":"http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg", + "type":"photo", + "id":777914712382058496, + "display_url":"pic.twitter.com/I9pUC0NdZC" + } + ] + }, + "in_reply_to_screen_name":null, + "id_str":"777915304261193728", + "display_text_range":[ + 0, + 139 + ], + "retweet_count":14767, + "in_reply_to_user_id":null, + "favorited":false, + "user":{ + "follow_request_sent":false, + "has_extended_profile":false, + "profile_use_background_image":true, + "id":783214, + "verified":true, + "profile_text_color":"333333", + "profile_image_url_https":"https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg", + "profile_sidebar_fill_color":"F6F6F6", + "is_translator":false, + "geo_enabled":true, + "entities":{ + "url":{ + "urls":[ + { + "url":"http://t.co/5iRhy7wTgu", + "indices":[ + 0, + 22 + ], + "expanded_url":"http://blog.twitter.com/", + "display_url":"blog.twitter.com" + } + ] + }, + "description":{ + "urls":[ + { + "url":"https://t.co/qq1HEzvnrA", + "indices":[ + 84, + 107 + ], + "expanded_url":"http://support.twitter.com", + "display_url":"support.twitter.com" + } + ] + } + }, + "followers_count":56827498, + "protected":false, + "location":"San Francisco, CA", + "default_profile_image":false, + "id_str":"783214", + "lang":"en", + "utc_offset":-25200, + "statuses_count":3161, + "description":"Your official source for news, updates and tips from Twitter, Inc. Need help? Visit https://t.co/qq1HEzvnrA.", + "friends_count":145, + "profile_link_color":"226699", + "profile_image_url":"http://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg", + "notifications":false, + "profile_background_image_url_https":"https://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png", + "profile_background_color":"ACDED6", + "profile_banner_url":"https://pbs.twimg.com/profile_banners/783214/1471929200", + "profile_background_image_url":"http://pbs.twimg.com/profile_background_images/657090062/l1uqey5sy82r9ijhke1i.png", + "name":"Twitter", + "is_translation_enabled":false, + "profile_background_tile":true, + "favourites_count":2332, + "screen_name":"twitter", + "url":"http://t.co/5iRhy7wTgu", + "created_at":"Tue Feb 20 14:35:54 +0000 2007", + "contributors_enabled":false, + "time_zone":"Pacific Time (US & Canada)", + "profile_sidebar_border_color":"FFFFFF", + "default_profile":false, + "following":false, + "listed_count":90445 + }, + "geo":null, + "in_reply_to_user_id_str":null, + "possibly_sensitive":false, + "possibly_sensitive_appealable":false, + "lang":"en", + "created_at":"Mon Sep 19 17:00:36 +0000 2016", + "in_reply_to_status_id_str":null, + "place":null, + "extended_entities":{ + "media":[ + { + "expanded_url":"https://twitter.com/twitter/status/777915304261193728/photo/1", + "display_url":"pic.twitter.com/I9pUC0NdZC", + "url":"https://t.co/I9pUC0NdZC", + "media_url_https":"https://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg", + "video_info":{ + "aspect_ratio":[ + 1, + 1 + ], + "variants":[ + { + "url":"https://pbs.twimg.com/tweet_video/Csu1TzEVMAAAEv7.mp4", + "bitrate":0, + "content_type":"video/mp4" + } + ] + }, + "id_str":"777914712382058496", + "sizes":{ + "small":{ + "h":340, + "w":340, + "resize":"fit" + }, + "large":{ + "h":700, + "w":700, + "resize":"fit" + }, + "medium":{ + "h":600, + "w":600, + "resize":"fit" + }, + "thumb":{ + "h":150, + "w":150, + "resize":"crop" + } + }, + "indices":[ + 140, + 163 + ], + "type":"animated_gif", + "id":777914712382058496, + "media_url":"http://pbs.twimg.com/tweet_video_thumb/Csu1TzEVMAAAEv7.jpg" + } + ] + } +} diff --git a/tests/tweets/identical_urls.json b/tests/tweets/identical_urls.json new file mode 100644 index 0000000..69840f9 --- /dev/null +++ b/tests/tweets/identical_urls.json @@ -0,0 +1,34 @@ +{ + "entities":{ + "hashtags":[ + + ], + "user_mentions":[ + + ], + "symbols":[ + + ], + "urls":[ + { + "display_url":"buff.ly/2sEhrgO", + "expanded_url":"http://buff.ly/2sEhrgO", + "indices":[ + 42, + 65 + ], + "url":"https://t.co/W0uArTMk9N" + }, + { + "display_url":"buff.ly/2sEhrgO", + "expanded_url":"http://buff.ly/2sEhrgO", + "indices":[ + 101, + 124 + ], + "url":"https://t.co/W0uArTMk9N" + } + ] + }, + "full_text":"Use Cases, Trials and Making 5G a Reality https://t.co/W0uArTMk9N #5G #innovation via @5GWorldSeries https://t.co/W0uArTMk9N" +} diff --git a/tests/tweets/media.json b/tests/tweets/media.json new file mode 100644 index 0000000..4366794 --- /dev/null +++ b/tests/tweets/media.json @@ -0,0 +1,205 @@ +{ + "contributors":null, + "truncated":false, + "is_quote_status":false, + "in_reply_to_status_id":null, + "id":905105588279013377, + "favorite_count":10, + "full_text":"I made some D3.js charts showing the years covered by books in a series compared to their publishing dates https://t.co/2yUmmn3TOc https://t.co/OwNc6uJklg", + "source":"Twitter Web Client", + "retweeted":false, + "coordinates":null, + "entities":{ + "symbols":[ + + ], + "user_mentions":[ + + ], + "hashtags":[ + + ], + "urls":[ + { + "url":"https://t.co/2yUmmn3TOc", + "indices":[ + 107, + 130 + ], + "expanded_url":"http://www.gyford.com/phil/writing/2017/09/05/book-series-charts.php", + "display_url":"gyford.com/phil/writing/2\u2026" + } + ], + "media":[ + { + "expanded_url":"https://twitter.com/philgyford/status/905105588279013377/photo/1", + "display_url":"pic.twitter.com/OwNc6uJklg", + "url":"https://t.co/OwNc6uJklg", + "media_url_https":"https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg", + "id_str":"905105571765944320", + "sizes":{ + "small":{ + "h":256, + "resize":"fit", + "w":680 + }, + "large":{ + "h":376, + "resize":"fit", + "w":1000 + }, + "medium":{ + "h":376, + "resize":"fit", + "w":1000 + }, + "thumb":{ + "h":150, + "resize":"crop", + "w":150 + } + }, + "indices":[ + 131, + 154 + ], + "type":"photo", + "id":905105571765944320, + "media_url":"http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg" + } + ] + }, + "in_reply_to_screen_name":null, + "in_reply_to_user_id":null, + "display_text_range":[ + 0, + 130 + ], + "retweet_count":1, + "id_str":"905105588279013377", + "favorited":false, + "user":{ + "screen_name":"philgyford", + "name":"Phil Gyford" + }, + "geo":null, + "in_reply_to_user_id_str":null, + "possibly_sensitive":false, + "possibly_sensitive_appealable":false, + "lang":"en", + "created_at":"Tue Sep 05 16:29:22 +0000 2017", + "in_reply_to_status_id_str":null, + "place":null, + "extended_entities":{ + "media":[ + { + "expanded_url":"https://twitter.com/philgyford/status/905105588279013377/photo/1", + "display_url":"pic.twitter.com/OwNc6uJklg", + "url":"https://t.co/OwNc6uJklg", + "media_url_https":"https://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg", + "id_str":"905105571765944320", + "sizes":{ + "small":{ + "h":256, + "resize":"fit", + "w":680 + }, + "large":{ + "h":376, + "resize":"fit", + "w":1000 + }, + "medium":{ + "h":376, + "resize":"fit", + "w":1000 + }, + "thumb":{ + "h":150, + "resize":"crop", + "w":150 + } + }, + "indices":[ + 131, + 154 + ], + "type":"photo", + "id":905105571765944320, + "media_url":"http://pbs.twimg.com/media/DI-UuNlWAAA_cvz.jpg" + }, + { + "expanded_url":"https://twitter.com/philgyford/status/905105588279013377/photo/1", + "display_url":"pic.twitter.com/OwNc6uJklg", + "url":"https://t.co/OwNc6uJklg", + "media_url_https":"https://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg", + "id_str":"905105572529393668", + "sizes":{ + "large":{ + "h":399, + "resize":"fit", + "w":1000 + }, + "small":{ + "h":271, + "resize":"fit", + "w":680 + }, + "medium":{ + "h":399, + "resize":"fit", + "w":1000 + }, + "thumb":{ + "h":150, + "resize":"crop", + "w":150 + } + }, + "indices":[ + 131, + 154 + ], + "type":"photo", + "id":905105572529393668, + "media_url":"http://pbs.twimg.com/media/DI-UuQbXUAQ1WlR.jpg" + }, + { + "expanded_url":"https://twitter.com/philgyford/status/905105588279013377/photo/1", + "display_url":"pic.twitter.com/OwNc6uJklg", + "url":"https://t.co/OwNc6uJklg", + "media_url_https":"https://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg", + "id_str":"905105573255016448", + "sizes":{ + "small":{ + "h":195, + "resize":"fit", + "w":680 + }, + "large":{ + "h":287, + "resize":"fit", + "w":1000 + }, + "medium":{ + "h":287, + "resize":"fit", + "w":1000 + }, + "thumb":{ + "h":150, + "resize":"crop", + "w":150 + } + }, + "indices":[ + 131, + 154 + ], + "type":"photo", + "id":905105573255016448, + "media_url":"http://pbs.twimg.com/media/DI-UuTIXcAA-t1_.jpg" + } + ] + } +} diff --git a/tests/tweets/quoted.json b/tests/tweets/quoted.json new file mode 100644 index 0000000..c8e372b --- /dev/null +++ b/tests/tweets/quoted.json @@ -0,0 +1,94 @@ +{ + "contributors":null, + "truncated":false, + "text":"Here\u2019s a quoted tweet. https://t.co/3neKzof0gT", + "is_quote_status":true, + "in_reply_to_status_id":null, + "id":917706313785905157, + "favorite_count":0, + "source":"Twitter Web Client", + "quoted_status_id":917699069916729344, + "retweeted":false, + "coordinates":null, + "quoted_status":{ + "contributors":null, + "truncated":false, + "text":"The quoted tweet text.", + "is_quote_status":false, + "in_reply_to_status_id":null, + "id":917699069916729344, + "favorite_count":1, + "source":"Twitter Web Client", + "retweeted":false, + "coordinates":null, + "entities":{ + "symbols":[ + + ], + "user_mentions":[ + + ], + "hashtags":[ + + ], + "urls":[ + + ] + }, + "in_reply_to_screen_name":null, + "in_reply_to_user_id":null, + "retweet_count":0, + "id_str":"917699069916729344", + "favorited":false, + "user":{ + "screen_name":"philgyford", + "name":"Phil Gyford" + }, + "geo":null, + "in_reply_to_user_id_str":null, + "lang":"ht", + "created_at":"Tue Oct 10 10:31:22 +0000 2017", + "in_reply_to_status_id_str":null, + "place":null + }, + "entities":{ + "symbols":[ + + ], + "user_mentions":[ + + ], + "hashtags":[ + + ], + "urls":[ + { + "url":"https://t.co/3neKzof0gT", + "indices":[ + 23, + 46 + ], + "expanded_url":"https://twitter.com/philgyford/status/917699069916729344", + "display_url":"twitter.com/philgyford/sta\u2026" + } + ] + }, + "in_reply_to_screen_name":null, + "in_reply_to_user_id":null, + "retweet_count":0, + "id_str":"917706313785905157", + "favorited":false, + "user":{ + "screen_name":"philgyfordtest", + "name":"Phil Gyford Test" + }, + "geo":null, + "in_reply_to_user_id_str":null, + "possibly_sensitive":false, + "possibly_sensitive_appealable":false, + "lang":"en", + "created_at":"Tue Oct 10 11:00:10 +0000 2017", + "quoted_status_id_str":"917699069916729344", + "in_reply_to_status_id_str":null, + "place":null +} diff --git a/tests/tweets/reply.json b/tests/tweets/reply.json new file mode 100644 index 0000000..2a22712 --- /dev/null +++ b/tests/tweets/reply.json @@ -0,0 +1,62 @@ +{ + "display_text_range":[ + 12, + 114 + ], + "in_reply_to_status_id_str":"742374355531923456", + "source":"Twitter Web Client", + "geo":null, + "full_text":"@philgyford Here\u2019s a test tweet that goes on as much as possible and includes an image. Hi to my fans in testland! https://t.co/tzhyk2QWSr", + "extended_entities":{ + "media":[ + + ] + }, + "id_str":"300", + "in_reply_to_status_id":742374355531923456, + "id":300, + "in_reply_to_screen_name":"philgyford", + "retweet_count":0, + "user":{ + + }, + "created_at":"Mon Jun 13 15:48:06 +0000 2016", + "lang":"en", + "favorite_count":0, + "coordinates":null, + "place":null, + "contributors":null, + "in_reply_to_user_id":12552, + "in_reply_to_user_id_str":"12552", + "retweeted":false, + "favorited":false, + "truncated":false, + "entities":{ + "user_mentions":[ + { + "id_str":"12552", + "id":12552, + "screen_name":"philgyford", + "name":"Phil Gyford", + "indices":[ + 0, + 11 + ] + } + ], + "media":[ + + ], + "hashtags":[ + + ], + "symbols":[ + + ], + "urls":[ + + ] + }, + "is_quote_status":false, + "possibly_sensitive":false +} diff --git a/tests/tweets/retweet.json b/tests/tweets/retweet.json new file mode 100644 index 0000000..046bb64 --- /dev/null +++ b/tests/tweets/retweet.json @@ -0,0 +1,91 @@ +{ + "coordinates":null, + "source":"web", + "in_reply_to_user_id_str":null, + "truncated":false, + "in_reply_to_user_id":null, + "favorite_count":0, + "user":{ + "name":"Phil Gyford Test", + "screen_name":"philgyfordtest" + }, + "favorited":false, + "retweeted_status":{ + "coordinates":null, + "source":"Twitter Web Client", + "in_reply_to_user_id_str":null, + "truncated":false, + "in_reply_to_user_id":null, + "favorite_count":21, + "user":{ + "name":"Samuel Pepys", + "screen_name":"samuelpepys" + }, + "favorited":false, + "id":917459832885653506, + "contributors":null, + "in_reply_to_screen_name":null, + "geo":null, + "in_reply_to_status_id_str":null, + "id_str":"917459832885653506", + "entities":{ + "hashtags":[ + + ], + "symbols":[ + + ], + "user_mentions":[ + + ], + "urls":[ + + ] + }, + "in_reply_to_status_id":null, + "text":"My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.", + "retweet_count":3, + "place":null, + "lang":"en", + "created_at":"Mon Oct 09 18:40:44 +0000 2017", + "is_quote_status":false, + "retweeted":false + }, + "id":917712989649801216, + "contributors":null, + "in_reply_to_screen_name":null, + "geo":null, + "in_reply_to_status_id_str":null, + "id_str":"917712989649801216", + "entities":{ + "hashtags":[ + + ], + "symbols":[ + + ], + "user_mentions":[ + { + "id_str":"14475268", + "indices":[ + 3, + 15 + ], + "name":"Samuel Pepys", + "id":14475268, + "screen_name":"samuelpepys" + } + ], + "urls":[ + + ] + }, + "in_reply_to_status_id":null, + "text":"RT @samuelpepys: My aunt and uncle in a very ill humour one with another, but I made shift with much ado to keep them from scolding.", + "retweet_count":3, + "place":null, + "lang":"en", + "created_at":"Tue Oct 10 11:26:41 +0000 2017", + "is_quote_status":false, + "retweeted":false +} diff --git a/tests/tweets/symbols.json b/tests/tweets/symbols.json new file mode 100644 index 0000000..7519a08 --- /dev/null +++ b/tests/tweets/symbols.json @@ -0,0 +1,61 @@ +{ + "text":"Some symbols: $AAPL and $PEP and $ANOTHER and $A.", + "contributors":null, + "geo":null, + "favorited":true, + "in_reply_to_user_id_str":null, + "user":{ + "screen_name":"philgyfordtest", + "name":"Phil Gyford Test" + }, + "in_reply_to_user_id":null, + "retweeted":false, + "coordinates":null, + "place":null, + "in_reply_to_status_id":null, + "lang":"en", + "in_reply_to_status_id_str":null, + "truncated":false, + "retweet_count":0, + "is_quote_status":false, + "id":662694880657989632, + "id_str":"662694880657989632", + "in_reply_to_screen_name":null, + "favorite_count":1, + "entities":{ + "hashtags":[ + + ], + "user_mentions":[ + + ], + "symbols":[ + { + "indices":[ + 14, + 19 + ], + "text":"AAPL" + }, + { + "indices":[ + 24, + 28 + ], + "text":"PEP" + }, + { + "indices":[ + 46, + 48 + ], + "text":"A" + } + ], + "urls":[ + + ] + }, + "created_at":"Fri Nov 06 18:15:46 +0000 2015", + "source":"Twitter Web Client" +} From d3f5361f4d58b693f013eeb07dd12b698cae5a58 Mon Sep 17 00:00:00 2001 From: Phil Gyford Date: Wed, 11 Oct 2017 18:40:55 +0100 Subject: [PATCH 8/8] Try to fix loading of JSON files in tests on Travis --- tests/test_html_for_tweet.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_html_for_tweet.py b/tests/test_html_for_tweet.py index cc49121..7331fa4 100644 --- a/tests/test_html_for_tweet.py +++ b/tests/test_html_for_tweet.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import json +import os from twython import Twython, TwythonError @@ -11,7 +12,11 @@ class TestHtmlForTweetTestCase(unittest.TestCase): self.api = Twython('', '', '', '') def load_tweet(self, name): - f = open('tests/tweets/%s.json' % name) + f = open(os.path.join( + os.path.dirname(__file__), + 'tweets', + '%s.json' % name + )) tweet = json.load(f) f.close() return tweet