feat: 完善 MVP-2 演示和进度体验
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from app.models import Comment, ContentItem, Hotspot, Report, Task
|
||||
from tests.helpers import make_test_client
|
||||
from sqlalchemy.exc import OperationalError
|
||||
|
||||
|
||||
def test_index_page_renders_task_form_empty_state_and_default_scale():
|
||||
@@ -354,3 +355,59 @@ def test_export_routes_return_csv_and_markdown():
|
||||
assert "热点总结" in hotspot_md.text
|
||||
assert item_md.status_code == 200
|
||||
assert "内容总结" in item_md.text
|
||||
|
||||
|
||||
def test_api_tasks_returns_service_unavailable_when_database_has_io_error(monkeypatch):
|
||||
def broken_list_tasks(_session):
|
||||
raise OperationalError("SELECT 1", {}, Exception("disk I/O error"))
|
||||
|
||||
monkeypatch.setattr("app.main.list_tasks", broken_list_tasks)
|
||||
|
||||
with make_test_client() as (client, _engine):
|
||||
response = client.get("/api/tasks")
|
||||
|
||||
assert response.status_code == 503
|
||||
assert response.json()["detail"] == "数据库暂时不可用,请稍后重试或联系维护者恢复数据。"
|
||||
|
||||
|
||||
def test_index_page_shows_database_error_state_when_database_has_io_error(monkeypatch):
|
||||
def broken_list_tasks(_session):
|
||||
raise OperationalError("SELECT 1", {}, Exception("disk I/O error"))
|
||||
|
||||
monkeypatch.setattr("app.main.list_tasks", broken_list_tasks)
|
||||
|
||||
with make_test_client() as (client, _engine):
|
||||
response = client.get("/")
|
||||
|
||||
assert response.status_code == 503
|
||||
assert "数据库暂时不可用" in response.text
|
||||
assert "请先保留 data 目录" in response.text
|
||||
|
||||
|
||||
def test_task_api_includes_progress_counts_stage_and_demo_flag():
|
||||
with make_test_client() as (client, engine):
|
||||
seed_result_data(engine)
|
||||
|
||||
response = client.get("/api/tasks/task-result")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["current_stage"] in (None, "success")
|
||||
assert data["current_stage_label"] == "已完成"
|
||||
assert data["comments_count"] == 1
|
||||
assert data["reports_count"] == 2
|
||||
assert data["is_demo"] is False
|
||||
assert data["last_progress_at"] is not None
|
||||
|
||||
|
||||
def test_task_detail_page_explains_target_and_actual_counts():
|
||||
with make_test_client() as (client, engine):
|
||||
seed_result_data(engine)
|
||||
|
||||
response = client.get("/tasks/task-result")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "目标上限" in response.text
|
||||
assert "实际结果" in response.text
|
||||
assert "实际评论 1" in response.text
|
||||
assert "少于理论上限通常是内容本身评论不足或平台返回不足" in response.text
|
||||
|
||||
Reference in New Issue
Block a user