feat(report): 博主名字后面带上账号池的账号状态
账号池服务(192.168.20.220:18050 的 /api/account_pool/accounts)返回每个号的 `nickname` 和 `account_status`(账号正常 / 账号异常 / 作品异常 / 账号安全待提升)。 报表按昵称匹配,在名字后面加括号显示:`周周逛苏州(账号异常)`。 **由后端去取,浏览器不直连** —— token 不该下发到前端,跨域也麻烦。地址和 token 走 环境变量 `MC_ACCOUNT_POOL_URL` / `MC_ACCOUNT_POOL_TOKEN`(已加到服务器 .env, 不进仓库);没配就静默跳过。 细节: * 缓存 60 秒 —— 报表会被反复刷新,而账号状态是分钟级的;刷新一次就多打一次外部 接口没有意义; * 外部服务失败时**保留上一份缓存**,没有缓存就返回空;报表本身绝不能因此打不开; * 同名不同号时把状态并起来(`A / B`),不静默只留一个; * 只在抖音平台附加 —— 那套池子管的是抖音号,小红书同名账号不该被误标。 测试 16 条(新增:按昵称附加状态、外部服务挂掉时报表照出)。
This commit is contained in:
@@ -383,6 +383,49 @@ async def test_task_from_another_platform_is_rejected(db):
|
||||
assert data["dates"] == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_account_pool_status_is_attached_by_nickname(db, monkeypatch):
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp() - 1000
|
||||
await _note(task_id, "n1", "博主A", now)
|
||||
|
||||
async def fake_pool():
|
||||
return [
|
||||
{"nickname": "博主A", "account_status": "账号异常"},
|
||||
{"nickname": "别人", "account_status": "账号正常"},
|
||||
]
|
||||
|
||||
monkeypatch.setenv("MC_ACCOUNT_POOL_URL", "http://pool/api")
|
||||
monkeypatch.setattr(service, "_fetch_account_pool", fake_pool)
|
||||
service._reset_account_status_cache()
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
assert data["creators"][0]["account_status"] == "账号异常"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_account_pool_failure_does_not_break_the_report(db, monkeypatch):
|
||||
task_id = await _task()
|
||||
now = get_current_timestamp() - 1000
|
||||
await _note(task_id, "n1", "博主A", now)
|
||||
|
||||
async def down():
|
||||
raise RuntimeError("pool is down")
|
||||
|
||||
monkeypatch.setenv("MC_ACCOUNT_POOL_URL", "http://pool/api")
|
||||
monkeypatch.setattr(service, "_fetch_account_pool", down)
|
||||
service._reset_account_status_cache()
|
||||
|
||||
async with monitor_db.get_session() as session:
|
||||
data = await service.daily_tag_matrix(session, "dy", days=7)
|
||||
|
||||
# 外部服务挂了,报表照出,只是没有状态
|
||||
assert data["dates"]
|
||||
assert data["creators"][0]["account_status"] == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_endpoint_returns_the_long_shape(client):
|
||||
task_id = await _task()
|
||||
|
||||
Reference in New Issue
Block a user