Add 'unavailable' tombstone category

This commit is contained in:
Alessio 2021-11-01 15:47:52 -07:00
parent b37bc4bc60
commit c0ae23b4fd
3 changed files with 36 additions and 0 deletions

View File

@ -258,6 +258,7 @@ type TweetResponse struct {
var tombstone_types = map[string]string{
"This Tweet was deleted by the Tweet author. Learn more": "deleted",
"Youre unable to view this Tweet because this account owner limits who can view their Tweets. Learn more": "hidden",
"This Tweet is unavailable. Learn more": "unavailable",
}
/**
* Insert tweets into GlobalObjects for each tombstone. Returns a list of users that need to

View File

@ -210,3 +210,37 @@ func TestHandleTombstonesDeleted(t *testing.T) {
t.Errorf("Wrong tombstone text: %s", tombstone.TombstoneText)
}
}
func TestHandleTombstonesUnavailable(t *testing.T) {
data, err := ioutil.ReadFile("test_responses/tombstones/tombstone_unavailable.json")
if err != nil {
panic(err)
}
var tweet_resp scraper.TweetResponse
err = json.Unmarshal(data, &tweet_resp)
if err != nil {
t.Fatalf(err.Error())
}
if len(tweet_resp.GlobalObjects.Tweets) != 2 {
t.Fatalf("Should have started with %d tweets, but had %d instead", 2, len(tweet_resp.GlobalObjects.Tweets))
}
tweet_resp.HandleTombstones()
if len(tweet_resp.GlobalObjects.Tweets) != 3 {
t.Errorf("Should have ended up with %d tweets, but had %d instead", 3, len(tweet_resp.GlobalObjects.Tweets))
}
tombstone, ok := tweet_resp.GlobalObjects.Tweets["1452686887651532809"]
if !ok {
t.Errorf("Missing tombstoned tweet for %s", "1452686887651532809")
}
if tombstone.ID != 1452686887651532809 {
t.Errorf("Expected ID %d, got %d instead", 1452686887651532809, tombstone.ID)
}
if tombstone.UserID != 1241389617502445569 {
t.Errorf("Expected UserID %d, got %d instead", 1241389617502445569, tombstone.UserID)
}
if tombstone.TombstoneText != "unavailable" {
t.Errorf("Wrong tombstone text: %s", tombstone.TombstoneText)
}
}

File diff suppressed because one or more lines are too long