2023-11-28 16:56:53 +01:00
|
|
|
from uuid import uuid4
|
2023-03-30 10:56:03 +02:00
|
|
|
from tests.integration.conftest import TRUMPET
|
2023-11-28 16:56:53 +01:00
|
|
|
from toot import api, cli
|
2023-11-22 08:41:15 +01:00
|
|
|
from toot.entities import Account, from_dict
|
2023-03-30 10:56:03 +02:00
|
|
|
from toot.utils import get_text
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_no_options(run):
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account)
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 1
|
|
|
|
assert result.stderr.strip() == "Error: Please specify at least one option to update the account"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_display_name(run, app, user):
|
2023-11-28 16:56:53 +01:00
|
|
|
name = str(uuid4())[:10]
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--display-name", name)
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-11-28 16:56:53 +01:00
|
|
|
assert account["display_name"] == name
|
2023-03-30 10:56:03 +02:00
|
|
|
|
|
|
|
|
2023-11-22 08:41:15 +01:00
|
|
|
def test_update_account_json(run_json, app, user):
|
2023-11-28 16:56:53 +01:00
|
|
|
name = str(uuid4())[:10]
|
2023-12-13 14:16:30 +01:00
|
|
|
out = run_json(cli.accounts.update_account, "--display-name", name, "--json")
|
2023-11-22 08:41:15 +01:00
|
|
|
account = from_dict(Account, out)
|
|
|
|
assert account.acct == user.username
|
2023-11-28 16:56:53 +01:00
|
|
|
assert account.display_name == name
|
2023-11-22 08:41:15 +01:00
|
|
|
|
|
|
|
|
2023-03-30 10:56:03 +02:00
|
|
|
def test_update_account_note(run, app, user):
|
|
|
|
note = ("It's 106 miles to Chicago, we got a full tank of gas, half a pack "
|
|
|
|
"of cigarettes, it's dark... and we're wearing sunglasses.")
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--note", note)
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert get_text(account["note"]) == note
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_language(run, app, user):
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--language", "hr")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["source"]["language"] == "hr"
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_privacy(run, app, user):
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--privacy", "private")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["source"]["privacy"] == "private"
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_avatar(run, app, user):
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
old_value = account["avatar"]
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--avatar", TRUMPET)
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["avatar"] != old_value
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_header(run, app, user):
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
old_value = account["header"]
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--header", TRUMPET)
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["header"] != old_value
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_locked(run, app, user):
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--locked")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["locked"] is True
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--no-locked")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["locked"] is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_bot(run, app, user):
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--bot")
|
2023-11-28 16:56:53 +01:00
|
|
|
|
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["bot"] is True
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--no-bot")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["bot"] is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_discoverable(run, app, user):
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--discoverable")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["discoverable"] is True
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--no-discoverable")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["discoverable"] is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_account_sensitive(run, app, user):
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--sensitive")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["source"]["sensitive"] is True
|
|
|
|
|
2023-12-13 14:16:30 +01:00
|
|
|
result = run(cli.accounts.update_account, "--no-sensitive")
|
2023-11-28 16:56:53 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Account updated"
|
2023-03-30 10:56:03 +02:00
|
|
|
|
2023-11-18 14:55:45 +01:00
|
|
|
account = api.verify_credentials(app, user).json()
|
2023-03-30 10:56:03 +02:00
|
|
|
assert account["source"]["sensitive"] is False
|