2023-12-13 01:50:45 -05:00
|
|
|
import re
|
|
|
|
from typing import List
|
2023-12-12 03:45:57 -05:00
|
|
|
|
2023-12-13 01:50:45 -05:00
|
|
|
from toot import api, cli
|
|
|
|
from toot.entities import FeaturedTag, Tag, from_dict, from_dict_list
|
2023-12-12 03:45:57 -05:00
|
|
|
|
2023-12-13 01:50:45 -05:00
|
|
|
|
|
|
|
def test_tags(run):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "followed")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.stdout.strip() == "You're not following any hashtags"
|
2023-12-12 03:45:57 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "follow", "foo")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ You are now following #foo"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "followed")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
2023-12-13 01:50:45 -05:00
|
|
|
assert _find_tags(result.stdout) == ["#foo"]
|
2023-12-12 03:45:57 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "follow", "bar")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ You are now following #bar"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "followed")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
2023-12-13 01:50:45 -05:00
|
|
|
assert _find_tags(result.stdout) == ["#bar", "#foo"]
|
2023-12-12 03:45:57 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "unfollow", "foo")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ You are no longer following #foo"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "followed")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
2023-12-13 01:50:45 -05:00
|
|
|
assert _find_tags(result.stdout) == ["#bar"]
|
2023-12-12 03:45:57 -05:00
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "unfollow", "bar")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ You are no longer following #bar"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "followed")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result.exit_code == 0
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.stdout.strip() == "You're not following any hashtags"
|
2023-12-12 03:45:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_tags_json(run_json):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "followed", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result == []
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "follow", "foo", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
tag = from_dict(Tag, result)
|
|
|
|
assert tag.name == "foo"
|
|
|
|
assert tag.following is True
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "followed", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
[tag] = from_dict_list(Tag, result)
|
|
|
|
assert tag.name == "foo"
|
|
|
|
assert tag.following is True
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "follow", "bar", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
tag = from_dict(Tag, result)
|
|
|
|
assert tag.name == "bar"
|
|
|
|
assert tag.following is True
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "followed", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
tags = from_dict_list(Tag, result)
|
|
|
|
[bar, foo] = sorted(tags, key=lambda t: t.name)
|
|
|
|
assert foo.name == "foo"
|
|
|
|
assert foo.following is True
|
|
|
|
assert bar.name == "bar"
|
|
|
|
assert bar.following is True
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "unfollow", "foo", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
tag = from_dict(Tag, result)
|
|
|
|
assert tag.name == "foo"
|
|
|
|
assert tag.following is False
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "unfollow", "bar", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
tag = from_dict(Tag, result)
|
|
|
|
assert tag.name == "bar"
|
|
|
|
assert tag.following is False
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "followed", "--json")
|
2023-12-12 03:45:57 -05:00
|
|
|
assert result == []
|
2023-12-13 01:50:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_tags_featured(run, app, user):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "featured")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "You don't have any featured hashtags"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "feature", "foo")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Tag #foo is now featured"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "featured")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert _find_tags(result.stdout) == ["#foo"]
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "feature", "bar")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Tag #bar is now featured"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "featured")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert _find_tags(result.stdout) == ["#bar", "#foo"]
|
|
|
|
|
|
|
|
# Unfeature by Name
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "unfeature", "foo")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Tag #foo is no longer featured"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "featured")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert _find_tags(result.stdout) == ["#bar"]
|
|
|
|
|
|
|
|
# Unfeature by ID
|
|
|
|
tag = api.find_featured_tag(app, user, "bar")
|
|
|
|
assert tag is not None
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "unfeature", tag["id"])
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "✓ Tag #bar is no longer featured"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run(cli.tags.tags, "featured")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert result.stdout.strip() == "You don't have any featured hashtags"
|
|
|
|
|
|
|
|
|
|
|
|
def test_tags_featured_json(run_json):
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "featured", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result == []
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "feature", "foo", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
tag = from_dict(FeaturedTag, result)
|
|
|
|
assert tag.name == "foo"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "featured", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
[tag] = from_dict_list(FeaturedTag, result)
|
|
|
|
assert tag.name == "foo"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "feature", "bar", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
tag = from_dict(FeaturedTag, result)
|
|
|
|
assert tag.name == "bar"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "featured", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
tags = from_dict_list(FeaturedTag, result)
|
|
|
|
[bar, foo] = sorted(tags, key=lambda t: t.name)
|
|
|
|
assert foo.name == "foo"
|
|
|
|
assert bar.name == "bar"
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "unfeature", "foo", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result == {}
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "unfeature", "bar", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result == {}
|
|
|
|
|
2023-12-13 08:16:30 -05:00
|
|
|
result = run_json(cli.tags.tags, "featured", "--json")
|
2023-12-13 01:50:45 -05:00
|
|
|
assert result == []
|
|
|
|
|
|
|
|
|
|
|
|
def _find_tags(txt: str) -> List[str]:
|
|
|
|
return sorted(re.findall(r"#\w+", txt))
|