From f1c8465e636fd4a12f375bd93bebbaac1cc68756 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Thu, 24 Jan 2019 09:36:25 +0100 Subject: [PATCH] Add a "reblogged_by" command --- tests/test_console.py | 29 +++++++++++++++++++++++++++++ toot/api.py | 6 ++++++ toot/commands.py | 5 +++++ toot/console.py | 6 ++++++ 4 files changed, 46 insertions(+) diff --git a/tests/test_console.py b/tests/test_console.py index 57e2948..3aef54d 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -259,6 +259,35 @@ def test_thread(mock_get, monkeypatch, capsys): assert "111111111111111111" in out assert "In reply to" in out +@mock.patch('toot.http.get') +def test_reblogged_by(mock_get, monkeypatch, capsys): + mock_get.return_value = MockResponse([{ + 'display_name': 'Terry Bozzio', + 'acct': 'bozzio@drummers.social', + }, { + 'display_name': 'Dweezil', + 'acct': 'dweezil@zappafamily.social', + }]) + + console.run_command(app, user, 'reblogged_by', ['111111111111111111']) + + calls = [ + mock.call(app, user, '/api/v1/statuses/111111111111111111/reblogged_by'), + ] + mock_get.assert_has_calls(calls, any_order=False) + + out, err = capsys.readouterr() + + # Display order + expected = "\n".join([ + "Terry Bozzio", + " @bozzio@drummers.social", + "Dweezil", + " @dweezil@zappafamily.social", + "", + ]) + assert out == expected + @mock.patch('toot.http.post') def test_upload(mock_post, capsys): mock_post.return_value = MockResponse({ diff --git a/toot/api.py b/toot/api.py index c6fde67..b9fd63d 100644 --- a/toot/api.py +++ b/toot/api.py @@ -151,6 +151,12 @@ def context(app, user, status_id): return http.get(app, user, url).json() +def reblogged_by(app, user, status_id): + url = '/api/v1/statuses/{}/reblogged_by'.format(status_id) + + return http.get(app, user, url).json() + + def _get_next_path(headers): """Given timeline response headers, returns the path to the next batch""" links = headers.get('Link', '') diff --git a/toot/commands.py b/toot/commands.py index cae3db9..b86c2ff 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -144,6 +144,11 @@ def unpin(app, user, args): print_out("✓ Status unpinned") +def reblogged_by(app, user, args): + for account in api.reblogged_by(app, user, args.status_id): + print_out("{}\n @{}".format(account['display_name'], account['acct'])) + + def auth(app, user, args): config_data = config.load_config() diff --git a/toot/console.py b/toot/console.py index 0689bfb..f61573c 100644 --- a/toot/console.py +++ b/toot/console.py @@ -316,6 +316,12 @@ STATUS_COMMANDS = [ arguments=[status_id_arg], require_auth=True, ), + Command( + name="reblogged_by", + description="Show accounts that reblogged the status", + arguments=[status_id_arg], + require_auth=False, + ), Command( name="pin", description="Pin a status",