整理配置和代码入口,增加部分测试。
This commit is contained in:
@@ -355,3 +355,55 @@ async def test_poll_tasks_queries_all_info_once_per_project_for_multiple_keys(mo
|
||||
assert polled[task_ids[1]].status == TaskStatus.SUCCESS
|
||||
assert polled[task_ids[1]].data_id == "remote-detail-2"
|
||||
assert client.all_info_calls == ["project-1"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_poll_tasks_retries_until_project_detail_appears(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
collection = DataCollection("remote")
|
||||
project = _build_project_node(node_id="p-node", project_id="project-1", all_info={"project_detail": []})
|
||||
await collection.add(project)
|
||||
|
||||
handler = ProjectDetailApiHandler()
|
||||
handler.set_collection(collection)
|
||||
handler.api_client = _MockApiClient()
|
||||
|
||||
call_count = {"value": 0}
|
||||
|
||||
async def _fake_get_all_info(cls, _client, project_id: str):
|
||||
call_count["value"] += 1
|
||||
if call_count["value"] >= 2:
|
||||
return {
|
||||
"project_detail": [
|
||||
{
|
||||
"id": "remote-detail-1",
|
||||
"project_id": project_id,
|
||||
"key": "ensure_production",
|
||||
"value": [{"year": 2026, "capacity": 21.0}],
|
||||
}
|
||||
]
|
||||
}
|
||||
return {"project_detail": []}
|
||||
|
||||
monkeypatch.setattr(ProjectApiHandler, "get_all_info", classmethod(_fake_get_all_info))
|
||||
|
||||
node = ProjectDetailSyncNode(
|
||||
node_id="detail-node-1",
|
||||
data_id="local-detail-1",
|
||||
data={
|
||||
"id": "local-detail-1",
|
||||
"project_id": "project-1",
|
||||
"key": "ensure_production",
|
||||
"value": [{"year": 2026, "capacity": 21.0}],
|
||||
},
|
||||
)
|
||||
|
||||
create_result = (await handler.create_all([node]))[0]
|
||||
assert create_result.task_id
|
||||
handler.api_client.push_logs[create_result.task_id] = {"code": 200, "data": {"biz_id": "project-1"}}
|
||||
|
||||
polled = await handler.poll_tasks([create_result.task_id])
|
||||
final = polled[create_result.task_id]
|
||||
|
||||
assert final.status == TaskStatus.SUCCESS
|
||||
assert final.data_id == "remote-detail-1"
|
||||
assert call_count["value"] >= 2
|
||||
|
||||
Reference in New Issue
Block a user