Skip to content

Commit

Permalink
Make account optional in following and followers
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Nov 22, 2023
1 parent 443f944 commit e961bd6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/integration/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions toot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
11 changes: 7 additions & 4 deletions toot/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def editor(value):
account_arg = (["account"], {
"help": "account name, e.g. 'Gargron@mastodon.social'",
})

optional_account_arg = (["account"], {
"nargs": "?",
"help": "account name, e.g. 'Gargron@mastodon.social'",
Expand Down Expand Up @@ -682,14 +683,16 @@ def editor(value):
),
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(
Expand Down

0 comments on commit e961bd6

Please sign in to comment.