Add --json option to post command
This commit is contained in:
parent
3530553a06
commit
7793d4499a
7 changed files with 42 additions and 19 deletions
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
import re
|
||||
import uuid
|
||||
|
||||
|
@ -27,6 +28,18 @@ def test_post(app, user, run):
|
|||
assert status["application"]["website"] == CLIENT_WEBSITE
|
||||
|
||||
|
||||
def test_post_json(run):
|
||||
content = "i wish i was a #lumberjack"
|
||||
out = run("post", content, "--json")
|
||||
status = json.loads(out)
|
||||
|
||||
assert get_text(status["content"]) == content
|
||||
assert status["visibility"] == "public"
|
||||
assert status["sensitive"] is False
|
||||
assert status["spoiler_text"] == ""
|
||||
assert status["poll"] is None
|
||||
|
||||
|
||||
def test_post_visibility(app, user, run):
|
||||
for visibility in ["public", "unlisted", "private", "direct"]:
|
||||
out = run("post", "foo", "--visibility", visibility)
|
||||
|
@ -269,7 +282,7 @@ def test_media_attachment_without_text(mock_read, mock_ml, app, user, run):
|
|||
|
||||
|
||||
def test_reply_thread(app, user, friend, run):
|
||||
status = api.post_status(app, friend, "This is the status")
|
||||
status = api.post_status(app, friend, "This is the status").json()
|
||||
|
||||
out = run("post", "--reply-to", status["id"], "This is the reply")
|
||||
status_id = posted_status_id(out)
|
||||
|
|
|
@ -95,7 +95,7 @@ def test_tags(run, base_url):
|
|||
|
||||
def test_status(app, user, run):
|
||||
uuid = str(uuid4())
|
||||
response = api.post_status(app, user, uuid)
|
||||
response = api.post_status(app, user, uuid).json()
|
||||
|
||||
out = run("status", response["id"])
|
||||
assert uuid in out
|
||||
|
@ -105,9 +105,9 @@ def test_status(app, user, run):
|
|||
|
||||
def test_thread(app, user, run):
|
||||
uuid = str(uuid4())
|
||||
s1 = api.post_status(app, user, uuid + "1")
|
||||
s2 = api.post_status(app, user, uuid + "2", in_reply_to_id=s1["id"])
|
||||
s3 = api.post_status(app, user, uuid + "3", in_reply_to_id=s2["id"])
|
||||
s1 = api.post_status(app, user, uuid + "1").json()
|
||||
s2 = api.post_status(app, user, uuid + "2", in_reply_to_id=s1["id"]).json()
|
||||
s3 = api.post_status(app, user, uuid + "3", in_reply_to_id=s2["id"]).json()
|
||||
|
||||
for status in [s1, s2, s3]:
|
||||
out = run("thread", status["id"])
|
||||
|
|
|
@ -6,7 +6,7 @@ from toot.exceptions import NotFoundError
|
|||
|
||||
|
||||
def test_delete_status(app, user, run):
|
||||
status = api.post_status(app, user, "foo")
|
||||
status = api.post_status(app, user, "foo").json()
|
||||
|
||||
out = run("delete", status["id"])
|
||||
assert out == "✓ Status deleted"
|
||||
|
@ -16,7 +16,7 @@ def test_delete_status(app, user, run):
|
|||
|
||||
|
||||
def test_favourite(app, user, run):
|
||||
status = api.post_status(app, user, "foo")
|
||||
status = api.post_status(app, user, "foo").json()
|
||||
assert not status["favourited"]
|
||||
|
||||
out = run("favourite", status["id"])
|
||||
|
@ -36,7 +36,7 @@ def test_favourite(app, user, run):
|
|||
|
||||
|
||||
def test_reblog(app, user, run):
|
||||
status = api.post_status(app, user, "foo")
|
||||
status = api.post_status(app, user, "foo").json()
|
||||
assert not status["reblogged"]
|
||||
|
||||
out = run("reblog", status["id"])
|
||||
|
@ -56,7 +56,7 @@ def test_reblog(app, user, run):
|
|||
|
||||
|
||||
def test_pin(app, user, run):
|
||||
status = api.post_status(app, user, "foo")
|
||||
status = api.post_status(app, user, "foo").json()
|
||||
assert not status["pinned"]
|
||||
|
||||
out = run("pin", status["id"])
|
||||
|
@ -73,7 +73,7 @@ def test_pin(app, user, run):
|
|||
|
||||
|
||||
def test_bookmark(app, user, run):
|
||||
status = api.post_status(app, user, "foo")
|
||||
status = api.post_status(app, user, "foo").json()
|
||||
assert not status["bookmarked"]
|
||||
|
||||
out = run("bookmark", status["id"])
|
||||
|
|
|
@ -201,7 +201,7 @@ def post_status(
|
|||
poll_expires_in=None,
|
||||
poll_multiple=None,
|
||||
poll_hide_totals=None,
|
||||
):
|
||||
) -> Response:
|
||||
"""
|
||||
Publish a new status.
|
||||
https://docs.joinmastodon.org/methods/statuses/#create
|
||||
|
@ -233,7 +233,7 @@ def post_status(
|
|||
"hide_totals": poll_hide_totals,
|
||||
}
|
||||
|
||||
return http.post(app, user, '/api/v1/statuses', json=data, headers=headers).json()
|
||||
return http.post(app, user, '/api/v1/statuses', json=data, headers=headers)
|
||||
|
||||
|
||||
def fetch_status(app, user, id):
|
||||
|
|
|
@ -121,12 +121,16 @@ def post(app, user, args):
|
|||
poll_hide_totals=args.poll_hide_totals,
|
||||
)
|
||||
|
||||
if "scheduled_at" in response:
|
||||
scheduled_at = parse_datetime(response["scheduled_at"])
|
||||
scheduled_at = datetime.strftime(scheduled_at, "%Y-%m-%d %H:%M:%S%z")
|
||||
print_out(f"Toot scheduled for: <green>{scheduled_at}</green>")
|
||||
if args.json:
|
||||
print(response.text)
|
||||
else:
|
||||
print_out(f"Toot posted: <green>{response['url']}")
|
||||
status = response.json()
|
||||
if "scheduled_at" in status:
|
||||
scheduled_at = parse_datetime(status["scheduled_at"])
|
||||
scheduled_at = datetime.strftime(scheduled_at, "%Y-%m-%d %H:%M:%S%z")
|
||||
print_out(f"Toot scheduled for: <green>{scheduled_at}</green>")
|
||||
else:
|
||||
print_out(f"Toot posted: <green>{status['url']}")
|
||||
|
||||
delete_tmp_status_file()
|
||||
|
||||
|
|
|
@ -583,6 +583,7 @@ POST_COMMANDS = [
|
|||
"default": False,
|
||||
"help": "Hide vote counts until the poll ends. Defaults to false."
|
||||
}),
|
||||
json_arg,
|
||||
],
|
||||
require_auth=True,
|
||||
),
|
||||
|
|
|
@ -529,10 +529,15 @@ class TUI(urwid.Frame):
|
|||
))
|
||||
|
||||
def post_status(self, content, warning, visibility, in_reply_to_id):
|
||||
data = api.post_status(self.app, self.user, content,
|
||||
data = api.post_status(
|
||||
self.app,
|
||||
self.user,
|
||||
content,
|
||||
spoiler_text=warning,
|
||||
visibility=visibility,
|
||||
in_reply_to_id=in_reply_to_id)
|
||||
in_reply_to_id=in_reply_to_id
|
||||
).json()
|
||||
|
||||
status = self.make_status(data)
|
||||
|
||||
# TODO: fetch new items from the timeline?
|
||||
|
|
Loading…
Reference in a new issue