merge: 合并移除导出功能分支

# Conflicts:
#	tests/integration/test_routes.py
This commit is contained in:
meijiali
2026-07-03 19:28:59 +08:00
9 changed files with 31 additions and 289 deletions
+21 -32
View File
@@ -422,8 +422,10 @@ def test_result_pages_render_seeded_data():
assert 'onclick="window.location.reload()"' in task_response.text
assert hotspot_response.status_code == 200
assert "热点总结" in hotspot_response.text
assert "downloadExport('/api/export/hotspots/hot-result.md'" in hotspot_response.text
assert "downloadExport('/api/export/hotspots/hot-result/comments.csv'" in hotspot_response.text
assert "downloadExport(" not in hotspot_response.text
assert "/api/export/" not in hotspot_response.text
assert "导出 Markdown" not in hotspot_response.text
assert "导出热点评论 CSV" not in hotspot_response.text
assert "评论样本" in hotspot_response.text
assert "关联内容" in hotspot_response.text
assert "正向" in hotspot_response.text
@@ -437,8 +439,10 @@ def test_result_pages_render_seeded_data():
item_visible_text = BeautifulSoup(item_response.text, "html.parser").get_text(" ")
assert "热点 1:热点标题" in item_visible_text
assert "#" not in item_visible_text
assert "downloadExport('/api/export/items/item-result.md'" in item_response.text
assert "downloadExport('/api/export/items/item-result/comments.csv'" in item_response.text
assert "downloadExport(" not in item_response.text
assert "/api/export/" not in item_response.text
assert "导出 Markdown" not in item_response.text
assert "导出评论 CSV" not in item_response.text
assert "评论样本" in item_response.text
assert "Top 标签" in item_response.text
assert "评论内容" in item_response.text
@@ -473,14 +477,16 @@ def test_report_pages_render_empty_state_when_report_missing():
assert hotspot_response.status_code == 200
assert "报告生成中,请稍候" in hotspot_response.text
assert 'title="报告尚未生成"' in hotspot_response.text
assert "Markdown 报告将在分析完成后开放下载" in hotspot_response.text
assert "downloadExport('/api/export/hotspots/hot-no-report/comments.csv'" in hotspot_response.text
assert 'title="报告尚未生成"' not in hotspot_response.text
assert "Markdown 报告将在分析完成后开放下载" not in hotspot_response.text
assert "downloadExport(" not in hotspot_response.text
assert "/api/export/" not in hotspot_response.text
assert item_response.status_code == 200
assert "报告生成中,请稍候" in item_response.text
assert 'title="报告尚未生成"' in item_response.text
assert "Markdown 报告将在分析完成后开放下载" in item_response.text
assert "downloadExport('/api/export/items/item-no-report/comments.csv'" in item_response.text
assert 'title="报告尚未生成"' not in item_response.text
assert "Markdown 报告将在分析完成后开放下载" not in item_response.text
assert "downloadExport(" not in item_response.text
assert "/api/export/" not in item_response.text
def test_report_pages_warn_when_ai_sample_is_insufficient():
@@ -503,7 +509,7 @@ def test_report_pages_warn_when_ai_sample_is_insufficient():
assert "当前有效评论样本不足" in item_response.text
def test_export_routes_return_csv_and_markdown():
def test_export_routes_are_removed():
with make_test_client() as (client, engine):
seed_result_data(engine)
@@ -512,15 +518,10 @@ def test_export_routes_return_csv_and_markdown():
hotspot_md = client.get("/api/export/hotspots/hot-result.md")
item_md = client.get("/api/export/items/item-result.md")
assert csv_response.status_code == 200
assert csv_response.content.startswith(b"\xef\xbb\xbf")
assert "评论内容".encode("utf-8") in csv_response.content
assert hotspot_csv_response.status_code == 200
assert "评论内容".encode("utf-8") in hotspot_csv_response.content
assert hotspot_md.status_code == 200
assert "热点总结" in hotspot_md.text
assert item_md.status_code == 200
assert "内容总结" in item_md.text
assert csv_response.status_code == 404
assert hotspot_csv_response.status_code == 404
assert hotspot_md.status_code == 404
assert item_md.status_code == 404
def test_api_tasks_returns_service_unavailable_when_database_has_io_error(monkeypatch):
@@ -616,18 +617,6 @@ def test_item_detail_page_shows_database_error_state_when_database_has_io_error(
assert "数据库暂时不可用" in response.text
def test_export_route_returns_service_unavailable_when_database_has_io_error(monkeypatch):
def broken_export(_session, _item_id):
raise OperationalError("SELECT 1", {}, Exception("disk I/O error"))
monkeypatch.setattr("app.main.export_item_comments_csv", broken_export)
with make_test_client() as (client, _engine):
response = client.get("/api/export/items/item-io/comments.csv")
assert response.status_code == 503
assert response.json()["detail"] == "数据库暂时不可用,请稍后重试或联系维护者恢复数据。"
def test_missing_html_pages_render_friendly_not_found_page():
with make_test_client() as (client, _engine):
+4 -2
View File
@@ -4,7 +4,7 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def test_user_guide_covers_startup_acceptance_exports_and_troubleshooting():
def test_user_guide_covers_startup_acceptance_no_exports_and_troubleshooting():
content = (ROOT / "docs" / "UserGuide.md").read_text(encoding="utf-8")
for required in [
@@ -12,7 +12,9 @@ def test_user_guide_covers_startup_acceptance_exports_and_troubleshooting():
"http://localhost:8000",
"1 × 1 × 10",
"5 × 5 × 50",
"导出文件",
"文件导出",
"已关闭 CSV / Markdown 文件下载入口和接口",
"页面不展示 CSV / Markdown 下载入口",
"8000 端口被占用",
"API Key 缺失",
"任务长期 running",
-24
View File
@@ -1,24 +0,0 @@
from app.services.export_service import labels_to_text, safe_csv_field, safe_filename
def test_labels_to_text_joins_json_array_with_chinese_comma():
assert labels_to_text('["认可", "质量好"]') == "认可,质量好"
assert labels_to_text("bad-json") == ""
def test_safe_csv_field_prevents_formula_injection_and_newlines():
assert safe_csv_field("=1+1") == "'=1+1"
assert safe_csv_field("+1+1") == "'+1+1"
assert safe_csv_field("-1+1") == "'-1+1"
assert safe_csv_field("@SUM(1,1)") == "'@SUM(1,1)"
assert safe_csv_field("hello\nworld") == "hello world"
assert safe_csv_field("hello\r\nworld") == "hello world"
assert safe_csv_field("hello\rworld") == "hello world"
def test_safe_filename_replaces_illegal_chars_and_truncates_keyword():
filename = safe_filename("douyin", "task", "a/b:c*d?e<f>g|很长很长很长很长很长")
assert "/" not in filename
assert "__" not in filename
assert filename.endswith(".csv")