test+ci: add regression tests and GitHub Actions workflow

This commit is contained in:
jackwener
2026-03-05 16:14:05 +08:00
parent 4c08d09304
commit 6f322ff2d6
7 changed files with 225 additions and 0 deletions

28
tests/test_cli.py Normal file
View File

@@ -0,0 +1,28 @@
from __future__ import annotations
from click.testing import CliRunner
from twitter_cli.cli import cli
from twitter_cli.models import UserProfile
from twitter_cli.serialization import tweets_to_json
def test_cli_user_command_works_with_client_factory(monkeypatch) -> None:
class FakeClient:
def fetch_user(self, screen_name: str) -> UserProfile:
return UserProfile(id="1", name="Alice", screen_name=screen_name)
monkeypatch.setattr("twitter_cli.cli._get_client", lambda: FakeClient())
runner = CliRunner()
result = runner.invoke(cli, ["user", "alice"])
assert result.exit_code == 0
def test_cli_feed_json_input_path(tmp_path, tweet_factory) -> None:
json_path = tmp_path / "tweets.json"
json_path.write_text(tweets_to_json([tweet_factory("1")]), encoding="utf-8")
runner = CliRunner()
result = runner.invoke(cli, ["feed", "--input", str(json_path), "--json"])
assert result.exit_code == 0
assert '"id": "1"' in result.output