2023-11-21 13:42:13 +01:00
|
|
|
import json
|
2023-03-30 10:56:03 +02:00
|
|
|
import time
|
|
|
|
import pytest
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
from toot import api, cli
|
2023-03-30 10:56:03 +02:00
|
|
|
from toot.exceptions import NotFoundError
|
|
|
|
|
|
|
|
|
2023-11-21 13:42:13 +01:00
|
|
|
def test_delete(app, user, run):
|
2023-11-21 12:19:07 +01:00
|
|
|
status = api.post_status(app, user, "foo").json()
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.delete, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status deleted"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
|
|
|
with pytest.raises(NotFoundError):
|
|
|
|
api.fetch_status(app, user, status["id"])
|
|
|
|
|
|
|
|
|
2023-11-21 13:42:13 +01:00
|
|
|
def test_delete_json(app, user, run):
|
|
|
|
status = api.post_status(app, user, "foo").json()
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.delete, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout
|
2023-11-21 13:42:13 +01:00
|
|
|
result = json.loads(out)
|
|
|
|
assert result["id"] == status["id"]
|
|
|
|
|
|
|
|
with pytest.raises(NotFoundError):
|
|
|
|
api.fetch_status(app, user, status["id"])
|
|
|
|
|
|
|
|
|
2023-03-30 10:56:03 +02:00
|
|
|
def test_favourite(app, user, run):
|
2023-11-21 12:19:07 +01:00
|
|
|
status = api.post_status(app, user, "foo").json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["favourited"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.favourite, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status favourited"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert status["favourited"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unfavourite, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status unfavourited"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
|
|
|
# A short delay is required before the server returns new data
|
2023-11-28 12:26:08 +01:00
|
|
|
time.sleep(0.2)
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["favourited"]
|
|
|
|
|
|
|
|
|
2023-11-21 13:42:13 +01:00
|
|
|
def test_favourite_json(app, user, run):
|
|
|
|
status = api.post_status(app, user, "foo").json()
|
|
|
|
assert not status["favourited"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.favourite, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["id"] == status["id"]
|
|
|
|
assert result["favourited"] is True
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unfavourite, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["id"] == status["id"]
|
|
|
|
assert result["favourited"] is False
|
|
|
|
|
|
|
|
|
2023-03-30 10:56:03 +02:00
|
|
|
def test_reblog(app, user, run):
|
2023-11-21 12:19:07 +01:00
|
|
|
status = api.post_status(app, user, "foo").json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["reblogged"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.reblogged_by, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "This status is not reblogged by anyone"
|
|
|
|
|
|
|
|
result = run(cli.reblog, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status reblogged"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert status["reblogged"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.reblogged_by, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert user.username in result.stdout
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unreblog, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status unreblogged"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["reblogged"]
|
|
|
|
|
|
|
|
|
2023-11-21 13:42:13 +01:00
|
|
|
def test_reblog_json(app, user, run):
|
|
|
|
status = api.post_status(app, user, "foo").json()
|
|
|
|
assert not status["reblogged"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.reblog, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["reblogged"] is True
|
|
|
|
assert result["reblog"]["id"] == status["id"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.reblogged_by, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
[reblog] = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert reblog["acct"] == user.username
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unreblog, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["reblogged"] is False
|
|
|
|
assert result["reblog"] is None
|
|
|
|
|
|
|
|
|
2023-03-30 10:56:03 +02:00
|
|
|
def test_pin(app, user, run):
|
2023-11-21 12:19:07 +01:00
|
|
|
status = api.post_status(app, user, "foo").json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["pinned"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.pin, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status pinned"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert status["pinned"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unpin, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status unpinned"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["pinned"]
|
|
|
|
|
|
|
|
|
2023-11-21 13:42:13 +01:00
|
|
|
def test_pin_json(app, user, run):
|
|
|
|
status = api.post_status(app, user, "foo").json()
|
|
|
|
assert not status["pinned"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.pin, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["pinned"] is True
|
|
|
|
assert result["id"] == status["id"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unpin, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["pinned"] is False
|
|
|
|
assert result["id"] == status["id"]
|
|
|
|
|
|
|
|
|
2023-03-30 10:56:03 +02:00
|
|
|
def test_bookmark(app, user, run):
|
2023-11-21 12:19:07 +01:00
|
|
|
status = api.post_status(app, user, "foo").json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["bookmarked"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.bookmark, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status bookmarked"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert status["bookmarked"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unbookmark, status["id"])
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Status unbookmarked"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-21 13:08:16 +01:00
|
|
|
status = api.fetch_status(app, user, status["id"]).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert not status["bookmarked"]
|
2023-11-21 13:42:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bookmark_json(app, user, run):
|
|
|
|
status = api.post_status(app, user, "foo").json()
|
|
|
|
assert not status["bookmarked"]
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.bookmark, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["id"] == status["id"]
|
|
|
|
assert result["bookmarked"] is True
|
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = run(cli.unbookmark, status["id"], "--json")
|
|
|
|
assert result.exit_code == 0
|
2023-11-21 13:42:13 +01:00
|
|
|
|
2023-11-28 12:26:08 +01:00
|
|
|
result = json.loads(result.stdout)
|
2023-11-21 13:42:13 +01:00
|
|
|
assert result["id"] == status["id"]
|
|
|
|
assert result["bookmarked"] is False
|