1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-06-30 06:35:24 +00:00
toot/tests/integration/test_status.py

201 lines
5.9 KiB
Python
Raw Permalink Normal View History

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