1
0
mirror of https://github.com/ihabunek/toot synced 2024-12-23 15:37:47 +01:00

Extract fetching list ID

Also don't check if account is found, that function alredy raises a
ConsoleError.
This commit is contained in:
Ivan Habunek 2023-03-30 12:31:04 +02:00
parent c659ed7a5d
commit e3394c1693
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 29 additions and 25 deletions

View File

@ -1,6 +1,7 @@
from toot import api
import pytest
from tests.integration.conftest import register_account
from toot.exceptions import ConsoleError
def test_lists_empty(run):
@ -35,6 +36,10 @@ def test_list_create_delete(run):
out = run("lists")
assert out == "You have no lists defined."
with pytest.raises(ConsoleError) as exc:
run("list_delete", "mango")
assert str(exc.value) == "List not found"
def test_list_add_remove(run, app):
acc = register_account(app)
@ -51,6 +56,16 @@ def test_list_add_remove(run, app):
out = run("list_accounts", "foo")
assert acc.username in out
# Account doesn't exist
with pytest.raises(ConsoleError) as exc:
run("list_add", "foo", "does_not_exist")
assert str(exc.value) == "Account not found"
# List doesn't exist
with pytest.raises(ConsoleError) as exc:
run("list_add", "does_not_exist", acc.username)
assert str(exc.value) == "List not found"
out = run("list_remove", "foo", acc.username)
assert out == f'✓ Removed account "{acc.username}"'

View File

@ -434,11 +434,7 @@ def lists(app, user, args):
def list_accounts(app, user, args):
list_id = args.id if args.id else api.find_list_id(app, user, args.title)
if not list_id:
print_out("<red>List not found</red>")
return
list_id = _get_list_id(app, user, args)
response = api.get_list_accounts(app, user, list_id)
print_list_accounts(response)
@ -449,24 +445,15 @@ def list_create(app, user, args):
def list_delete(app, user, args):
list_id = args.id if args.id else api.find_list_id(app, user, args.title)
if not list_id:
print_out("<red>List not found</red>")
return
list_id = _get_list_id(app, user, args)
api.delete_list(app, user, list_id)
print_out(f"<green>✓ List \"{args.title if args.title else args.id}\"</green> <red>deleted.</red>")
def list_add(app, user, args):
list_id = args.id if args.id else api.find_list_id(app, user, args.title)
if not list_id:
print_out("<red>List not found</red>")
return
list_id = _get_list_id(app, user, args)
account = find_account(app, user, args.account)
if not account:
print_out("<red>Account not found</red>")
return
try:
api.add_accounts_to_list(app, user, list_id, [account['id']])
except Exception as ex:
@ -484,22 +471,24 @@ def list_add(app, user, args):
else:
print_out(f"<red>{ex}</red>")
return
print_out(f"<green>✓ Added account \"{args.account}\"</green>")
def list_remove(app, user, args):
list_id = args.id if args.id else api.find_list_id(app, user, args.title)
if not list_id:
print_out("<red>List not found</red>")
return
list_id = _get_list_id(app, user, args)
account = find_account(app, user, args.account)
if not account:
print_out("<red>Account not found</red>")
return
api.remove_accounts_from_list(app, user, list_id, [account['id']])
print_out(f"<green>✓ Removed account \"{args.account}\"</green>")
def _get_list_id(app, user, args):
list_id = args.id or api.find_list_id(app, user, args.title)
if not list_id:
raise ConsoleError("List not found")
return list_id
def mute(app, user, args):
account = find_account(app, user, args.account)
api.mute(app, user, account['id'])