def test_check_delete_after_date(mocker): mocker.patch("tweet_delete.deleter.Deleter.delete") import datetime d = Deleter( "Mq0PdSJPMQwJwpMm3RtQKGkWA", "kWPpBJvSk7gW59J59WxoWdy5yeA7T6Jr6OJ4yOwxta9I4qtjjG", "959446912159158273-4sLsH3PpTRh93f733s7EZLmLGL4haAD", "98lOut16loWFuHn2uADQfUxP8F4Oxsa3wq6HpdDtbsMbH", datetime.timedelta(seconds=1), dateutil.parser.parse("2008-09-03T20:56:35.450686Z").replace( tzinfo=None), 5, False, ) status = twitter.Status( id=1, favorite_count=1, retweet_count=1, created_at="Wed Mar 13 15:16:59 +0000 2019", ) assert d.to_be_deleted(status) == True assert d.delete.called
def test_schedule_delete(mocker, check_fixture_cm): mocker.patch("tweet_delete.deleter.Deleter.delete") import datetime d = Deleter( "Mq0PdSJPMQwJwpMm3RtQKGkWA", "kWPpBJvSk7gW59J59WxoWdy5yeA7T6Jr6OJ4yOwxta9I4qtjjG", "959446912159158273-4sLsH3PpTRh93f733s7EZLmLGL4haAD", "98lOut16loWFuHn2uADQfUxP8F4Oxsa3wq6HpdDtbsMbH", datetime.timedelta(seconds=10), dateutil.parser.parse("2008-09-03T20:56:35.450686Z").replace( tzinfo=None), 5, False, ) statuses = [] for i in range(100, 90, -1): statuses.append( twitter.Status( id=i, favorite_count=1, retweet_count=1, created_at=datetime.datetime.utcnow().isoformat(), )) with check_fixture_cm(statuses) as mock: mock.side_effect = [statuses, []] max_id = d.check_for_tweets() mock.assert_has_calls([ call( d.api, include_rts=True, exclude_replies=False, max_id=None, count=200, since_id=None, ), call( d.api, include_rts=True, exclude_replies=False, max_id=91, count=200, since_id=None, ), ]) assert len(mock.call_args_list) == 2 assert max_id == 100 for s in statuses: assert s.id in d.ids_scheduled_for_deletion
def test_check_dont_delete_after_date(mocker): mocker.patch('tweet_delete.deleter.Deleter.delete') import datetime d = Deleter('Mq0PdSJPMQwJwpMm3RtQKGkWA', 'kWPpBJvSk7gW59J59WxoWdy5yeA7T6Jr6OJ4yOwxta9I4qtjjG', '959446912159158273-4sLsH3PpTRh93f733s7EZLmLGL4haAD', '98lOut16loWFuHn2uADQfUxP8F4Oxsa3wq6HpdDtbsMbH', datetime.timedelta(seconds=1), datetime.datetime.utcnow(), 5) status = twitter.Status(id=1, favorite_count=1, retweet_count=1, created_at="Wed Mar 13 15:16:59 +0000 2019") assert d.to_be_deleted(status) == False assert not d.delete.called
def test_check_low_quality_tweets2(mocker): mocker.patch("tweet_delete.deleter.Deleter.delete") import datetime d = Deleter( "Mq0PdSJPMQwJwpMm3RtQKGkWA", "kWPpBJvSk7gW59J59WxoWdy5yeA7T6Jr6OJ4yOwxta9I4qtjjG", "959446912159158273-4sLsH3PpTRh93f733s7EZLmLGL4haAD", "98lOut16loWFuHn2uADQfUxP8F4Oxsa3wq6HpdDtbsMbH", datetime.timedelta(seconds=1), None, 5, False, ) status = twitter.Status( id=1, favorite_count=100, retweet_count=100, created_at="Wed Mar 13 15:16:59 +0000 2019", ) assert d.to_be_deleted(status) == False assert not d.delete.called
def cli( consumer_key, consumer_secret, access_token_key, access_token_secret, delete_older_than, delete_everything_after, minimum_engagement, remove_favorites, ): """A simple program to delete all your tweets! Woohoo!""" from tweet_delete.deleter import Deleter from tweet_delete.util import td_format click.echo(click.style("🐦␡ starting tweet-delete".ljust(76) + "␡🐦", fg="green")) deleter = Deleter( consumer_key, consumer_secret, access_token_key, access_token_secret, delete_older_than, delete_everything_after, minimum_engagement, remove_favorites, ) click.echo(click.style("🔑 validating credentials".ljust(77) + "🔑", fg="yellow")) creds = deleter.validate_creds() click.echo( highlight( json.dumps(creds.AsDict(), sort_keys=True, indent=2), JsonLexer(), TerminalFormatter(), ) ) click.echo( click.style( "👉 tweets older than {} will be deleted".format( td_format(delete_older_than.total_seconds()) ).ljust(77) + "👈", fg="yellow", ) ) if delete_everything_after is not None: click.echo( click.style( "👉 only tweets created after {} will be deleted".format( str(delete_everything_after) ).ljust(77) + "👈", fg="yellow", ) ) if remove_favorites: click.echo( click.style( "👉 deleting favorites older than {} created after {}".format( td_format(delete_older_than.total_seconds()), str(delete_everything_after), ).ljust(77) + "👈", fg="yellow", ) ) else: click.echo( click.style("👉 favorites will NOT be deleted".ljust(77) + "👈", fg="yellow",) ) click.echo(click.style("🦅 off we go".ljust(77) + "🦅", fg="green")) deleter.run()
def test_validate_auth_invalid(): d = Deleter("a", "b", "c", "d", None, None, 5, False) with pytest.raises(twitter.error.TwitterError): d.validate_creds()
def test_check_for_tweets2(mocker, check_fixture_cm): mocker.patch("tweet_delete.deleter.Deleter.delete") import datetime d = Deleter( "Mq0PdSJPMQwJwpMm3RtQKGkWA", "kWPpBJvSk7gW59J59WxoWdy5yeA7T6Jr6OJ4yOwxta9I4qtjjG", "959446912159158273-4sLsH3PpTRh93f733s7EZLmLGL4haAD", "98lOut16loWFuHn2uADQfUxP8F4Oxsa3wq6HpdDtbsMbH", datetime.timedelta(seconds=1), dateutil.parser.parse("2008-09-03T20:56:35.450686Z").replace( tzinfo=None), 5, False, ) statuses1 = [] for i in range(100, 90, -1): statuses1.append( twitter.Status( id=i, favorite_count=1, retweet_count=1, created_at="Wed Mar 13 15:16:59 +0000 2019", )) with check_fixture_cm(statuses1) as mock: mock.side_effect = [statuses1, []] max_id = d.check_for_tweets() mock.assert_has_calls([ call( d.api, include_rts=True, exclude_replies=False, max_id=None, count=200, since_id=None, ), call( d.api, include_rts=True, exclude_replies=False, max_id=91, count=200, since_id=None, ), ]) assert len(mock.call_args_list) == 2 assert max_id == 100 calls = [call(s) for s in statuses1] d.delete.assert_has_calls(calls) d.delete.reset_mock() statuses2 = [] for i in range(110, 100, -1): statuses2.append( twitter.Status( id=i, favorite_count=1, retweet_count=1, created_at="Wed Mar 13 15:16:59 +0000 2019", )) with check_fixture_cm(statuses2) as mock: mock.side_effect = [statuses2, statuses1, []] max_id = d.check_for_tweets(max_id) mock.assert_has_calls([ call( d.api, include_rts=True, exclude_replies=False, max_id=None, count=200, since_id=100, ) ]) assert len(mock.call_args_list) == 3 assert max_id == 110 calls = [call(s) for s in statuses2] d.delete.assert_has_calls(calls) d.delete.reset_mock()
def test_validate_auth_invalid(): d = Deleter('a', 'b', 'c', 'd', None, None, 5) with pytest.raises(twitter.error.TwitterError): d.validate_creds()