- Add configurable request delay between paginated API calls (default 1.5s) - Add retry with exponential backoff on HTTP 429 and Twitter error code 88 - Add hard max count cap (default 200, absolute ceiling 500) - Add rateLimit config section with requestDelay, maxRetries, retryBaseDelay, maxCount - Add normalization tests for rateLimit config
29 lines
1009 B
Python
29 lines
1009 B
Python
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 config=None: 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
|