mirror of
https://github.com/ihabunek/toot
synced 2024-12-22 23:08:17 +01:00
Make account optional in following and followers
This commit is contained in:
parent
443f9445b1
commit
e961bd696d
2
.flake8
2
.flake8
@ -1,4 +1,4 @@
|
||||
[flake8]
|
||||
exclude=build,tests,tmp,venv,toot/tui/scroll.py
|
||||
ignore=E128,W503
|
||||
ignore=E128,W503,W504
|
||||
max-line-length=120
|
||||
|
@ -42,6 +42,10 @@ def test_following(app: App, user: User, friend: User, friend_id, run):
|
||||
out = run("following", user.username)
|
||||
assert friend.username in out
|
||||
|
||||
# If no account is given defaults to logged in user
|
||||
out = run("following")
|
||||
assert friend.username in out
|
||||
|
||||
out = run("unfollow", friend.username)
|
||||
assert out == f"✓ You are no longer following {friend.username}"
|
||||
|
||||
@ -82,6 +86,11 @@ def test_following_json(app: App, user: User, friend: User, user_id, friend_id,
|
||||
relationship = from_dict(Relationship, result)
|
||||
assert relationship.id == friend_id
|
||||
|
||||
# If no account is given defaults to logged in user
|
||||
[result] = run_json("following", user.username, "--json")
|
||||
relationship = from_dict(Relationship, result)
|
||||
assert relationship.id == friend_id
|
||||
|
||||
[result] = run_json("followers", friend.username, "--json")
|
||||
assert result["id"] == user_id
|
||||
|
||||
|
@ -436,7 +436,8 @@ def unfollow(app, user, args):
|
||||
|
||||
|
||||
def following(app, user, args):
|
||||
account = api.find_account(app, user, args.account)
|
||||
account = args.account or user.username
|
||||
account = api.find_account(app, user, account)
|
||||
accounts = api.following(app, user, account["id"])
|
||||
if args.json:
|
||||
print(json.dumps(accounts))
|
||||
@ -445,7 +446,8 @@ def following(app, user, args):
|
||||
|
||||
|
||||
def followers(app, user, args):
|
||||
account = api.find_account(app, user, args.account)
|
||||
account = args.account or user.username
|
||||
account = api.find_account(app, user, account)
|
||||
accounts = api.followers(app, user, account["id"])
|
||||
if args.json:
|
||||
print(json.dumps(accounts))
|
||||
|
@ -191,6 +191,7 @@ common_auth_args = [
|
||||
account_arg = (["account"], {
|
||||
"help": "account name, e.g. 'Gargron@mastodon.social'",
|
||||
})
|
||||
|
||||
optional_account_arg = (["account"], {
|
||||
"nargs": "?",
|
||||
"help": "account name, e.g. 'Gargron@mastodon.social'",
|
||||
@ -682,14 +683,16 @@ ACCOUNTS_COMMANDS = [
|
||||
),
|
||||
Command(
|
||||
name="following",
|
||||
description="List accounts followed by the given account",
|
||||
arguments=[account_arg, json_arg],
|
||||
description="List accounts followed by the given account, " +
|
||||
"or your account if no account given",
|
||||
arguments=[optional_account_arg, json_arg],
|
||||
require_auth=True,
|
||||
),
|
||||
Command(
|
||||
name="followers",
|
||||
description="List accounts following the given account",
|
||||
arguments=[account_arg, json_arg],
|
||||
description="List accounts following the given account, " +
|
||||
"or your account if no account given",
|
||||
arguments=[optional_account_arg, json_arg],
|
||||
require_auth=True,
|
||||
),
|
||||
Command(
|
||||
|
Loading…
Reference in New Issue
Block a user