test+ci: add regression tests and GitHub Actions workflow
This commit is contained in:
28
tests/test_cli.py
Normal file
28
tests/test_cli.py
Normal 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
|
||||
Reference in New Issue
Block a user