Add integration test for downloading user contents

This commit is contained in:
Alessio 2021-08-10 22:06:03 -07:00
parent 932b42eafc
commit 917c3fc7a7
2 changed files with 20 additions and 0 deletions

View File

@ -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"

View File

@ -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())
}
}