Skip to content

Commit

Permalink
Test new timeline commands, tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Jan 16, 2025
1 parent 89035ac commit bfcf623
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tests/integration/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
103 changes: 98 additions & 5 deletions tests/integration/test_timelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@
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)
api.follow(app, user, friend_account["id"])
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()
Expand Down Expand Up @@ -111,6 +110,100 @@ def test_home():
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)
Expand Down
39 changes: 24 additions & 15 deletions toot/cli/timelines_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ def wrapper(*args, **kwargs):
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"""
Expand Down Expand Up @@ -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],
Expand All @@ -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 = {
Expand All @@ -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,
Expand Down Expand Up @@ -255,6 +258,7 @@ def public(

@timelines.command()
@common_timeline_options
@instance_option
@click.argument("tag_name")
@click.option(
"--local",
Expand All @@ -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],
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit bfcf623

Please sign in to comment.