fix(web): align trend ranges, next runs and preview task records
This commit is contained in:
1 parent
19572171b8
commit
257fbe009b
7 files changed
+139
-10
No files matched your search
@@ -194,6 +194,34 @@ def test_run_once_offline():
|
||||
db.close()
|
||||
|
||||
|
||||
def test_serve_preview_guard():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = write_config(tmp)
|
||||
assert run_cli(["init", "--config", str(path)])[0] == 0
|
||||
db_path = Path(tmp) / "app.db"
|
||||
try:
|
||||
cli._assert_preview_database(db_path)
|
||||
except cli.ConfigError as exc:
|
||||
assert "preview:seeded" in str(exc)
|
||||
else:
|
||||
raise AssertionError("普通数据库不应通过 --preview 校验")
|
||||
|
||||
db = Database(db_path)
|
||||
db.initialize()
|
||||
try:
|
||||
Repository(db).kv_set("preview:seeded", "1")
|
||||
finally:
|
||||
db.close()
|
||||
cli._assert_preview_database(db_path)
|
||||
|
||||
try:
|
||||
cli._assert_preview_database(Path(tmp) / "missing.db")
|
||||
except cli.ConfigError as exc:
|
||||
assert "不存在" in str(exc)
|
||||
else:
|
||||
raise AssertionError("缺失数据库应报错")
|
||||
|
||||
|
||||
def test_default_command_starts_web_and_scheduler():
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = write_config(tmp)
|
||||
@@ -299,6 +327,7 @@ def main_test():
|
||||
test_auth_check_without_cookie()
|
||||
test_auth_check_all_and_auth_dispatch()
|
||||
test_run_once_offline()
|
||||
test_serve_preview_guard()
|
||||
test_default_command_starts_web_and_scheduler()
|
||||
test_snapshot_backup_failure_returns_error_and_retries()
|
||||
test_candidates_and_discover_commands()
|
||||
|
||||
@@ -203,6 +203,9 @@ def test_seed_preview_end_to_end():
|
||||
assert conn.execute(
|
||||
"SELECT 1 FROM up_blacklist WHERE mid=?", (FAKE_BLACKLIST_MID,)
|
||||
).fetchone() is not None
|
||||
assert conn.execute(
|
||||
"SELECT 1 FROM kv WHERE k='task:last:snapshot'"
|
||||
).fetchone() is not None
|
||||
up_rows = conn.execute(
|
||||
"SELECT stat_date, follower FROM up_stat WHERE mid=37754047 "
|
||||
"ORDER BY stat_date"
|
||||
|
||||
@@ -142,6 +142,10 @@ def test_video_detail_and_trend():
|
||||
assert trend["available"] is True
|
||||
assert len(trend["points"]) == 3
|
||||
|
||||
# 请求区间早于首次快照时,从首次快照开始,不制造空白历史
|
||||
wide = q.video_trend(101, days=30)
|
||||
assert wide["dates"] == list(DATES)
|
||||
|
||||
# 删除中间一天,折线在缺失日期应为 None,而不是插值
|
||||
db.write(lambda conn: conn.execute(
|
||||
"DELETE FROM snapshot WHERE aid=101 AND stat_date=?",
|
||||
@@ -204,6 +208,8 @@ def test_fans_candidates_system_and_export():
|
||||
assert fans["delta_7d"] is None
|
||||
assert fans["delta_cum"] == 20
|
||||
assert fans["options"][0]["mid"] == 37754047
|
||||
wide = q.fans(days=30)
|
||||
assert wide["dates"] == list(DATES)
|
||||
|
||||
candidates = q.candidates()
|
||||
assert candidates["total"] == 2
|
||||
@@ -220,6 +226,8 @@ def test_fans_candidates_system_and_export():
|
||||
assert system["errors"] == []
|
||||
assert system["preview"] is False
|
||||
assert system["next_runs"]["snapshot"] > 0
|
||||
assert system["next_runs"]["folder_sync"] > FIXED_NOW
|
||||
assert system["next_runs"]["discover"] > FIXED_NOW
|
||||
|
||||
exported = q.export_videos(sort="view")
|
||||
assert exported["total"] == 3
|
||||
|
||||
@@ -74,6 +74,13 @@ def test_readonly_routes_and_static():
|
||||
assert "text/html" in headers["Content-Type"]
|
||||
assert b"<html" in payload.lower()
|
||||
|
||||
for asset in ("/static/style.css", "/static/app.js", "/static/vendor/echarts.min.js"):
|
||||
status, asset_headers, asset_payload = running.request(asset)
|
||||
assert status == 200, asset
|
||||
assert asset_payload, asset
|
||||
content_type = asset_headers["Content-Type"]
|
||||
assert "text/css" in content_type or "javascript" in content_type, asset
|
||||
|
||||
status, _, payload = running.request("/static/../config.json")
|
||||
assert status == 404
|
||||
|
||||
|
||||
Reference in new issue
Block a user