57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
from __future__ import annotations
|
|
import os
|
|
import pytest
|
|
from nmfs_agents.dashboard.api import make_app
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_daily_timeline_with_data(tmp_path):
|
|
"""写入一条记录后,GET /api/daily/timeline 能读到它"""
|
|
from nmfs_agents.tools.daily_report import DailyReport, ReportEntry
|
|
|
|
daily_path = tmp_path / "daily_reports.db"
|
|
daily_db = DailyReport(db_path=daily_path)
|
|
daily_db.append(ReportEntry(
|
|
report_date="2026-03-09", report_hour=10,
|
|
event_type="task_done", source_role="ops",
|
|
project="company", summary="RTP 优化到 8ms", status="done",
|
|
))
|
|
|
|
os.environ["DAILY_DB_PATH"] = str(daily_path)
|
|
try:
|
|
app = make_app(db_path=tmp_path / "tasks.db")
|
|
client = TestClient(app)
|
|
resp = client.get("/api/daily/timeline?date=2026-03-09")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert len(data) == 1
|
|
assert "RTP" in data[0]["summary"]
|
|
finally:
|
|
os.environ.pop("DAILY_DB_PATH", None)
|
|
|
|
|
|
def test_daily_timeline_endpoint(tmp_path):
|
|
"""GET /api/daily/timeline?date=2026-03-09 返回列表(空库)"""
|
|
app = make_app(db_path=tmp_path / "tasks.db")
|
|
client = TestClient(app)
|
|
resp = client.get("/api/daily/timeline?date=2026-03-09")
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), list)
|
|
|
|
|
|
def test_daily_boss_summary_endpoint(tmp_path):
|
|
"""GET /api/daily/boss?date=2026-03-09 返回 null(空库)"""
|
|
app = make_app(db_path=tmp_path / "tasks.db")
|
|
client = TestClient(app)
|
|
resp = client.get("/api/daily/boss?date=2026-03-09")
|
|
assert resp.status_code == 200
|
|
|
|
|
|
def test_daily_dates_endpoint(tmp_path):
|
|
"""GET /api/daily/dates 返回日期列表(空库)"""
|
|
app = make_app(db_path=tmp_path / "tasks.db")
|
|
client = TestClient(app)
|
|
resp = client.get("/api/daily/dates")
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), list)
|