kopia lustrzana https://github.com/ihabunek/toot
Make account optional in following and followers
rodzic
443f9445b1
commit
e961bd696d
2
.flake8
2
.flake8
|
@ -1,4 +1,4 @@
|
||||||
[flake8]
|
[flake8]
|
||||||
exclude=build,tests,tmp,venv,toot/tui/scroll.py
|
exclude=build,tests,tmp,venv,toot/tui/scroll.py
|
||||||
ignore=E128,W503
|
ignore=E128,W503,W504
|
||||||
max-line-length=120
|
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)
|
out = run("following", user.username)
|
||||||
assert friend.username in out
|
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)
|
out = run("unfollow", friend.username)
|
||||||
assert out == f"✓ You are no longer following {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)
|
relationship = from_dict(Relationship, result)
|
||||||
assert relationship.id == friend_id
|
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")
|
[result] = run_json("followers", friend.username, "--json")
|
||||||
assert result["id"] == user_id
|
assert result["id"] == user_id
|
||||||
|
|
||||||
|
|
|
@ -436,7 +436,8 @@ def unfollow(app, user, args):
|
||||||
|
|
||||||
|
|
||||||
def following(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"])
|
accounts = api.following(app, user, account["id"])
|
||||||
if args.json:
|
if args.json:
|
||||||
print(json.dumps(accounts))
|
print(json.dumps(accounts))
|
||||||
|
@ -445,7 +446,8 @@ def following(app, user, args):
|
||||||
|
|
||||||
|
|
||||||
def followers(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"])
|
accounts = api.followers(app, user, account["id"])
|
||||||
if args.json:
|
if args.json:
|
||||||
print(json.dumps(accounts))
|
print(json.dumps(accounts))
|
||||||
|
|
|
@ -191,6 +191,7 @@ common_auth_args = [
|
||||||
account_arg = (["account"], {
|
account_arg = (["account"], {
|
||||||
"help": "account name, e.g. 'Gargron@mastodon.social'",
|
"help": "account name, e.g. 'Gargron@mastodon.social'",
|
||||||
})
|
})
|
||||||
|
|
||||||
optional_account_arg = (["account"], {
|
optional_account_arg = (["account"], {
|
||||||
"nargs": "?",
|
"nargs": "?",
|
||||||
"help": "account name, e.g. 'Gargron@mastodon.social'",
|
"help": "account name, e.g. 'Gargron@mastodon.social'",
|
||||||
|
@ -682,14 +683,16 @@ ACCOUNTS_COMMANDS = [
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
name="following",
|
name="following",
|
||||||
description="List accounts followed by the given account",
|
description="List accounts followed by the given account, " +
|
||||||
arguments=[account_arg, json_arg],
|
"or your account if no account given",
|
||||||
|
arguments=[optional_account_arg, json_arg],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
name="followers",
|
name="followers",
|
||||||
description="List accounts following the given account",
|
description="List accounts following the given account, " +
|
||||||
arguments=[account_arg, json_arg],
|
"or your account if no account given",
|
||||||
|
arguments=[optional_account_arg, json_arg],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
|
|
Ładowanie…
Reference in New Issue