Feed cursor pagination (#49)
* Expose promoted tweets in feed output * Add cursor-based feed pagination output
This commit is contained in:
@@ -333,6 +333,24 @@ class TestBuildHeaders:
|
||||
|
||||
|
||||
class TestPaginationBehavior:
|
||||
def test_fetch_timeline_can_include_promoted_content(self):
|
||||
client = TwitterClient.__new__(TwitterClient)
|
||||
client._request_delay = 0.0
|
||||
client._max_count = 200
|
||||
|
||||
calls = []
|
||||
|
||||
def _graphql_get(operation_name, variables, features, field_toggles=None):
|
||||
calls.append(variables.copy())
|
||||
return {"page": 1}
|
||||
|
||||
client._graphql_get = _graphql_get
|
||||
|
||||
with patch('twitter_cli.client.parse_timeline_response', return_value=([], None)):
|
||||
client._fetch_timeline("HomeTimeline", 1, lambda data: data, include_promoted=True)
|
||||
|
||||
assert calls[0]["includePromotedContent"] is True
|
||||
|
||||
def test_continues_when_cursor_advances_without_new_tweets(self):
|
||||
client = TwitterClient.__new__(TwitterClient)
|
||||
client._request_delay = 0.0
|
||||
@@ -379,6 +397,33 @@ class TestPaginationBehavior:
|
||||
assert tweets == []
|
||||
assert calls == [None, "cursor-same"]
|
||||
|
||||
def test_fetch_timeline_returns_continuation_cursor(self):
|
||||
client = TwitterClient.__new__(TwitterClient)
|
||||
client._request_delay = 0.0
|
||||
client._max_count = 200
|
||||
|
||||
calls = []
|
||||
|
||||
def _graphql_get(operation_name, variables, features, field_toggles=None):
|
||||
calls.append(variables.copy())
|
||||
return {"page": 1}
|
||||
|
||||
client._graphql_get = _graphql_get
|
||||
|
||||
tweet = MagicMock(id="tweet-1")
|
||||
with patch('twitter_cli.client.parse_timeline_response', return_value=([tweet], "cursor-next")):
|
||||
tweets, cursor = client._fetch_timeline(
|
||||
"HomeTimeline",
|
||||
1,
|
||||
lambda data: data,
|
||||
start_cursor="cursor-prev",
|
||||
return_cursor=True,
|
||||
)
|
||||
|
||||
assert [item.id for item in tweets] == ["tweet-1"]
|
||||
assert cursor == "cursor-next"
|
||||
assert calls[0]["cursor"] == "cursor-prev"
|
||||
|
||||
def test_user_list_continues_when_cursor_advances_without_new_users(self):
|
||||
client = TwitterClient.__new__(TwitterClient)
|
||||
client._request_delay = 0.0
|
||||
|
||||
Reference in New Issue
Block a user