Skip to content
Browse files

adds tests and data for new-style models

  • Loading branch information...
1 parent 484695f commit 6b9220bf1ad5c4a9343d92b82a15f7a1c43b2312 @jeremylow jeremylow committed
View
1 testdata/models/models_category.json
@@ -0,0 +1 @@
+{"size":26,"slug":"sports","name":"Sports"}
View
1 testdata/models/models_direct_message.json
@@ -0,0 +1 @@
+{"id":678629245946433539,"id_str":"678629245946433539","text":"The Communists are distinguished from the other working-class parties by this only: 1. In the national struggles of the proletarians of the different countries, they point out and bring to the front the common interests of the entire proletariat, independently of all nationality. 2. In the various stages of development which the struggle of the working class against the bourgeoisie has to pass through, they always and everywhere represent the interests of the movement as a whole.","sender":{"id":372018022,"id_str":"372018022","name":"jeremy","screen_name":"__jcbl__","location":"not a very good kingdom tbh","description":"my kingdom for a microwave that doesn't beep","url":"http:\/\/t.co\/wtg3XzqQTX","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/wtg3XzqQTX","expanded_url":"http:\/\/iseverythingstilltheworst.com","display_url":"iseverythingstilltheworst.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":51,"friends_count":289,"listed_count":5,"created_at":"Sun Sep 11 23:49:28 +0000 2011","favourites_count":1245,"utc_offset":-18000,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":312,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/659691753826615298\/yN1SoWrU_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/659691753826615298\/yN1SoWrU_normal.jpg","profile_link_color":"EE3355","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"has_extended_profile":false,"default_profile":false,"default_profile_image":false,"following":true,"follow_request_sent":false,"notifications":false},"sender_id":372018022,"sender_id_str":"372018022","sender_screen_name":"__jcbl__","recipient":{"id":4012966701,"id_str":"4012966701","name":"notinourselves","screen_name":"notinourselves","location":"","description":"","url":null,"entities":{"description":{"urls":[]}},"protected":true,"followers_count":1,"friends_count":1,"listed_count":1,"created_at":"Wed Oct 21 23:53:04 +0000 2015","favourites_count":1,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":25,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false},"recipient_id":4012966701,"recipient_id_str":"4012966701","recipient_screen_name":"notinourselves","created_at":"Sun Dec 20 17:33:15 +0000 2015","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[{"url":"https:\/\/t.co\/PnDU7HQGwq","expanded_url":"http:\/\/twitter.com\/pattymo\/status\/674659346127679488","display_url":"twitter.com\/pattymo\/status\u2026","indices":[0,23]}]}}
View
1 testdata/models/models_direct_message_short.json
@@ -0,0 +1 @@
+{"id":678629245946433539,"id_str":"678629245946433539","text":"The Communists are distinguished from the other working-class parties by this only","sender":{"id":372018022,"id_str":"372018022","name":"jeremy","screen_name":"__jcbl__","location":"not a very good kingdom tbh","description":"my kingdom for a microwave that doesn't beep","url":"http:\/\/t.co\/wtg3XzqQTX","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/wtg3XzqQTX","expanded_url":"http:\/\/iseverythingstilltheworst.com","display_url":"iseverythingstilltheworst.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":51,"friends_count":289,"listed_count":5,"created_at":"Sun Sep 11 23:49:28 +0000 2011","favourites_count":1245,"utc_offset":-18000,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":312,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/659691753826615298\/yN1SoWrU_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/659691753826615298\/yN1SoWrU_normal.jpg","profile_link_color":"EE3355","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"has_extended_profile":false,"default_profile":false,"default_profile_image":false,"following":true,"follow_request_sent":false,"notifications":false},"sender_id":372018022,"sender_id_str":"372018022","sender_screen_name":"__jcbl__","recipient":{"id":4012966701,"id_str":"4012966701","name":"notinourselves","screen_name":"notinourselves","location":"","description":"","url":null,"entities":{"description":{"urls":[]}},"protected":true,"followers_count":1,"friends_count":1,"listed_count":1,"created_at":"Wed Oct 21 23:53:04 +0000 2015","favourites_count":1,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":25,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false},"recipient_id":4012966701,"recipient_id_str":"4012966701","recipient_screen_name":"notinourselves","created_at":"Sun Dec 20 17:33:15 +0000 2015","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[{"url":"https:\/\/t.co\/PnDU7HQGwq","expanded_url":"http:\/\/twitter.com\/pattymo\/status\/674659346127679488","display_url":"twitter.com\/pattymo\/status\u2026","indices":[0,23]}]}}
View
1 testdata/models/models_hashtag.json
@@ -0,0 +1 @@
+{"text":"python","indices":[5,12]}
View
1 testdata/models/models_list.json
@@ -0,0 +1 @@
+{"id":229581524,"id_str":"229581524","name":"test","uri":"\/notinourselves\/lists\/test","subscriber_count":0,"member_count":1,"mode":"public","description":"","slug":"test","full_name":"@notinourselves\/test","created_at":"Fri Dec 18 20:00:45 +0000 2015","following":true,"user":{"id":4012966701,"id_str":"4012966701","name":"notinourselves","screen_name":"notinourselves","location":"","description":"","url":null,"entities":{"description":{"urls":[]}},"protected":true,"followers_count":1,"friends_count":1,"listed_count":1,"created_at":"Wed Oct 21 23:53:04 +0000 2015","favourites_count":1,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":25,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_2_normal.png","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false}}
View
1 testdata/models/models_media.json
@@ -0,0 +1 @@
+{"display_url": "pic.twitter.com/NWg4YmiZKA", "expanded_url": "http://twitter.com/himawari8bot/status/698657677329752065/photo/1", "id": 698657676939685888, "media_url": "http://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "type": "animated_gif", "url": "https://t.co/NWg4YmiZKA"}
View
1 testdata/models/models_status.json
@@ -0,0 +1 @@
+{"extended_entities": {"media": [{"media_url": "http://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "url": "https://t.co/NWg4YmiZKA", "indices": [20, 43], "id": 698657676939685888, "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "expanded_url": "http://twitter.com/himawari8bot/status/698657677329752065/photo/1", "sizes": {"large": {"w": 450, "h": 458, "resize": "fit"}, "medium": {"w": 450, "h": 458, "resize": "fit"}, "thumb": {"w": 150, "h": 150, "resize": "crop"}, "small": {"w": 340, "h": 346, "resize": "fit"}}, "display_url": "pic.twitter.com/NWg4YmiZKA", "video_info": {"aspect_ratio": [225, 229], "variants": [{"url": "https://pbs.twimg.com/tweet_video/CbIhdJ2W8AASWjq.mp4", "bitrate": 0, "content_type": "video/mp4"}]}, "id_str": "698657676939685888", "type": "animated_gif"}]}, "retweet_count": 2, "source": "<a href=\"http://iseverythingstilltheworst.com\" rel=\"nofollow\">space, jerks.</a>", "created_at": "Sat Feb 13 23:59:05 +0000 2016", "in_reply_to_user_id": null, "id": 698657677329752065, "coordinates": null, "id_str": "698657677329752065", "in_reply_to_user_id_str": null, "place": null, "in_reply_to_screen_name": null, "possibly_sensitive": false, "is_quote_status": false, "in_reply_to_status_id_str": null, "favorite_count": 0, "contributors": null, "favorited": false, "text": "2016-02-13T23:00:00 https://t.co/NWg4YmiZKA", "lang": "und", "retweeted": false, "entities": {"hashtags": [], "symbols": [], "user_mentions": [], "urls": [], "media": [{"media_url": "http://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "url": "https://t.co/NWg4YmiZKA", "indices": [20, 43], "id": 698657676939685888, "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "expanded_url": "http://twitter.com/himawari8bot/status/698657677329752065/photo/1", "sizes": {"large": {"w": 450, "h": 458, "resize": "fit"}, "medium": {"w": 450, "h": 458, "resize": "fit"}, "thumb": {"w": 150, "h": 150, "resize": "crop"}, "small": {"w": 340, "h": 346, "resize": "fit"}}, "display_url": "pic.twitter.com/NWg4YmiZKA", "id_str": "698657676939685888", "type": "photo"}]}, "user": {"verified": false, "default_profile": false, "followers_count": 640, "created_at": "Tue Oct 27 23:06:22 +0000 2015", "notifications": false, "profile_use_background_image": false, "favourites_count": 1, "friends_count": 2, "is_translation_enabled": false, "id_str": "4040207472", "profile_background_color": "000000", "profile_background_tile": false, "profile_image_url": "http://pbs.twimg.com/profile_images/659145099113295873/ufx8ad3i_normal.jpg", "url": "https://t.co/uYVLL8E5Qg", "lang": "en", "geo_enabled": false, "protected": false, "contributors_enabled": false, "id": 4040207472, "listed_count": 35, "description": "Unofficial; imagery courtesy: Japan Meteorological Agency (https://t.co/lzPXaTnMCi) and CIRA (https://t.co/YksnDoJEl8). Bot by @__jcbl__", "following": false, "default_profile_image": false, "profile_link_color": "000000", "utc_offset": -18000, "has_extended_profile": false, "location": "Space", "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", "profile_sidebar_border_color": "000000", "profile_sidebar_fill_color": "000000", "time_zone": "Eastern Time (US & Canada)", "screen_name": "himawari8bot", "is_translator": false, "profile_image_url_https": "https://pbs.twimg.com/profile_images/659145099113295873/ufx8ad3i_normal.jpg", "entities": {"url": {"urls": [{"expanded_url": "https://github.com/jeremylow/himawari_bot", "indices": [0, 23], "url": "https://t.co/uYVLL8E5Qg", "display_url": "github.com/jeremylow/hima\u2026"}]}, "description": {"urls": [{"expanded_url": "http://www.jma.go.jp/en/gms/", "indices": [59, 82], "url": "https://t.co/lzPXaTnMCi", "display_url": "jma.go.jp/en/gms/"}, {"expanded_url": "http://rammb.cira.colostate.edu/ramsdis/online/himawari-8.asp", "indices": [94, 117], "url": "https://t.co/YksnDoJEl8", "display_url": "rammb.cira.colostate.edu/ramsdis/online\u2026"}]}}, "follow_request_sent": false, "name": "himawari8bot", "profile_text_color": "000000", "statuses_count": 1871}, "truncated": false, "in_reply_to_status_id": null, "geo": null}
View
1 testdata/models/models_status_no_user.json
@@ -0,0 +1 @@
+{"extended_entities": {"media": [{"media_url": "http://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "url": "https://t.co/NWg4YmiZKA", "indices": [20, 43], "id": 698657676939685888, "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "expanded_url": "http://twitter.com/himawari8bot/status/698657677329752065/photo/1", "sizes": {"large": {"w": 450, "h": 458, "resize": "fit"}, "medium": {"w": 450, "h": 458, "resize": "fit"}, "thumb": {"w": 150, "h": 150, "resize": "crop"}, "small": {"w": 340, "h": 346, "resize": "fit"}}, "display_url": "pic.twitter.com/NWg4YmiZKA", "video_info": {"aspect_ratio": [225, 229], "variants": [{"url": "https://pbs.twimg.com/tweet_video/CbIhdJ2W8AASWjq.mp4", "bitrate": 0, "content_type": "video/mp4"}]}, "id_str": "698657676939685888", "type": "animated_gif"}]}, "retweet_count": 2, "source": "<a href=\"http://iseverythingstilltheworst.com\" rel=\"nofollow\">space, jerks.</a>", "created_at": "Sat Feb 13 23:59:05 +0000 2016", "in_reply_to_user_id": null, "id": 698657677329752065, "coordinates": null, "id_str": "698657677329752065", "in_reply_to_user_id_str": null, "place": null, "in_reply_to_screen_name": null, "possibly_sensitive": false, "is_quote_status": false, "in_reply_to_status_id_str": null, "favorite_count": 0, "contributors": null, "favorited": false, "text": "2016-02-13T23:00:00 https://t.co/NWg4YmiZKA", "lang": "und", "retweeted": false, "entities": {"hashtags": [], "symbols": [], "user_mentions": [], "urls": [], "media": [{"media_url": "http://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "url": "https://t.co/NWg4YmiZKA", "indices": [20, 43], "id": 698657676939685888, "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/CbIhdJ2W8AASWjq.jpg", "expanded_url": "http://twitter.com/himawari8bot/status/698657677329752065/photo/1", "sizes": {"large": {"w": 450, "h": 458, "resize": "fit"}, "medium": {"w": 450, "h": 458, "resize": "fit"}, "thumb": {"w": 150, "h": 150, "resize": "crop"}, "small": {"w": 340, "h": 346, "resize": "fit"}}, "display_url": "pic.twitter.com/NWg4YmiZKA", "id_str": "698657676939685888", "type": "photo"}]}, "truncated": false, "in_reply_to_status_id": null, "geo": null}
View
1 testdata/models/models_trend.json
@@ -0,0 +1 @@
+{"name":"#ChangeAConsonantSpoilAMovie","url":"http:\\/\\/twitter.com\\/search?q=%23ChangeAConsonantSpoilAMovie","promoted_content":null,"query":"%23ChangeAConsonantSpoilAMovie","tweet_volume":null}
View
1 testdata/models/models_url.json
@@ -0,0 +1 @@
+{"url":"http:\/\/t.co\/wtg3XzqQTX","expanded_url":"http:\/\/iseverythingstilltheworst.com","display_url":"iseverythingstilltheworst.com","indices":[0,22]}
View
1 testdata/models/models_user.json
@@ -0,0 +1 @@
+{"id":718443,"id_str":"718443","name":"Kesuke Miyagi","screen_name":"kesuke","location":"Okinawa, Japan","profile_location":null,"description":"\u79c1\u306e\u30db\u30d0\u30fc\u30af\u30e9\u30d5\u30c8 \u306f\u9c3b\u304c\u4e00\u676f\u3067\u3059\u3002","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":22,"friends_count":1,"listed_count":6,"created_at":"Sun Jan 28 06:31:55 +0000 2007","favourites_count":0,"utc_offset":32400,"time_zone":"Tokyo","geo_enabled":false,"verified":false,"statuses_count":10,"lang":"en","status":{"created_at":"Mon Jul 07 13:10:40 +0000 2014","id":486135208928751616,"id_str":"486135208928751616","text":"Wax on.","source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"favorited":false,"retweeted":false,"lang":"en"},"contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"9AE4E8","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/21525032\/kesuke_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/21525032\/kesuke_normal.png","profile_link_color":"0000FF","profile_sidebar_border_color":"87BC44","profile_sidebar_fill_color":"E0FF92","profile_text_color":"000000","profile_use_background_image":true,"has_extended_profile":false,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}
View
1 testdata/models/models_user_status.json
@@ -0,0 +1 @@
+{"name": "dick costolo", "id": 6385432, "screen_name": "dickc", "id_str": "6385432", "connections": ["blocking", "muting"]}
View
4 tests/test_api_30.py
@@ -1334,13 +1334,13 @@ def testPostUpdateWithMedia(self):
# Local file
resp = self.api.PostUpdate(media='testdata/168NQ.jpg', status='test')
- self.assertEqual(697007311538229248, resp.AsDict()['media'][0].id)
+ self.assertEqual(697007311538229248, resp.AsDict()['media'][0]['id'])
self.assertEqual(resp.text, "hi this is a test for media uploads with statuses https://t.co/FHgqb6iLOX")
# File object
with open('testdata/168NQ.jpg', 'rb') as f:
resp = self.api.PostUpdate(media=[f], status='test')
- self.assertEqual(697007311538229248, resp.AsDict()['media'][0].id)
+ self.assertEqual(697007311538229248, resp.AsDict()['media'][0]['id'])
self.assertEqual(resp.text, "hi this is a test for media uploads with statuses https://t.co/FHgqb6iLOX")
# Media ID as int
View
116 tests/test_models.py
@@ -0,0 +1,116 @@
+import twitter
+import json
+import re
+import unittest
+
+
+class ModelsTest(unittest.TestCase):
+ with open('testdata/models/models_category.json', 'rb') as f:
+ CATEGORY_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_direct_message.json', 'rb') as f:
+ DIRECT_MESSAGE_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_direct_message_short.json', 'rb') as f:
+ DIRECT_MESSAGE_SHORT_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_hashtag.json', 'rb') as f:
+ HASHTAG_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_list.json', 'rb') as f:
+ LIST_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_media.json', 'rb') as f:
+ MEDIA_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_status.json', 'rb') as f:
+ STATUS_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_status_no_user.json', 'rb') as f:
+ STATUS_NO_USER_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_trend.json', 'rb') as f:
+ TREND_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_url.json', 'rb') as f:
+ URL_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_user.json', 'rb') as f:
+ USER_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+ with open('testdata/models/models_user_status.json', 'rb') as f:
+ USER_STATUS_SAMPLE_JSON = json.loads(f.read().decode('utf8'))
+
+ def test_category(self):
+ """ Test twitter.Category object """
+ cat = twitter.Category.NewFromJsonDict(self.CATEGORY_SAMPLE_JSON)
+ self.assertEqual(cat.__repr__(), "Category(Name=Sports, Slug=sports, Size=26)")
+ self.assertTrue(cat.AsJsonString())
+ self.assertTrue(cat.AsDict())
+
+ def test_direct_message(self):
+ """ Test twitter.DirectMessage object """
+ dm = twitter.DirectMessage.NewFromJsonDict(self.DIRECT_MESSAGE_SAMPLE_JSON)
+ self.assertEqual(dm.__repr__(), "DirectMessage(ID=678629245946433539, Sender=__jcbl__, Time=Sun Dec 20 17:33:15 +0000 2015, Text='The Communists are distinguished from the other working-class parties by this only: 1. In the national struggles of the proletarians of the [...]')")
+ dm_short = twitter.DirectMessage.NewFromJsonDict(self.DIRECT_MESSAGE_SHORT_SAMPLE_JSON)
+ self.assertEqual(dm_short.__repr__(), "DirectMessage(ID=678629245946433539, Sender=__jcbl__, Time=Sun Dec 20 17:33:15 +0000 2015, Text='The Communists are distinguished from the other working-class parties by this only')")
+ self.assertTrue(dm.AsJsonString())
+ self.assertTrue(dm.AsDict())
+
+ def test_hashtag(self):
+ """ Test twitter.Hashtag object """
+ ht = twitter.Hashtag.NewFromJsonDict(self.HASHTAG_SAMPLE_JSON)
+ self.assertEqual(ht.__repr__(), "Hashtag(Text=python)")
+ self.assertTrue(ht.AsJsonString())
+ self.assertTrue(ht.AsDict())
+
+ def test_list(self):
+ """ Test twitter.List object """
+ lt = twitter.List.NewFromJsonDict(self.LIST_SAMPLE_JSON)
+ self.assertEqual(lt.__repr__(), "List(ID=229581524, FullName=@notinourselves/test, Slug=test, User=notinourselves)")
+ self.assertTrue(lt.AsJsonString())
+ self.assertTrue(lt.AsDict())
+
+ def test_media(self):
+ """ Test twitter.Media object """
+ media = twitter.Media.NewFromJsonDict(self.MEDIA_SAMPLE_JSON)
+ self.assertEqual(media.__repr__(), "Media(ID=698657676939685888, Type=animated_gif, DisplayURL='pic.twitter.com/NWg4YmiZKA')")
+ self.assertTrue(media.AsJsonString())
+ self.assertTrue(media.AsDict())
+
+ def test_status(self):
+ """ Test twitter.Status object """
+ status = twitter.Status.NewFromJsonDict(self.STATUS_SAMPLE_JSON)
+ self.assertEqual(status.__repr__(), "Status(ID=698657677329752065, screen_name='himawari8bot', created_at='Sat Feb 13 23:59:05 +0000 2016')")
+ self.assertTrue(status.AsJsonString())
+ self.assertTrue(status.AsDict())
+ self.assertTrue(status.media[0].AsJsonString())
+ self.assertTrue(status.media[0].AsDict())
+ self.assertTrue(isinstance(status.AsDict()['media'][0], dict))
+
+ def test_status_no_user(self):
+ """ Test twitter.Status object which does not contain a 'user' entity. """
+ status = twitter.Status.NewFromJsonDict(self.STATUS_NO_USER_SAMPLE_JSON)
+ self.assertEqual(status.__repr__(), "Status(ID=698657677329752065, created_at='Sat Feb 13 23:59:05 +0000 2016')")
+ self.assertTrue(status.AsJsonString())
+ self.assertTrue(status.AsDict())
+
+ def test_trend(self):
+ """ Test twitter.Trend object """
+ trend = twitter.Trend.NewFromJsonDict(self.TREND_SAMPLE_JSON)
+ self.assertEqual(trend.__repr__(), "Trend(Name=#ChangeAConsonantSpoilAMovie, Time=None, URL=http:\\/\\/twitter.com\\/search?q=%23ChangeAConsonantSpoilAMovie)")
+ self.assertTrue(trend.AsJsonString())
+ self.assertTrue(trend.AsDict())
+
+ def test_url(self):
+ url = twitter.Url.NewFromJsonDict(self.URL_SAMPLE_JSON)
+ self.assertEqual(url.__repr__(), "URL(URL=http://t.co/wtg3XzqQTX, ExpandedURL=http://iseverythingstilltheworst.com)")
+ self.assertTrue(url.AsJsonString())
+ self.assertTrue(url.AsDict())
+
+ def test_user(self):
+ '''Test the twitter.User NewFromJsonDict method'''
+ user = twitter.User.NewFromJsonDict(self.USER_SAMPLE_JSON)
+ self.assertEqual(user.id, 718443)
+ self.assertEqual(user.__repr__(), "User(ID=718443, Screenname=kesuke)")
+ self.assertTrue(user.AsJsonString())
+ self.assertTrue(user.AsDict())
+
+ def test_user_status(self):
+ """ Test twitter.UserStatus object """
+ user_status = twitter.UserStatus.NewFromJsonDict(self.USER_STATUS_SAMPLE_JSON)
+ # __repr__ doesn't always order 'connections' in the same manner when
+ # call, hence the regex.
+ mtch = re.compile(r'UserStatus\(ID=6385432, Name=dickc, Connections=\[[blocking|muting]+, [blocking|muting]+\]\)')
+ self.assertTrue(re.findall(mtch, user_status.__repr__()))
+ self.assertTrue(user_status.AsJsonString())
+ self.assertTrue(user_status.AsDict())

0 comments on commit 6b9220b

Please sign in to comment.
Something went wrong with that request. Please try again.