1
0
mirror of https://github.com/ihabunek/toot.git synced 2025-02-02 15:07:51 -05:00

Use assert_ok helper for better testing errors

This commit is contained in:
Ivan Habunek 2024-09-22 20:02:22 +02:00
parent 74a73d1c2d
commit 3ff9bc7942
No known key found for this signature in database
GPG Key ID: 01DB3DD0D824504C
10 changed files with 156 additions and 153 deletions

View File

@ -129,7 +129,7 @@ def run_json(app, user, runner):
def _run_json(command, *params):
obj = TootObj(test_ctx=Context(app, user))
result = runner.invoke(command, params, obj=obj)
assert result.exit_code == 0
assert_ok(result)
return json.loads(result.stdout)
return _run_json

View File

@ -1,5 +1,5 @@
import json
from tests.integration.conftest import register_account
from tests.integration.conftest import assert_ok, register_account
from toot import App, User, api, cli
from toot.entities import Account, Relationship, from_dict
@ -7,7 +7,7 @@ from toot.entities import Account, Relationship, from_dict
def test_whoami(user: User, run):
result = run(cli.read.whoami)
assert result.exit_code == 0
assert_ok(result)
# TODO: test other fields once updating account is supported
out = result.stdout.strip()
@ -16,7 +16,7 @@ def test_whoami(user: User, run):
def test_whoami_json(user: User, run):
result = run(cli.read.whoami, "--json")
assert result.exit_code == 0
assert_ok(result)
account = from_dict(Account, json.loads(result.stdout))
assert account.username == user.username
@ -32,7 +32,7 @@ def test_whois(app: App, friend: User, run):
for username in variants:
result = run(cli.read.whois, username)
assert result.exit_code == 0
assert_ok(result)
assert f"@{friend.username}" in result.stdout
@ -40,35 +40,35 @@ def test_following(app: App, user: User, run):
friend = register_account(app)
result = run(cli.accounts.following, user.username)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == ""
result = run(cli.accounts.follow, friend.username)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == f"✓ You are now following {friend.username}"
result = run(cli.accounts.following, user.username)
assert result.exit_code == 0
assert_ok(result)
assert friend.username in result.stdout.strip()
# If no account is given defaults to logged in user
result = run(cli.accounts.following)
assert result.exit_code == 0
assert_ok(result)
assert friend.username in result.stdout.strip()
result = run(cli.accounts.unfollow, friend.username)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == f"✓ You are no longer following {friend.username}"
result = run(cli.accounts.following, user.username)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == ""
def test_following_case_insensitive(user: User, friend: User, run):
assert friend.username != friend.username.upper()
result = run(cli.accounts.follow, friend.username.upper())
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == f"✓ You are now following {friend.username.upper()}"
@ -128,31 +128,31 @@ def test_mute(app, user, friend, friend_id, run):
api.unmute(app, user, friend_id)
result = run(cli.accounts.muted)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == "No accounts muted"
result = run(cli.accounts.mute, friend.username)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == f"✓ You have muted {friend.username}"
result = run(cli.accounts.muted)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert friend.username in out
result = run(cli.accounts.unmute, friend.username)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == f"{friend.username} is no longer muted"
result = run(cli.accounts.muted)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == "No accounts muted"
@ -160,7 +160,7 @@ def test_mute(app, user, friend, friend_id, run):
def test_mute_case_insensitive(friend: User, run):
result = run(cli.accounts.mute, friend.username.upper())
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == f"✓ You have muted {friend.username.upper()}"
@ -205,31 +205,31 @@ def test_block(app, user, run):
friend = register_account(app)
result = run(cli.accounts.blocked)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == "No accounts blocked"
result = run(cli.accounts.block, friend.username)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == f"✓ You are now blocking {friend.username}"
result = run(cli.accounts.blocked)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert friend.username in out
result = run(cli.accounts.unblock, friend.username)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == f"{friend.username} is no longer blocked"
result = run(cli.accounts.blocked)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == "No accounts blocked"
@ -237,7 +237,7 @@ def test_block(app, user, run):
def test_block_case_insensitive(friend: User, run):
result = run(cli.accounts.block, friend.username.upper())
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert out == f"✓ You are now blocking {friend.username.upper()}"

View File

@ -3,7 +3,7 @@ from unittest import mock
from unittest.mock import MagicMock
from toot import User, cli
from tests.integration.conftest import PASSWORD, Run
from tests.integration.conftest import PASSWORD, Run, assert_ok
# TODO: figure out how to test login
@ -47,7 +47,7 @@ SAMPLE_CONFIG = {
def test_env(run: Run):
result = run(cli.auth.env)
assert result.exit_code == 0
assert_ok(result)
assert "toot" in result.stdout
assert "Python" in result.stdout
@ -56,7 +56,7 @@ def test_env(run: Run):
def test_auth_empty(load_config: MagicMock, run: Run):
load_config.return_value = EMPTY_CONFIG
result = run(cli.auth.auth)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You are not logged in to any accounts"
@ -64,7 +64,7 @@ def test_auth_empty(load_config: MagicMock, run: Run):
def test_auth_full(load_config: MagicMock, run: Run):
load_config.return_value = SAMPLE_CONFIG
result = run(cli.auth.auth)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip().startswith("Authenticated accounts:")
assert "frank@foo.social" in result.stdout
assert "frank@bar.social" in result.stdout
@ -91,7 +91,7 @@ def test_login_cli(
"--email", f"{user.username}@example.com",
"--password", PASSWORD,
)
assert result.exit_code == 0
assert_ok(result)
assert "✓ Successfully logged in." in result.stdout
save_app.assert_called_once()
@ -147,7 +147,7 @@ def test_logout(delete_user: MagicMock, load_config: MagicMock, run: Run):
load_config.return_value = SAMPLE_CONFIG
result = run(cli.auth.logout, "frank@foo.social")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account frank@foo.social logged out"
delete_user.assert_called_once_with(User("foo.social", "frank", "123"))
@ -185,7 +185,7 @@ def test_activate(activate_user: MagicMock, load_config: MagicMock, run: Run):
load_config.return_value = SAMPLE_CONFIG
result = run(cli.auth.activate, "frank@foo.social")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account frank@foo.social activated"
activate_user.assert_called_once_with(User("foo.social", "frank", "123"))

View File

@ -1,12 +1,12 @@
from uuid import uuid4
from toot import cli
from tests.integration.conftest import register_account
from tests.integration.conftest import assert_ok, register_account
def test_lists_empty(run):
result = run(cli.lists.list)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You have no lists defined."
@ -17,37 +17,37 @@ def test_lists_empty_json(run_json):
def test_list_create_delete(run):
result = run(cli.lists.create, "banana")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == '✓ List "banana" created.'
result = run(cli.lists.list)
assert result.exit_code == 0
assert_ok(result)
assert "banana" in result.stdout
result = run(cli.lists.create, "mango")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == '✓ List "mango" created.'
result = run(cli.lists.list)
assert result.exit_code == 0
assert_ok(result)
assert "banana" in result.stdout
assert "mango" in result.stdout
result = run(cli.lists.delete, "banana")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == '✓ List "banana" deleted.'
result = run(cli.lists.list)
assert result.exit_code == 0
assert_ok(result)
assert "banana" not in result.stdout
assert "mango" in result.stdout
result = run(cli.lists.delete, "mango")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == '✓ List "mango" deleted.'
result = run(cli.lists.list)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You have no lists defined."
result = run(cli.lists.delete, "mango")
@ -102,11 +102,11 @@ def test_list_add_remove(run, app):
run(cli.accounts.follow, acc.username)
result = run(cli.lists.add, list_name, acc.username)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == f'✓ Added account "{acc.username}"'
result = run(cli.lists.accounts, list_name)
assert result.exit_code == 0
assert_ok(result)
assert acc.username in result.stdout
# Account doesn't exist
@ -120,11 +120,11 @@ def test_list_add_remove(run, app):
assert result.stderr.strip() == "Error: List not found"
result = run(cli.lists.remove, list_name, acc.username)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == f'✓ Removed account "{acc.username}"'
result = run(cli.lists.accounts, list_name)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "This list has no accounts."

View File

@ -4,16 +4,17 @@ import uuid
from datetime import datetime, timedelta, timezone
from os import path
from tests.integration.conftest import ASSETS_DIR, posted_status_id
from tests.integration.conftest import ASSETS_DIR, Run, assert_ok, posted_status_id
from toot import CLIENT_NAME, CLIENT_WEBSITE, api, cli
from toot.utils import get_text
from unittest import mock
def test_post(app, user, run):
def test_post(app, user, run: Run):
text = "i wish i was a #lumberjack"
result = run(cli.post.post, text)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
@ -39,7 +40,7 @@ def test_post_no_text(run):
def test_post_json(run):
content = "i wish i was a #lumberjack"
result = run(cli.post.post, content, "--json")
assert result.exit_code == 0
assert_ok(result)
status = json.loads(result.stdout)
assert get_text(status["content"]) == content
@ -52,7 +53,7 @@ def test_post_json(run):
def test_post_visibility(app, user, run):
for visibility in ["public", "unlisted", "private", "direct"]:
result = run(cli.post.post, "foo", "--visibility", visibility)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
@ -64,7 +65,7 @@ def test_post_scheduled_at(app, user, run):
scheduled_at = datetime.now(timezone.utc).replace(microsecond=0) + timedelta(minutes=10)
result = run(cli.post.post, text, "--scheduled-at", scheduled_at.isoformat())
assert result.exit_code == 0
assert_ok(result)
assert "Toot scheduled for" in result.stdout
@ -97,7 +98,7 @@ def test_post_scheduled_in(app, user, run):
datetimes = []
for scheduled_in, delta in variants:
result = run(cli.post.post, text, "--scheduled-in", scheduled_in)
assert result.exit_code == 0
assert_ok(result)
dttm = datetime.utcnow() + delta
assert result.stdout.startswith(f"Toot scheduled for: {str(dttm)[:16]}")
@ -137,7 +138,7 @@ def test_post_poll(app, user, run):
"--poll-option", "qux",
)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
@ -166,7 +167,7 @@ def test_post_poll_multiple(app, user, run):
"--poll-option", "bar",
"--poll-multiple"
)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
@ -182,7 +183,7 @@ def test_post_poll_expires_in(app, user, run):
"--poll-option", "bar",
"--poll-expires-in", "8h",
)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
@ -202,7 +203,7 @@ def test_post_poll_hide_totals(app, user, run):
"--poll-option", "bar",
"--poll-hide-totals"
)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
@ -217,14 +218,14 @@ def test_post_poll_hide_totals(app, user, run):
def test_post_language(app, user, run):
result = run(cli.post.post, "test", "--language", "hr")
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
assert status["language"] == "hr"
result = run(cli.post.post, "test", "--language", "zh")
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
@ -248,7 +249,7 @@ def test_media_thumbnail(app, user, run):
"--description", "foo",
"some text"
)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
@ -287,7 +288,7 @@ def test_media_attachments(app, user, run):
"--description", "Test 4",
"some text"
)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
status = api.fetch_status(app, user, status_id).json()
@ -324,7 +325,7 @@ def test_media_attachment_without_text(mock_read, mock_ml, app, user, run):
media_path = path.join(ASSETS_DIR, "test1.png")
result = run(cli.post.post, "--media", media_path)
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
@ -343,7 +344,7 @@ def test_reply_thread(app, user, friend, run):
status = api.post_status(app, friend, "This is the status").json()
result = run(cli.post.post, "--reply-to", status["id"], "This is the reply")
assert result.exit_code == 0
assert_ok(result)
status_id = posted_status_id(result.stdout)
reply = api.fetch_status(app, user, status_id).json()
@ -351,7 +352,7 @@ def test_reply_thread(app, user, friend, run):
assert reply["in_reply_to_id"] == status["id"]
result = run(cli.read.thread, status["id"])
assert result.exit_code == 0
assert_ok(result)
[s1, s2] = [s.strip() for s in re.split(r"─+", result.stdout) if s.strip()]

View File

@ -1,7 +1,7 @@
import json
import re
from tests.integration.conftest import TOOT_TEST_BASE_URL
from tests.integration.conftest import TOOT_TEST_BASE_URL, assert_ok
from toot import api, cli
from toot.entities import Account, Status, from_dict, from_dict_list
from uuid import uuid4
@ -9,7 +9,7 @@ from uuid import uuid4
def test_instance_default(app, run):
result = run(cli.read.instance)
assert result.exit_code == 0
assert_ok(result)
assert "Mastodon" in result.stdout
assert app.instance in result.stdout
@ -18,7 +18,7 @@ def test_instance_default(app, run):
def test_instance_with_url(app, run):
result = run(cli.read.instance, TOOT_TEST_BASE_URL)
assert result.exit_code == 0
assert_ok(result)
assert "Mastodon" in result.stdout
assert app.instance in result.stdout
@ -27,7 +27,7 @@ def test_instance_with_url(app, run):
def test_instance_json(app, run):
result = run(cli.read.instance, "--json")
assert result.exit_code == 0
assert_ok(result)
data = json.loads(result.stdout)
assert data["title"] is not None
@ -37,7 +37,7 @@ def test_instance_json(app, run):
def test_instance_anon(app, run_anon, base_url):
result = run_anon(cli.read.instance, base_url)
assert result.exit_code == 0
assert_ok(result)
assert "Mastodon" in result.stdout
assert app.instance in result.stdout
@ -51,13 +51,13 @@ def test_instance_anon(app, run_anon, base_url):
def test_whoami(user, run):
result = run(cli.read.whoami)
assert result.exit_code == 0
assert_ok(result)
assert f"@{user.username}" in result.stdout
def test_whoami_json(user, run):
result = run(cli.read.whoami, "--json")
assert result.exit_code == 0
assert_ok(result)
data = json.loads(result.stdout)
account = from_dict(Account, data)
@ -75,13 +75,13 @@ def test_whois(app, friend, run):
for username in variants:
result = run(cli.read.whois, username)
assert result.exit_code == 0
assert_ok(result)
assert f"@{friend.username}" in result.stdout
def test_whois_json(app, friend, run):
result = run(cli.read.whois, friend.username, "--json")
assert result.exit_code == 0
assert_ok(result)
data = json.loads(result.stdout)
account = from_dict(Account, data)
@ -91,13 +91,13 @@ def test_whois_json(app, friend, run):
def test_search_account(friend, run):
result = run(cli.read.search, friend.username)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == f"Accounts:\n* @{friend.username}"
def test_search_account_json(friend, run):
result = run(cli.read.search, friend.username, "--json")
assert result.exit_code == 0
assert_ok(result)
data = json.loads(result.stdout)
[account] = from_dict_list(Account, data["accounts"])
@ -110,7 +110,7 @@ def test_search_hashtag(app, user, run):
api.post_status(app, user, "#hashtag_z")
result = run(cli.read.search, "#hashtag")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "Hashtags:\n#hashtag_x, #hashtag_y, #hashtag_z"
@ -120,7 +120,7 @@ def test_search_hashtag_json(app, user, run):
api.post_status(app, user, "#hashtag_z")
result = run(cli.read.search, "#hashtag", "--json")
assert result.exit_code == 0
assert_ok(result)
data = json.loads(result.stdout)
[h1, h2, h3] = sorted(data["hashtags"], key=lambda h: h["name"])
@ -135,7 +135,7 @@ def test_status(app, user, run):
status_id = api.post_status(app, user, uuid).json()["id"]
result = run(cli.read.status, status_id)
assert result.exit_code == 0
assert_ok(result)
out = result.stdout.strip()
assert uuid in out
@ -148,7 +148,7 @@ def test_status_json(app, user, run):
status_id = api.post_status(app, user, uuid).json()["id"]
result = run(cli.read.status, status_id, "--json")
assert result.exit_code == 0
assert_ok(result)
status = from_dict(Status, json.loads(result.stdout))
assert status.id == status_id
@ -167,7 +167,7 @@ def test_thread(app, user, run):
for status in [s1, s2, s3]:
result = run(cli.read.thread, status["id"])
assert result.exit_code == 0
assert_ok(result)
bits = re.split(r"─+", result.stdout.strip())
bits = [b for b in bits if b]
@ -193,7 +193,7 @@ def test_thread_json(app, user, run):
s3 = api.post_status(app, user, uuid3, in_reply_to_id=s2["id"]).json()
result = run(cli.read.thread, s2["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
[ancestor] = [from_dict(Status, s) for s in result["ancestors"]]

View File

@ -1,6 +1,7 @@
import json
import pytest
from tests.integration.conftest import assert_ok
from tests.utils import run_with_retries
from toot import api, cli
from toot.exceptions import NotFoundError
@ -10,7 +11,7 @@ def test_delete(app, user, run):
status = api.post_status(app, user, "foo").json()
result = run(cli.statuses.delete, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status deleted"
with pytest.raises(NotFoundError):
@ -21,7 +22,7 @@ def test_delete_json(app, user, run):
status = api.post_status(app, user, "foo").json()
result = run(cli.statuses.delete, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
out = result.stdout
result = json.loads(out)
@ -36,14 +37,14 @@ def test_favourite(app, user, run):
assert not status["favourited"]
result = run(cli.statuses.favourite, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status favourited"
status = api.fetch_status(app, user, status["id"]).json()
assert status["favourited"]
result = run(cli.statuses.unfavourite, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status unfavourited"
def test_favourited():
@ -58,14 +59,14 @@ def test_favourite_json(app, user, run):
assert not status["favourited"]
result = run(cli.statuses.favourite, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
assert result["id"] == status["id"]
assert result["favourited"] is True
result = run(cli.statuses.unfavourite, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
assert result["id"] == status["id"]
@ -77,22 +78,22 @@ def test_reblog(app, user, run):
assert not status["reblogged"]
result = run(cli.statuses.reblogged_by, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "This status is not reblogged by anyone"
result = run(cli.statuses.reblog, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status reblogged"
status = api.fetch_status(app, user, status["id"]).json()
assert status["reblogged"]
result = run(cli.statuses.reblogged_by, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert user.username in result.stdout
result = run(cli.statuses.unreblog, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status unreblogged"
status = api.fetch_status(app, user, status["id"]).json()
@ -104,20 +105,20 @@ def test_reblog_json(app, user, run):
assert not status["reblogged"]
result = run(cli.statuses.reblog, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
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")
assert result.exit_code == 0
assert_ok(result)
[reblog] = json.loads(result.stdout)
assert reblog["acct"] == user.username
result = run(cli.statuses.unreblog, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
assert result["reblogged"] is False
@ -129,14 +130,14 @@ def test_pin(app, user, run):
assert not status["pinned"]
result = run(cli.statuses.pin, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status pinned"
status = api.fetch_status(app, user, status["id"]).json()
assert status["pinned"]
result = run(cli.statuses.unpin, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status unpinned"
status = api.fetch_status(app, user, status["id"]).json()
@ -148,14 +149,14 @@ def test_pin_json(app, user, run):
assert not status["pinned"]
result = run(cli.statuses.pin, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
assert result["pinned"] is True
assert result["id"] == status["id"]
result = run(cli.statuses.unpin, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
assert result["pinned"] is False
@ -167,14 +168,14 @@ def test_bookmark(app, user, run):
assert not status["bookmarked"]
result = run(cli.statuses.bookmark, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status bookmarked"
status = api.fetch_status(app, user, status["id"]).json()
assert status["bookmarked"]
result = run(cli.statuses.unbookmark, status["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Status unbookmarked"
status = api.fetch_status(app, user, status["id"]).json()
@ -186,14 +187,14 @@ def test_bookmark_json(app, user, run):
assert not status["bookmarked"]
result = run(cli.statuses.bookmark, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
assert result["id"] == status["id"]
assert result["bookmarked"] is True
result = run(cli.statuses.unbookmark, status["id"], "--json")
assert result.exit_code == 0
assert_ok(result)
result = json.loads(result.stdout)
assert result["id"] == status["id"]

View File

@ -1,45 +1,46 @@
import re
from typing import List
from tests.integration.conftest import assert_ok
from toot import api, cli
from toot.entities import FeaturedTag, Tag, from_dict, from_dict_list
def test_tags(run):
result = run(cli.tags.tags, "followed")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You're not following any hashtags"
result = run(cli.tags.tags, "follow", "foo")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ You are now following #foo"
result = run(cli.tags.tags, "followed")
assert result.exit_code == 0
assert_ok(result)
assert _find_tags(result.stdout) == ["#foo"]
result = run(cli.tags.tags, "follow", "bar")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ You are now following #bar"
result = run(cli.tags.tags, "followed")
assert result.exit_code == 0
assert_ok(result)
assert _find_tags(result.stdout) == ["#bar", "#foo"]
result = run(cli.tags.tags, "unfollow", "foo")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ You are no longer following #foo"
result = run(cli.tags.tags, "followed")
assert result.exit_code == 0
assert_ok(result)
assert _find_tags(result.stdout) == ["#bar"]
result = run(cli.tags.tags, "unfollow", "bar")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ You are no longer following #bar"
result = run(cli.tags.tags, "followed")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You're not following any hashtags"
@ -86,32 +87,32 @@ def test_tags_json(run_json):
def test_tags_featured(run, app, user):
result = run(cli.tags.tags, "featured")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You don't have any featured hashtags"
result = run(cli.tags.tags, "feature", "foo")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Tag #foo is now featured"
result = run(cli.tags.tags, "featured")
assert result.exit_code == 0
assert_ok(result)
assert _find_tags(result.stdout) == ["#foo"]
result = run(cli.tags.tags, "feature", "bar")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Tag #bar is now featured"
result = run(cli.tags.tags, "featured")
assert result.exit_code == 0
assert_ok(result)
assert _find_tags(result.stdout) == ["#bar", "#foo"]
# Unfeature by Name
result = run(cli.tags.tags, "unfeature", "foo")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Tag #foo is no longer featured"
result = run(cli.tags.tags, "featured")
assert result.exit_code == 0
assert_ok(result)
assert _find_tags(result.stdout) == ["#bar"]
# Unfeature by ID
@ -119,11 +120,11 @@ def test_tags_featured(run, app, user):
assert tag is not None
result = run(cli.tags.tags, "unfeature", tag["id"])
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Tag #bar is no longer featured"
result = run(cli.tags.tags, "featured")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You don't have any featured hashtags"

View File

@ -5,7 +5,7 @@ from tests.utils import run_with_retries
from toot import api, cli
from toot.entities import from_dict, Status
from tests.integration.conftest import TOOT_TEST_BASE_URL, register_account
from tests.integration.conftest import TOOT_TEST_BASE_URL, assert_ok, register_account
# TODO: If fixture is not overridden here, tests fail, not sure why, figure it out
@ -43,7 +43,7 @@ def test_timelines(app, user, other_user, friend_user, friend_list, run):
# Home timeline
def test_home():
result = run(cli.timelines.timeline)
assert result.exit_code == 0
assert_ok(result)
assert status1.id in result.stdout
assert status2.id not in result.stdout
assert status3.id in result.stdout
@ -51,61 +51,61 @@ def test_timelines(app, user, other_user, friend_user, friend_list, run):
# Public timeline
result = run(cli.timelines.timeline, "--public")
assert result.exit_code == 0
assert_ok(result)
assert status1.id in result.stdout
assert status2.id in result.stdout
assert status3.id in result.stdout
# Anon public timeline
result = run(cli.timelines.timeline, "--instance", TOOT_TEST_BASE_URL, "--public")
assert result.exit_code == 0
assert_ok(result)
assert status1.id in result.stdout
assert status2.id in result.stdout
assert status3.id in result.stdout
# Tag timeline
result = run(cli.timelines.timeline, "--tag", "foo")
assert result.exit_code == 0
assert_ok(result)
assert status1.id in result.stdout
assert status2.id not in result.stdout
assert status3.id in result.stdout
result = run(cli.timelines.timeline, "--tag", "bar")
assert result.exit_code == 0
assert_ok(result)
assert status1.id not in result.stdout
assert status2.id in result.stdout
assert status3.id in result.stdout
# Anon tag timeline
result = run(cli.timelines.timeline, "--instance", TOOT_TEST_BASE_URL, "--tag", "foo")
assert result.exit_code == 0
assert_ok(result)
assert status1.id in result.stdout
assert status2.id not in result.stdout
assert status3.id in result.stdout
# List timeline (by list name)
result = run(cli.timelines.timeline, "--list", friend_list["title"])
assert result.exit_code == 0
assert_ok(result)
assert status1.id not in result.stdout
assert status2.id not in result.stdout
assert status3.id in result.stdout
# List timeline (by list ID)
result = run(cli.timelines.timeline, "--list", friend_list["id"])
assert result.exit_code == 0
assert_ok(result)
assert status1.id not in result.stdout
assert status2.id not in result.stdout
assert status3.id in result.stdout
# Account timeline
result = run(cli.timelines.timeline, "--account", friend_user.username)
assert result.exit_code == 0
assert_ok(result)
assert status1.id not in result.stdout
assert status2.id not in result.stdout
assert status3.id in result.stdout
result = run(cli.timelines.timeline, "--account", other_user.username)
assert result.exit_code == 0
assert_ok(result)
assert status1.id not in result.stdout
assert status2.id in result.stdout
assert status3.id not in result.stdout
@ -114,7 +114,7 @@ def test_timelines(app, user, other_user, friend_user, friend_list, run):
def test_empty_timeline(app, run_as):
user = register_account(app)
result = run_as(user, cli.timelines.timeline)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "" * 80
@ -144,14 +144,14 @@ def test_bookmarks(app, user, run):
api.bookmark(app, user, status2.id)
result = run(cli.timelines.bookmarks)
assert result.exit_code == 0
assert_ok(result)
assert status1.id in result.stdout
assert status2.id in result.stdout
assert result.stdout.find(status1.id) > result.stdout.find(status2.id)
result = run(cli.timelines.bookmarks, "--reverse")
assert result.exit_code == 0
assert_ok(result)
assert status1.id in result.stdout
assert status2.id in result.stdout
assert result.stdout.find(status1.id) < result.stdout.find(status2.id)
@ -159,7 +159,7 @@ def test_bookmarks(app, user, run):
def test_notifications(app, user, other_user, run):
result = run(cli.timelines.notifications)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "You have no notifications"
text = f"Paging doctor @{user.username}"
@ -167,14 +167,14 @@ def test_notifications(app, user, other_user, run):
def test_notifications():
result = run(cli.timelines.notifications)
assert result.exit_code == 0
assert_ok(result)
assert f"@{other_user.username} mentioned you" in result.stdout
assert status.id in result.stdout
assert text in result.stdout
run_with_retries(test_notifications)
result = run(cli.timelines.notifications, "--mentions")
assert result.exit_code == 0
assert_ok(result)
assert f"@{other_user.username} mentioned you" in result.stdout
assert status.id in result.stdout
assert text in result.stdout
@ -182,11 +182,11 @@ def test_notifications(app, user, other_user, run):
def test_notifications_follow(app, user, friend_user, run_as):
result = run_as(friend_user, cli.timelines.notifications)
assert result.exit_code == 0
assert_ok(result)
assert f"@{user.username} now follows you" in result.stdout
result = run_as(friend_user, cli.timelines.notifications, "--mentions")
assert result.exit_code == 0
assert_ok(result)
assert "now follows you" not in result.stdout

View File

@ -1,5 +1,5 @@
from uuid import uuid4
from tests.integration.conftest import TRUMPET
from tests.integration.conftest import TRUMPET, assert_ok
from toot import api, cli
from toot.entities import Account, from_dict
from toot.utils import get_text
@ -15,7 +15,7 @@ def test_update_account_display_name(run, app, user):
name = str(uuid4())[:10]
result = run(cli.accounts.update_account, "--display-name", name)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -35,7 +35,7 @@ def test_update_account_note(run, app, user):
"of cigarettes, it's dark... and we're wearing sunglasses.")
result = run(cli.accounts.update_account, "--note", note)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -44,7 +44,7 @@ def test_update_account_note(run, app, user):
def test_update_account_language(run, app, user):
result = run(cli.accounts.update_account, "--language", "hr")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -53,7 +53,7 @@ def test_update_account_language(run, app, user):
def test_update_account_privacy(run, app, user):
result = run(cli.accounts.update_account, "--privacy", "private")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -65,7 +65,7 @@ def test_update_account_avatar(run, app, user):
old_value = account["avatar"]
result = run(cli.accounts.update_account, "--avatar", TRUMPET)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -77,7 +77,7 @@ def test_update_account_header(run, app, user):
old_value = account["header"]
result = run(cli.accounts.update_account, "--header", TRUMPET)
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -86,14 +86,14 @@ def test_update_account_header(run, app, user):
def test_update_account_locked(run, app, user):
result = run(cli.accounts.update_account, "--locked")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
assert account["locked"] is True
result = run(cli.accounts.update_account, "--no-locked")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -103,14 +103,14 @@ def test_update_account_locked(run, app, user):
def test_update_account_bot(run, app, user):
result = run(cli.accounts.update_account, "--bot")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
assert account["bot"] is True
result = run(cli.accounts.update_account, "--no-bot")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -119,14 +119,14 @@ def test_update_account_bot(run, app, user):
def test_update_account_discoverable(run, app, user):
result = run(cli.accounts.update_account, "--discoverable")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
assert account["discoverable"] is True
result = run(cli.accounts.update_account, "--no-discoverable")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
@ -135,14 +135,14 @@ def test_update_account_discoverable(run, app, user):
def test_update_account_sensitive(run, app, user):
result = run(cli.accounts.update_account, "--sensitive")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()
assert account["source"]["sensitive"] is True
result = run(cli.accounts.update_account, "--no-sensitive")
assert result.exit_code == 0
assert_ok(result)
assert result.stdout.strip() == "✓ Account updated"
account = api.verify_credentials(app, user).json()