mirror of
https://github.com/ihabunek/toot
synced 2025-02-16 20:10:41 +01:00
Test new timeline commands, tweaks
This commit is contained in:
parent
89035accc3
commit
bfcf623448
@ -84,7 +84,7 @@ def test_following_not_found(run):
|
||||
assert result.stderr.strip() == "Error: Account not found"
|
||||
|
||||
|
||||
def test_following_json(app: App, user: User, user_id, run_json):
|
||||
def test_following_json(app: App, user: User, run_json):
|
||||
friend = register_account(app)
|
||||
|
||||
result = run_json(cli.accounts.following, user.username, "--json")
|
||||
|
@ -8,18 +8,17 @@ from toot.entities import from_dict, Status
|
||||
from tests.integration.conftest import TOOT_TEST_BASE_URL, assert_ok, register_account
|
||||
|
||||
|
||||
# TODO: If fixture is not overridden here, tests fail, not sure why, figure it out
|
||||
@pytest.fixture(scope="module")
|
||||
@pytest.fixture(scope="function")
|
||||
def user(app):
|
||||
return register_account(app)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@pytest.fixture(scope="function")
|
||||
def other_user(app):
|
||||
return register_account(app)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@pytest.fixture(scope="function")
|
||||
def friend_user(app, user):
|
||||
friend = register_account(app)
|
||||
friend_account = api.find_account(app, user, friend.username)
|
||||
@ -27,7 +26,7 @@ def friend_user(app, user):
|
||||
return friend
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@pytest.fixture(scope="function")
|
||||
def friend_list(app, user, friend_user):
|
||||
friend_account = api.find_account(app, user, friend_user.username)
|
||||
list = api.create_list(app, user, str(uuid4())).json()
|
||||
@ -111,6 +110,100 @@ def test_timelines(app, user, other_user, friend_user, friend_list, run):
|
||||
assert status3.id not in result.stdout
|
||||
|
||||
|
||||
def test_timelines_v2(app, user, other_user, friend_user, friend_list, run):
|
||||
status1 = _post_status(app, user, "#foo")
|
||||
status2 = _post_status(app, other_user, "#bar")
|
||||
status3 = _post_status(app, friend_user, "#foo #bar")
|
||||
|
||||
# Home timeline
|
||||
def test_home():
|
||||
result = run(cli.timelines_v2.home)
|
||||
assert_ok(result)
|
||||
assert status1.id in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
run_with_retries(test_home)
|
||||
|
||||
# Public timeline
|
||||
result = run(cli.timelines_v2.public)
|
||||
assert_ok(result)
|
||||
assert status1.id in result.stdout
|
||||
assert status2.id in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
# Anon public timeline
|
||||
result = run(cli.timelines_v2.public, "--instance", TOOT_TEST_BASE_URL)
|
||||
assert_ok(result)
|
||||
assert status1.id in result.stdout
|
||||
assert status2.id in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
# Tag timeline
|
||||
result = run(cli.timelines_v2.tag, "foo")
|
||||
assert_ok(result)
|
||||
assert status1.id in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
result = run(cli.timelines_v2.tag, "bar")
|
||||
assert_ok(result)
|
||||
assert status1.id not in result.stdout
|
||||
assert status2.id in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
result = run(cli.timelines_v2.tag, "foo", "--all", "bar")
|
||||
assert_ok(result)
|
||||
assert status1.id not in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
result = run(cli.timelines_v2.tag, "foo", "--any", "bar")
|
||||
assert_ok(result)
|
||||
assert status1.id in result.stdout
|
||||
assert status2.id in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
result = run(cli.timelines_v2.tag, "foo", "--none", "bar")
|
||||
assert_ok(result)
|
||||
assert status1.id in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id not in result.stdout
|
||||
|
||||
# Anon tag timeline
|
||||
result = run(cli.timelines_v2.tag, "--instance", TOOT_TEST_BASE_URL, "foo")
|
||||
assert_ok(result)
|
||||
assert status1.id in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
# List timeline (by list name)
|
||||
result = run(cli.timelines_v2.list, friend_list["title"])
|
||||
assert_ok(result)
|
||||
assert status1.id not in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
# List timeline (by list ID)
|
||||
result = run(cli.timelines_v2.list, friend_list["id"])
|
||||
assert_ok(result)
|
||||
assert status1.id not in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
# Account timeline
|
||||
result = run(cli.timelines_v2.account, friend_user.username)
|
||||
assert_ok(result)
|
||||
assert status1.id not in result.stdout
|
||||
assert status2.id not in result.stdout
|
||||
assert status3.id in result.stdout
|
||||
|
||||
result = run(cli.timelines_v2.account, other_user.username)
|
||||
assert_ok(result)
|
||||
assert status1.id not in result.stdout
|
||||
assert status2.id in result.stdout
|
||||
assert status3.id not in result.stdout
|
||||
|
||||
|
||||
def test_empty_timeline(app, run_as):
|
||||
user = register_account(app)
|
||||
result = run_as(user, cli.timelines.timeline)
|
||||
|
@ -65,6 +65,16 @@ def common_timeline_options(func):
|
||||
return wrapper
|
||||
|
||||
|
||||
instance_option = click.option(
|
||||
"-i",
|
||||
"--instance",
|
||||
callback=validate_instance,
|
||||
help="""Domain or base URL of the instance, e.g. 'mastodon.social' or
|
||||
'https://mastodon.social'. If not given will display timeline of the
|
||||
logged in server.""",
|
||||
)
|
||||
|
||||
|
||||
@cli.group()
|
||||
def timelines():
|
||||
"""Show various timelines"""
|
||||
@ -161,13 +171,13 @@ def link(
|
||||
|
||||
|
||||
@timelines.command()
|
||||
@click.argument("list_name")
|
||||
@click.argument("list_name_or_id")
|
||||
@common_timeline_options
|
||||
@json_option
|
||||
@pass_context
|
||||
def list(
|
||||
ctx: Context,
|
||||
list_name: str,
|
||||
list_name_or_id: str,
|
||||
min_id: Optional[str],
|
||||
max_id: Optional[str],
|
||||
since_id: Optional[str],
|
||||
@ -177,7 +187,7 @@ def list(
|
||||
json: bool,
|
||||
):
|
||||
"""View statuses in the given list timeline."""
|
||||
list_id = get_list_id(ctx, list_name, None)
|
||||
list_id = get_list_id(ctx, list_name_or_id, list_name_or_id)
|
||||
path = f"/api/v1/timelines/list/{list_id}"
|
||||
|
||||
params = {
|
||||
@ -192,14 +202,7 @@ def list(
|
||||
|
||||
@timelines.command()
|
||||
@common_timeline_options
|
||||
@click.option(
|
||||
"-i",
|
||||
"--instance",
|
||||
callback=validate_instance,
|
||||
help="""Domain or base URL of the instance, e.g. 'mastodon.social' or
|
||||
'https://mastodon.social'. If not given will display timeline of the
|
||||
logged in server.""",
|
||||
)
|
||||
@instance_option
|
||||
@click.option(
|
||||
"--local",
|
||||
is_flag=True,
|
||||
@ -255,6 +258,7 @@ def public(
|
||||
|
||||
@timelines.command()
|
||||
@common_timeline_options
|
||||
@instance_option
|
||||
@click.argument("tag_name")
|
||||
@click.option(
|
||||
"--local",
|
||||
@ -277,23 +281,24 @@ def public(
|
||||
@click.option(
|
||||
"--any",
|
||||
multiple=True,
|
||||
help="Return statuses that contain any of these additional tags"
|
||||
help="Return statuses that contain any of these additional tags (can be specified multiple times)",
|
||||
)
|
||||
@click.option(
|
||||
"--all",
|
||||
multiple=True,
|
||||
help="Return statuses that contain all of these additional tags"
|
||||
help="Return statuses that contain all of these additional tags (can be specified multiple times)",
|
||||
)
|
||||
@click.option(
|
||||
"--none",
|
||||
multiple=True,
|
||||
help="Return statuses that contain none of these additional tags"
|
||||
help="Return statuses that contain none of these additional tags (can be specified multiple times)",
|
||||
)
|
||||
@json_option
|
||||
@pass_context
|
||||
def tag(
|
||||
ctx: Context,
|
||||
tag_name: str,
|
||||
instance: Optional[str],
|
||||
min_id: Optional[str],
|
||||
max_id: Optional[str],
|
||||
since_id: Optional[str],
|
||||
@ -323,7 +328,11 @@ def tag(
|
||||
"none[]": none or None,
|
||||
}
|
||||
|
||||
_show_timeline(ctx, path, params, json, pager, clear, limit)
|
||||
if instance:
|
||||
url = f"{instance}{path}"
|
||||
_show_anon_timeline(url, params, json, pager, clear, limit)
|
||||
else:
|
||||
_show_timeline(ctx, path, params, json, pager, clear, limit)
|
||||
|
||||
|
||||
def _show_timeline(ctx, path, params, json, pager, clear, limit):
|
||||
|
Loading…
x
Reference in New Issue
Block a user