This commit is contained in:
@@ -319,6 +319,60 @@ def test_ppt_audit_file_view_renders_online_preview(client, monkeypatch, tmp_pat
|
||||
assert '下載 PPTX' in html
|
||||
|
||||
|
||||
def test_ppt_audit_history_audit_rows_include_inline_replay(client, monkeypatch, tmp_path):
|
||||
"""審核歷史每筆紀錄都應能直接開同頁 PDF 回放。"""
|
||||
import zipfile
|
||||
from datetime import datetime
|
||||
from unittest.mock import MagicMock
|
||||
from routes import admin_observability_routes as mod
|
||||
|
||||
reports_dir = tmp_path / 'reports'
|
||||
reports_dir.mkdir()
|
||||
pptx = reports_dir / 'ocbot_daily_20260517.pptx'
|
||||
with zipfile.ZipFile(pptx, 'w') as zf:
|
||||
zf.writestr('[Content_Types].xml', '<Types></Types>')
|
||||
|
||||
monkeypatch.setenv('REPORTS_DIR', str(reports_dir))
|
||||
|
||||
class FakeSession:
|
||||
def execute(self, statement, _params=None):
|
||||
sql = str(statement)
|
||||
result = MagicMock()
|
||||
if 'FROM ppt_reports' in sql:
|
||||
rows = []
|
||||
result.fetchall.return_value = rows
|
||||
elif 'SELECT audited_at, pptx_filename' in sql:
|
||||
rows = [
|
||||
(datetime(2026, 5, 17, 22, 5), 'ocbot_daily_20260517.pptx', 'passed', 0, 0.93, 1200, '')
|
||||
]
|
||||
result.fetchall.return_value = rows
|
||||
elif 'COALESCE(AVG(confidence)' in sql:
|
||||
row = (1, 1, 0, 0, 0, 0.93, 0)
|
||||
result.fetchone.return_value = row
|
||||
elif 'GROUP BY pptx_filename' in sql:
|
||||
rows = []
|
||||
result.fetchall.return_value = rows
|
||||
else:
|
||||
rows = []
|
||||
result.fetchall.return_value = rows
|
||||
result.fetchone.return_value = (0,)
|
||||
return result
|
||||
|
||||
def close(self):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(mod, 'get_session', lambda: FakeSession())
|
||||
|
||||
r = client.get('/observability/ppt_audit_history?month=2026-05')
|
||||
html = r.data.decode('utf-8')
|
||||
|
||||
assert r.status_code == 200
|
||||
assert '審核回放 · ocbot_daily_20260517.pptx' in html
|
||||
assert 'data-ppt-open-preview' in html
|
||||
assert 'ocbot_daily_20260517.pptx?action=pdf' in html
|
||||
assert '回放' in html
|
||||
|
||||
|
||||
def test_ppt_audit_history_shows_preview_prewarm_action(client, monkeypatch, tmp_path):
|
||||
"""未快取 PDF 的 PPTX 要能在產線清單直接預熱預覽。"""
|
||||
import zipfile
|
||||
|
||||
Reference in New Issue
Block a user