From 917c3fc7a7e19220beaa224795bbe7c44df8b613 Mon Sep 17 00:00:00 2001 From: Alessio Date: Tue, 10 Aug 2021 22:06:03 -0700 Subject: [PATCH] Add integration test for downloading user contents --- cmd/tests.sh | 7 +++++++ cmd/twitter/main.go | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/cmd/tests.sh b/cmd/tests.sh index 4387a04..c06b246 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -65,4 +65,11 @@ test $(sqlite3 data/twitter.db "select count(*) from tweets") = "2" test $(sqlite3 data/twitter.db "select count(*) from videos") = "1" +# Download a user's profile image and banner image +test $(sqlite3 data/twitter.db "select is_content_downloaded from users where handle = 'DiamondChariots'") = "0" +./tw download_user_content data DiamondChariots +test $(sqlite3 data/twitter.db "select is_content_downloaded from users where handle = 'DiamondChariots'") = "1" +test -f data/profile_images/DiamondChariots_profile_rE4OTedS.jpg +test -f data/profile_images/DiamondChariots_banner_1615811094.jpg + echo -e "\033[32mAll tests passed. Finished successfully.\033[0m" diff --git a/cmd/twitter/main.go b/cmd/twitter/main.go index f455bb1..5e68eb5 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -53,6 +53,8 @@ func main() { fetch_tweet_only(target) case "download_tweet_content": download_tweet_content(target) + case "download_user_content": + download_user_content(scraper.UserHandle(target)) default: die("Invalid operation: " + operation, true, 3) } @@ -137,3 +139,14 @@ func download_tweet_content(tweet_id string) { panic("Error getting content: " + err.Error()) } } + +func download_user_content(handle scraper.UserHandle) { + user, err := profile.GetUserByHandle(handle) + if err != nil { + panic("Couldn't get the user from database: " + err.Error()) + } + err = profile.DownloadUserContentFor(&user) + if err != nil { + panic("Error getting content: " + err.Error()) + } +}