fix: use user log stat endpoint for finance upstream costs

This commit is contained in:
SmartUp Developer
2026-07-03 15:59:47 +08:00
parent a1e2c059b9
commit 1a1a663b6a
2 changed files with 44 additions and 3 deletions
+28 -1
View File
@@ -282,7 +282,7 @@ def test_upstream_cost_new_api_success(monkeypatch):
assert err is None
assert abs(amount - 10.0) < 1e-6 # 5_000_000 / 500_000 = 10.0
assert mock_client_instance.calls[0]["method"] == "GET"
assert mock_client_instance.calls[0]["url"] == "http://up.test/api/log/stat"
assert mock_client_instance.calls[0]["url"] == "http://up.test/api/log/self/stat"
assert mock_client_instance.calls[0]["params"] == {
"type": 2,
"start_timestamp": 1782921600,
@@ -290,6 +290,33 @@ def test_upstream_cost_new_api_success(monkeypatch):
}
def test_upstream_cost_new_api_zero_quota_success(monkeypatch):
u = FakeUpstream(api_prefix="", auth_type="new_api_token")
monkeypatch.setattr(
"app.services.finance_service.UpstreamClient",
lambda **kw: FakeUpstreamClientCtx(response={"data": {"quota": 0}}),
)
amount, err = fetch_upstream_cost_new_api(u, date(2026, 7, 2))
assert err is None
assert amount == 0.0
def test_upstream_cost_new_api_success_false_uses_remote_message(monkeypatch):
u = FakeUpstream(api_prefix="", auth_type="new_api_token")
monkeypatch.setattr(
"app.services.finance_service.UpstreamClient",
lambda **kw: FakeUpstreamClientCtx(response={"success": False, "message": "无权访问日志统计"}),
)
amount, err = fetch_upstream_cost_new_api(u, date(2026, 7, 2))
assert amount == 0.0
assert err == "无权访问日志统计"
assert "quota" not in err
def test_upstream_cost_new_api_missing_quota(monkeypatch):
u = FakeUpstream(api_prefix="", auth_type="new_api_token")
monkeypatch.setattr(