From 587706374843a17ee14cca06faea9188ea18d840 Mon Sep 17 00:00:00 2001 From: Alessio Date: Sat, 15 Oct 2022 15:50:25 -0400 Subject: [PATCH] Add some tests for multiple videos / videos+images --- cmd/tests.sh | 33 +++++++++++++++++++++++++++++++++ scraper/tweet_test.go | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/cmd/tests.sh b/cmd/tests.sh index f3920b0..eaa624c 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -98,6 +98,39 @@ tw download_tweet_content https://twitter.com/Cernovich/status/14444295170202746 test $(find videos -mindepth 2 | wc -l) = "$((initial_videos_count + 1))" +# Fetch a tweet with 2 gifs +initial_videos_count=$(find videos -mindepth 2 | wc -l) +test $(sqlite3 twitter.db "select count(*) from videos where tweet_id = 1580185800968327168 and is_gif = 1") = "0" +tw fetch_tweet https://twitter.com/emo_garfield420/status/1580185800968327168 +test $(find videos -mindepth 2 | wc -l) = "$((initial_videos_count + 2))" +test $(sqlite3 twitter.db "select count(*) from videos where tweet_id = 1580185800968327168 and is_gif = 1") = "2" + +# Fetch a tweet with 2 videos +test $(sqlite3 twitter.db "select count(*) from videos where tweet_id = 1579701786252042240 and is_gif = 0") = "0" +tw fetch_user FairwayWill +tw fetch_tweet_only https://twitter.com/FairwayWill/status/1579701786252042240 +test $(sqlite3 twitter.db "select count(*) from videos where tweet_id = 1579701786252042240 and is_gif = 0") = "2" + +initial_videos_count=$(find videos -mindepth 2 | wc -l) +tw download_tweet_content https://twitter.com/FairwayWill/status/1579701786252042240 +test $(find videos -mindepth 2 | wc -l) = "$((initial_videos_count + 2))" + +# Fetch a tweet with a video and an image +test $(sqlite3 twitter.db "select count(*) from videos where tweet_id = 1579292281898766336") = "0" +test $(sqlite3 twitter.db "select count(*) from images where tweet_id = 1579292281898766336") = "0" +tw fetch_user mexicanwilddog +tw fetch_tweet_only https://twitter.com/mexicanwilddog/status/1579292281898766336 +test $(sqlite3 twitter.db "select count(*) from videos where tweet_id = 1579292281898766336") = "1" +test $(sqlite3 twitter.db "select count(*) from images where tweet_id = 1579292281898766336") = "1" + +initial_videos_count=$(find videos -mindepth 2 | wc -l) +initial_images_count=$(find images -mindepth 2 | wc -l) +tw download_tweet_content https://twitter.com/mexicanwilddog/status/1579292281898766336 +test $(find videos -mindepth 2 | wc -l) = "$((initial_videos_count + 1))" +test $(find images -mindepth 2 | wc -l) = "$((initial_images_count + 1))" + + + # Fetch a tweet with a poll tw fetch_tweet 1465534109573390348 test $(sqlite3 twitter.db "select count(*) from polls where tweet_id = 1465534109573390348") = "1" diff --git a/scraper/tweet_test.go b/scraper/tweet_test.go index 3b31c4f..0f2e255 100644 --- a/scraper/tweet_test.go +++ b/scraper/tweet_test.go @@ -101,9 +101,14 @@ func TestParseTweetWith2Videos(t *testing.T) { v1 := tweet.Videos[0] assert.Equal("https://video.twimg.com/ext_tw_video/1579701730148847617/pu/vid/576x576/ghA0fyf58v-2naWR.mp4?tag=12", v1.RemoteURL) assert.False(v1.IsGif) + assert.Equal("gh/ghA0fyf58v-2naWR.mp4", v1.LocalFilename) + assert.Equal("xU/xUlghaCXbPOVN7vI.jpg", v1.ThumbnailLocalPath) + v2 := tweet.Videos[1] assert.Equal("https://video.twimg.com/ext_tw_video/1579701730157252608/pu/vid/480x480/VQ69Ut84XT2BgIzX.mp4?tag=12", v2.RemoteURL) assert.False(v2.IsGif) + assert.Equal("VQ/VQ69Ut84XT2BgIzX.mp4", v2.LocalFilename) + assert.Equal("dY/dYN55HDytKvM1Bi8.jpg", v2.ThumbnailLocalPath) } func TestParseTweetWithImageAndVideo(t *testing.T) {