fix: 修复报告摘要生成并稳定默认端口
This commit is contained in:
@@ -118,3 +118,39 @@ def test_douyin_maps_null_comments_as_empty_list():
|
||||
payload = {"data": {"comments": None}}
|
||||
|
||||
assert platform.map_comments(payload, limit=10) == []
|
||||
|
||||
|
||||
class RecordingDouyinClient:
|
||||
def __init__(self):
|
||||
self.requests = []
|
||||
|
||||
def get(self, path, *, params=None):
|
||||
self.requests.append((path, params))
|
||||
cursor = params["cursor"]
|
||||
if cursor == 0:
|
||||
return {
|
||||
"data": {
|
||||
"comments": [{"cid": f"c-{index}", "text": f"评论 {index}"} for index in range(20)],
|
||||
"cursor": 20,
|
||||
"has_more": 1,
|
||||
}
|
||||
}
|
||||
return {
|
||||
"data": {
|
||||
"comments": [{"cid": f"c-{index}", "text": f"评论 {index}"} for index in range(20, 55)],
|
||||
"cursor": 55,
|
||||
"has_more": 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_douyin_fetch_comments_paginates_until_limit():
|
||||
client = RecordingDouyinClient()
|
||||
platform = DouyinPlatform(client=client)
|
||||
|
||||
comments = platform.fetch_comments("aweme-1", limit=50)
|
||||
|
||||
assert len(comments) == 50
|
||||
assert comments[0].source_comment_id == "c-0"
|
||||
assert comments[-1].source_comment_id == "c-49"
|
||||
assert [request[1]["cursor"] for request in client.requests] == [0, 20]
|
||||
|
||||
Reference in New Issue
Block a user