-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
333 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import pytest | ||
|
||
from time import sleep | ||
from uuid import uuid4 | ||
|
||
from toot import api, cli | ||
from toot.entities import from_dict, Status | ||
from tests.integration.conftest import TOOT_TEST_BASE_URL, register_account | ||
|
||
|
||
# TODO: If fixture is not overriden here, tests fail, not sure why, figure it out | ||
@pytest.fixture(scope="module") | ||
def user(app): | ||
return register_account(app) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def other_user(app): | ||
return register_account(app) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
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") | ||
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())) | ||
api.add_accounts_to_list(app, user, list["id"], account_ids=[friend_account["id"]]) | ||
return list | ||
|
||
|
||
# TODO: break up big test and set up module level fixtures | ||
def test_timelines(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") | ||
|
||
# Give mastodon time to process things :/ | ||
# Tests fail if this is removed, required delay depends on server speed | ||
sleep(1) | ||
|
||
# Home timeline | ||
result = run(cli.timeline) | ||
assert result.exit_code == 0 | ||
print() | ||
print(result.stdout) | ||
print() | ||
|
||
assert status1.id in result.stdout | ||
assert status2.id not in result.stdout | ||
assert status3.id in result.stdout | ||
|
||
# Public timeline | ||
result = run(cli.timeline, "--public") | ||
assert result.exit_code == 0 | ||
assert status1.id in result.stdout | ||
assert status2.id in result.stdout | ||
assert status3.id in result.stdout | ||
|
||
# Anon public timeline | ||
result = run(cli.timeline, "--instance", TOOT_TEST_BASE_URL, "--public") | ||
assert result.exit_code == 0 | ||
assert status1.id in result.stdout | ||
assert status2.id in result.stdout | ||
assert status3.id in result.stdout | ||
|
||
# Tag timeline | ||
result = run(cli.timeline, "--tag", "foo") | ||
assert result.exit_code == 0 | ||
assert status1.id in result.stdout | ||
assert status2.id not in result.stdout | ||
assert status3.id in result.stdout | ||
|
||
result = run(cli.timeline, "--tag", "bar") | ||
assert result.exit_code == 0 | ||
assert status1.id not in result.stdout | ||
assert status2.id in result.stdout | ||
assert status3.id in result.stdout | ||
|
||
# Anon tag timeline | ||
result = run(cli.timeline, "--instance", TOOT_TEST_BASE_URL, "--tag", "foo") | ||
assert result.exit_code == 0 | ||
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.timeline, "--list", friend_list["title"]) | ||
assert result.exit_code == 0 | ||
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.timeline, "--list", friend_list["id"]) | ||
assert result.exit_code == 0 | ||
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.timeline, "--account", friend_user.username) | ||
assert result.exit_code == 0 | ||
assert status1.id not in result.stdout | ||
assert status2.id not in result.stdout | ||
assert status3.id in result.stdout | ||
|
||
result = run(cli.timeline, "--account", other_user.username) | ||
assert result.exit_code == 0 | ||
assert status1.id not in result.stdout | ||
assert status2.id in result.stdout | ||
assert status3.id not in result.stdout | ||
|
||
|
||
def test_timeline_cant_combine_timelines(run): | ||
result = run(cli.timeline, "--tag", "foo", "--account", "bar") | ||
assert result.exit_code == 1 | ||
assert result.stderr.strip() == "Error: Only one of --public, --tag, --account, or --list can be used at one time." | ||
|
||
|
||
def test_timeline_local_needs_public_or_tag(run): | ||
result = run(cli.timeline, "--local") | ||
assert result.exit_code == 1 | ||
assert result.stderr.strip() == "Error: The --local option is only valid alongside --public or --tag." | ||
|
||
|
||
def test_timeline_instance_needs_public_or_tag(run): | ||
result = run(cli.timeline, "--instance", TOOT_TEST_BASE_URL) | ||
assert result.exit_code == 1 | ||
assert result.stderr.strip() == "Error: The --instance option is only valid alongside --public or --tag." | ||
|
||
|
||
def _post_status(app, user, text=None) -> Status: | ||
text = text or str(uuid4()) | ||
response = api.post_status(app, user, text) | ||
return from_dict(Status, response.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from toot.cli.base import cli, Context # noqa | ||
# flake8: noqa | ||
from toot.cli.base import cli, Context | ||
|
||
from toot.cli.auth import * | ||
from toot.cli.accounts import * | ||
from toot.cli.auth import * | ||
from toot.cli.lists import * | ||
from toot.cli.post import * | ||
from toot.cli.read import * | ||
from toot.cli.statuses import * | ||
from toot.cli.tags import * | ||
from toot.cli.timelines import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.