fix(test): 清理日报测试环境变量泄露 + 移除无效 DB_PATH 设置
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
from __future__ import annotations
|
||||
import os
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
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
|
||||
from nmfs_agents.dashboard.api import make_app
|
||||
from fastapi.testclient import TestClient
|
||||
import os
|
||||
|
||||
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,
|
||||
@@ -20,7 +17,6 @@ def test_daily_timeline_with_data(tmp_path):
|
||||
project="company", summary="RTP 优化到 8ms", status="done",
|
||||
))
|
||||
|
||||
# 通过环境变量告知 make_app 使用同一个 daily_reports.db
|
||||
os.environ["DAILY_DB_PATH"] = str(daily_path)
|
||||
try:
|
||||
app = make_app(db_path=tmp_path / "tasks.db")
|
||||
@@ -31,16 +27,12 @@ def test_daily_timeline_with_data(tmp_path):
|
||||
assert len(data) == 1
|
||||
assert "RTP" in data[0]["summary"]
|
||||
finally:
|
||||
del os.environ["DAILY_DB_PATH"]
|
||||
os.environ.pop("DAILY_DB_PATH", None)
|
||||
|
||||
|
||||
def test_daily_timeline_endpoint(tmp_path):
|
||||
"""GET /api/daily/timeline?date=2026-03-09 返回列表"""
|
||||
from nmfs_agents.dashboard.api import make_app
|
||||
from fastapi.testclient import TestClient
|
||||
import os
|
||||
os.environ["DB_PATH"] = str(tmp_path / "t.db")
|
||||
app = make_app(db_path=tmp_path / "t.db")
|
||||
"""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
|
||||
@@ -48,24 +40,16 @@ def test_daily_timeline_endpoint(tmp_path):
|
||||
|
||||
|
||||
def test_daily_boss_summary_endpoint(tmp_path):
|
||||
"""GET /api/daily/boss?date=2026-03-09 返回 null 或摘要对象"""
|
||||
from nmfs_agents.dashboard.api import make_app
|
||||
from fastapi.testclient import TestClient
|
||||
import os
|
||||
os.environ["DB_PATH"] = str(tmp_path / "t2.db")
|
||||
app = make_app(db_path=tmp_path / "t2.db")
|
||||
"""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 返回日期列表"""
|
||||
from nmfs_agents.dashboard.api import make_app
|
||||
from fastapi.testclient import TestClient
|
||||
import os
|
||||
os.environ["DB_PATH"] = str(tmp_path / "t3.db")
|
||||
app = make_app(db_path=tmp_path / "t3.db")
|
||||
"""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
|
||||
|
||||
Reference in New Issue
Block a user