2023-11-18 09:00:39 -05:00
|
|
|
import json
|
|
|
|
|
2023-11-28 08:05:44 -05:00
|
|
|
from toot import App, User, api, cli
|
2023-11-21 12:16:23 -05:00
|
|
|
from toot.entities import Account, Relationship, from_dict
|
2023-03-30 04:56:03 -04:00
|
|
|
|
|
|
|
|
2023-11-21 12:16:23 -05:00
|
|
|
def test_whoami(user: User, run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.read.whoami)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
2023-03-30 04:56:03 -04:00
|
|
|
# TODO: test other fields once updating account is supported
|
2023-11-28 08:05:44 -05:00
|
|
|
out = result.stdout.strip()
|
2023-03-30 04:56:03 -04:00
|
|
|
assert f"@{user.username}" in out
|
|
|
|
|
|
|
|
|
2023-11-21 12:16:23 -05:00
|
|
|
def test_whoami_json(user: User, run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.read.whoami, "--json")
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
account = from_dict(Account, json.loads(result.stdout))
|
2023-11-18 09:00:39 -05:00
|
|
|
assert account.username == user.username
|
|
|
|
|
|
|
|
|
2023-11-21 12:16:23 -05:00
|
|
|
def test_whois(app: App, friend: User, run):
|
2023-03-30 04:56:03 -04:00
|
|
|
variants = [
|
|
|
|
friend.username,
|
|
|
|
f"@{friend.username}",
|
|
|
|
f"{friend.username}@{app.instance}",
|
|
|
|
f"@{friend.username}@{app.instance}",
|
|
|
|
]
|
|
|
|
|
|
|
|
for username in variants:
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.read.whois, username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert f"@{friend.username}" in result.stdout
|
2023-11-21 12:16:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_following(app: App, user: User, friend: User, friend_id, run):
|
|
|
|
# Make sure we're not initally following friend
|
|
|
|
api.unfollow(app, user, friend_id)
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.following, user.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == ""
|
2023-11-21 12:16:23 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.follow, friend.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == f"✓ You are now following {friend.username}"
|
2023-11-21 12:16:23 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.following, user.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert friend.username in result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
|
2023-11-22 02:22:21 -05:00
|
|
|
# If no account is given defaults to logged in user
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.following)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert friend.username in result.stdout.strip()
|
2023-11-22 02:22:21 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.unfollow, friend.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == f"✓ You are no longer following {friend.username}"
|
2023-11-21 12:16:23 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.following, user.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == ""
|
2023-11-21 12:16:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_following_case_insensitive(user: User, friend: User, run):
|
|
|
|
assert friend.username != friend.username.upper()
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.follow, friend.username.upper())
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == f"✓ You are now following {friend.username.upper()}"
|
|
|
|
|
|
|
|
|
|
|
|
def test_following_not_found(run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.follow, "bananaman")
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 1
|
|
|
|
assert result.stderr.strip() == "Error: Account not found"
|
2023-11-21 12:16:23 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.unfollow, "bananaman")
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 1
|
|
|
|
assert result.stderr.strip() == "Error: Account not found"
|
2023-11-21 12:16:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_following_json(app: App, user: User, friend: User, user_id, friend_id, run_json):
|
|
|
|
# Make sure we're not initally following friend
|
|
|
|
api.unfollow(app, user, friend_id)
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.following, user.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.followers, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.follow, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
relationship = from_dict(Relationship, result)
|
|
|
|
assert relationship.id == friend_id
|
|
|
|
assert relationship.following is True
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
[result] = run_json(cli.accounts.following, user.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
relationship = from_dict(Relationship, result)
|
|
|
|
assert relationship.id == friend_id
|
|
|
|
|
2023-11-22 02:22:21 -05:00
|
|
|
# If no account is given defaults to logged in user
|
2023-12-13 08:16:30 -05:00
|
|
|
[result] = run_json(cli.accounts.following, user.username, "--json")
|
2023-11-22 02:22:21 -05:00
|
|
|
relationship = from_dict(Relationship, result)
|
|
|
|
assert relationship.id == friend_id
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
[result] = run_json(cli.accounts.followers, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result["id"] == user_id
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.unfollow, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result["id"] == friend_id
|
|
|
|
assert result["following"] is False
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.following, user.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.followers, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|
|
|
|
|
|
|
|
|
|
|
|
def test_mute(app, user, friend, friend_id, run):
|
|
|
|
# Make sure we're not initially muting friend
|
|
|
|
api.unmute(app, user, friend_id)
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.muted)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == "No accounts muted"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.mute, friend.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == f"✓ You have muted {friend.username}"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.muted)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert friend.username in out
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.unmute, friend.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == f"✓ {friend.username} is no longer muted"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.muted)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == "No accounts muted"
|
|
|
|
|
|
|
|
|
|
|
|
def test_mute_case_insensitive(friend: User, run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.mute, friend.username.upper())
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == f"✓ You have muted {friend.username.upper()}"
|
|
|
|
|
|
|
|
|
|
|
|
def test_mute_not_found(run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.mute, "doesnotexistperson")
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 1
|
|
|
|
assert result.stderr.strip() == "Error: Account not found"
|
2023-11-21 12:16:23 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.unmute, "doesnotexistperson")
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 1
|
|
|
|
assert result.stderr.strip() == "Error: Account not found"
|
2023-11-21 12:16:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_mute_json(app: App, user: User, friend: User, run_json, friend_id):
|
|
|
|
# Make sure we're not initially muting friend
|
|
|
|
api.unmute(app, user, friend_id)
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.muted, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.mute, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
relationship = from_dict(Relationship, result)
|
|
|
|
assert relationship.id == friend_id
|
|
|
|
assert relationship.muting is True
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
[result] = run_json(cli.accounts.muted, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
account = from_dict(Account, result)
|
|
|
|
assert account.id == friend_id
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.unmute, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
relationship = from_dict(Relationship, result)
|
|
|
|
assert relationship.id == friend_id
|
|
|
|
assert relationship.muting is False
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.muted, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|
|
|
|
|
|
|
|
|
|
|
|
def test_block(app, user, friend, friend_id, run):
|
|
|
|
# Make sure we're not initially blocking friend
|
|
|
|
api.unblock(app, user, friend_id)
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.blocked)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == "No accounts blocked"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.block, friend.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == f"✓ You are now blocking {friend.username}"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.blocked)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert friend.username in out
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.unblock, friend.username)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == f"✓ {friend.username} is no longer blocked"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.blocked)
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == "No accounts blocked"
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_case_insensitive(friend: User, run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.block, friend.username.upper())
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
out = result.stdout.strip()
|
2023-11-21 12:16:23 -05:00
|
|
|
assert out == f"✓ You are now blocking {friend.username.upper()}"
|
|
|
|
|
|
|
|
|
|
|
|
def test_block_not_found(run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.accounts.block, "doesnotexistperson")
|
2023-11-28 08:05:44 -05:00
|
|
|
assert result.exit_code == 1
|
|
|
|
assert result.stderr.strip() == "Error: Account not found"
|
2023-11-21 12:16:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_block_json(app: App, user: User, friend: User, run_json, friend_id):
|
|
|
|
# Make sure we're not initially blocking friend
|
|
|
|
api.unblock(app, user, friend_id)
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.blocked, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.block, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
relationship = from_dict(Relationship, result)
|
|
|
|
assert relationship.id == friend_id
|
|
|
|
assert relationship.blocking is True
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
[result] = run_json(cli.accounts.blocked, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
account = from_dict(Account, result)
|
|
|
|
assert account.id == friend_id
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.unblock, friend.username, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
relationship = from_dict(Relationship, result)
|
|
|
|
assert relationship.id == friend_id
|
|
|
|
assert relationship.blocking is False
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.accounts.blocked, "--json")
|
2023-11-21 12:16:23 -05:00
|
|
|
assert result == []
|