Remove use of deprecated status.text_url

This commit is contained in:
Ivan Habunek 2022-11-30 08:55:46 +01:00
parent e396768d15
commit 7b4063fddc
No known key found for this signature in database
GPG key ID: F5F0623FF5EBCB3D
5 changed files with 35 additions and 13 deletions

View file

@ -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',
})

View file

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

View file

@ -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 <yellow>{}</yellow> 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 <yellow>{}</yellow> 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: <green>{}</green>".format(response['url']))
print_out("URL: <green>{}</green>".format(response['url']))
print_out("Preview URL: <green>{}</green>".format(response['preview_url']))
print_out("Text URL: <green>{}</green>".format(response['text_url']))
def search(app, user, args):

View file

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

View file

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