From edf51788d811fb2b20ac09cc7c1d9931db442c3f Mon Sep 17 00:00:00 2001 From: aditya Date: Thu, 2 Jun 2016 23:22:32 -0400 Subject: [PATCH] Add test for quoted tweet --- json/statuses/show.json?id=738567564641599489 | 1 + twitter_test.go | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 json/statuses/show.json?id=738567564641599489 diff --git a/json/statuses/show.json?id=738567564641599489 b/json/statuses/show.json?id=738567564641599489 new file mode 100644 index 0000000..5d7eda0 --- /dev/null +++ b/json/statuses/show.json?id=738567564641599489 @@ -0,0 +1 @@ +{"created_at":"Fri Jun 03 03:06:43 +0000 2016","id":738567564641599489,"id_str":"738567564641599489","text":"Well, this has certainly come a long way! https:\/\/t.co\/QomzRzwcti","truncated":false,"entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[{"url":"https:\/\/t.co\/QomzRzwcti","expanded_url":"https:\/\/twitter.com\/chimeracoder\/status\/284377451625340928","display_url":"twitter.com\/chimeracoder\/s\u2026","indices":[42,65]}]},"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","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,"user":{"id":182675886,"id_str":"182675886","name":"Aditya Mukerjee","screen_name":"chimeracoder","location":"New York, NY","description":"Risk engineer at @stripe. Linux dev, statistician. Writing lots of Go. Alum of @recursecenter, @cornell_tech, @columbia","url":"https:\/\/t.co\/6PwvHXBN5Y","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/6PwvHXBN5Y","expanded_url":"https:\/\/adityamukerjee.net","display_url":"adityamukerjee.net","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":3061,"friends_count":914,"listed_count":172,"created_at":"Wed Aug 25 03:49:41 +0000 2010","favourites_count":5193,"utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":9559,"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:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","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":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"quoted_status_id":284377451625340928,"quoted_status_id_str":"284377451625340928","quoted_status":{"created_at":"Thu Dec 27 19:17:22 +0000 2012","id":284377451625340928,"id_str":"284377451625340928","text":"Just created gojson - a simple tool for turning JSON data into Go structs! http:\/\/t.co\/QM6k9AUV #golang","truncated":false,"entities":{"hashtags":[{"text":"golang","indices":[96,103]}],"symbols":[],"user_mentions":[],"urls":[{"url":"http:\/\/t.co\/QM6k9AUV","expanded_url":"http:\/\/bit.ly\/UbfXOC","display_url":"bit.ly\/UbfXOC","indices":[75,95]}]},"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","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,"user":{"id":182675886,"id_str":"182675886","name":"Aditya Mukerjee","screen_name":"chimeracoder","location":"New York, NY","description":"Risk engineer at @stripe. Linux dev, statistician. Writing lots of Go. Alum of @recursecenter, @cornell_tech, @columbia","url":"https:\/\/t.co\/6PwvHXBN5Y","entities":{"url":{"urls":[{"url":"https:\/\/t.co\/6PwvHXBN5Y","expanded_url":"https:\/\/adityamukerjee.net","display_url":"adityamukerjee.net","indices":[0,23]}]},"description":{"urls":[]}},"protected":false,"followers_count":3061,"friends_count":914,"listed_count":172,"created_at":"Wed Aug 25 03:49:41 +0000 2010","favourites_count":5193,"utc_offset":-14400,"time_zone":"Eastern Time (US & Canada)","geo_enabled":false,"verified":false,"statuses_count":9559,"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:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1807988313\/230348_1870593437981_1035450059_32104665_3285049_n_cropped_normal.jpg","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":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":2,"favorited":false,"retweeted":false,"possibly_sensitive":false,"possibly_sensitive_appealable":false,"lang":"en"},"is_quote_status":true,"retweet_count":0,"favorite_count":1,"favorited":false,"retweeted":false,"possibly_sensitive":false,"possibly_sensitive_appealable":false,"lang":"en"} \ No newline at end of file diff --git a/twitter_test.go b/twitter_test.go index e80071f..d787a83 100644 --- a/twitter_test.go +++ b/twitter_test.go @@ -11,6 +11,7 @@ import ( "path" "path/filepath" "reflect" + "strconv" "strings" "testing" "time" @@ -241,7 +242,34 @@ func Test_GetTweet(t *testing.T) { if !reflect.DeepEqual(tweet.Entities, expectedEntities) { t.Fatalf("Tweet entities differ") } +} + +func Test_GetQuotedTweet(t *testing.T) { + const tweetId = 738567564641599489 + const tweetText = `Well, this has certainly come a long way! https://t.co/QomzRzwcti` + const quotedID = 284377451625340928 + const quotedText = `Just created gojson - a simple tool for turning JSON data into Go structs! http://t.co/QM6k9AUV #golang` + + tweet, err := api.GetTweet(tweetId, nil) + if err != nil { + t.Fatalf("GetTweet returned error: %s", err.Error()) + } + if tweet.Text != tweetText { + t.Fatalf("Tweet %d contained incorrect text. Received: %s", tweetId, tweet.Text) + } + + if tweet.QuotedStatusID != quotedID { + t.Fatalf("Expected quoted status %d, received %d", quotedID, tweet.QuotedStatusID) + } + + if tweet.QuotedStatusIdStr != strconv.Itoa(quotedID) { + t.Fatalf("Expected quoted status %d (as string), received %s", quotedID, tweet.QuotedStatusIdStr) + } + + if tweet.QuotedStatus.Text != quotedText { + t.Fatalf("Expected quoted status text %#v, received $#v", quotedText, tweet.QuotedStatus.Text) + } } // This assumes that the current user has at least two pages' worth of followers