From 7b4063fddca3236ea9e4c8edbe19b3a20ff3f33c Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Wed, 30 Nov 2022 08:55:46 +0100 Subject: [PATCH] Remove use of deprecated status.text_url --- tests/test_console.py | 3 ++- tests/test_integration.py | 22 ++++++++++++++++++++++ toot/commands.py | 18 +++++++++--------- toot/output.py | 2 +- toot/tui/timeline.py | 3 +-- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/tests/test_console.py b/tests/test_console.py index 56927ca..56e127c 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -293,13 +293,14 @@ def test_reblogged_by(mock_get, monkeypatch, capsys): ]) assert out == expected + @mock.patch('toot.http.post') def test_upload(mock_post, capsys): mock_post.return_value = MockResponse({ 'id': 123, 'url': 'https://bigfish.software/123/456', 'preview_url': 'https://bigfish.software/789/012', - 'text_url': 'https://bigfish.software/345/678', + 'url': 'https://bigfish.software/345/678', 'type': 'image', }) diff --git a/tests/test_integration.py b/tests/test_integration.py index cd9521e..35aa28f 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -25,6 +25,7 @@ from toot import CLIENT_NAME, CLIENT_WEBSITE, api, App, User from toot.console import run_command from toot.exceptions import ConsoleError, NotFoundError from toot.utils import get_text +from unittest import mock # Host name of a test instance to run integration tests against # DO NOT USE PUBLIC INSTANCES!!! @@ -181,6 +182,27 @@ def test_media_attachments(app, user, run): assert a4["description"] == "Test 4" +@mock.patch("toot.utils.multiline_input") +@mock.patch("sys.stdin.read") +def test_media_attachment_without_text(mock_read, mock_ml, app, user, run): + # No status from stdin or readline + mock_read.return_value = "" + mock_ml.return_value = "" + + assets_dir = path.realpath(path.join(path.dirname(__file__), "assets")) + media_path = path.join(assets_dir, "test1.png") + + out = run("post", "--media", media_path) + status_id = _posted_status_id(out) + + status = api.fetch_status(app, user, status_id) + assert status["content"] == "" + + [attachment] = status["media_attachments"] + assert attachment["meta"]["original"]["size"] == "50x50" + assert attachment["description"] is None + + def test_delete_status(app, user, run): status = api.post_status(app, user, "foo") diff --git a/toot/commands.py b/toot/commands.py index 559d26d..925e134 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -100,15 +100,16 @@ def post(app, user, args): media_ids = [m["id"] for m in uploaded_media] if uploaded_media and not args.text: - args.text = "\n".join(m['text_url'] for m in uploaded_media) + args.text = "\n".join(m['url'] for m in uploaded_media) - if args.editor: - args.text = editor_input(args.editor, args.text) - elif not args.text: - print_out("Write or paste your toot. Press {} to post it.".format(EOF_KEY)) - args.text = multiline_input() + if sys.stdin.isatty(): + if args.editor: + args.text = editor_input(args.editor, args.text) + elif not args.text: + print_out("Write or paste your toot. Press {} to post it.".format(EOF_KEY)) + args.text = multiline_input() - if not args.text: + if not args.text and not uploaded_media: raise ConsoleError("You must specify either text or media to post.") response = api.post_status( @@ -232,9 +233,8 @@ def upload(app, user, args): print_out() print_out(msg.format(response['id'], response['type'])) - print_out("Original URL: {}".format(response['url'])) + print_out("URL: {}".format(response['url'])) print_out("Preview URL: {}".format(response['preview_url'])) - print_out("Text URL: {}".format(response['text_url'])) def search(app, user, args): diff --git a/toot/output.py b/toot/output.py index 6d75e82..20ef3bb 100644 --- a/toot/output.py +++ b/toot/output.py @@ -196,7 +196,7 @@ def print_status(status, width): if media_attachments: print_out("\nMedia:") for attachment in media_attachments: - url = attachment['text_url'] or attachment['url'] + url = attachment["url"] for line in wc_wrap(url, width): print_out(line) diff --git a/toot/tui/timeline.py b/toot/tui/timeline.py index bcc89de..53ecb78 100644 --- a/toot/tui/timeline.py +++ b/toot/tui/timeline.py @@ -274,8 +274,7 @@ class StatusDetails(urwid.Pile): yield ("pack", urwid.Text([("bold", "Media attachment"), " (", m["type"], ")"])) if m["description"]: yield ("pack", urwid.Text(m["description"])) - url = m.get("text_url") or m["url"] - yield ("pack", urwid.Text(("link", url))) + yield ("pack", urwid.Text(("link", m["url"]))) poll = status.data.get("poll") if poll: