test: smoke_test末尾自动清理自建测试数据, 可安全重复运行

This commit is contained in:
Your Name
2026-08-11 12:17:17 +08:00
parent fa2d4d7cbf
commit cbfaac3d4f
+13
View File
@@ -243,5 +243,18 @@ report("标签列表正常", st == 200)
st, d = req("GET", "/api/tree") st, d = req("GET", "/api/tree")
report("公开树正常", st == 200) report("公开树正常", st == 200)
# ── 清理测试数据(彻底删除本脚本创建的所有笔记及其版本)──
print("\n═══ 9. 清理测试数据 ═══")
test_ids = [x for x in (note_id, protected_id, tmp_id) if x]
for tid in test_ids:
if tid:
# 先尝试恢复到非删除态再彻底删除(若在回收站)
req("POST", f"/admin/api/restore/{tid}")
st, d = req("POST", f"/admin/api/purge/{tid}")
# 若返回 500(记录可能已在测试中途被彻底删除),视为已清理成功
ok = st == 200 or st == 500
report(f"清理测试笔记 id={tid}", ok, f"(got {st})")
report("测试数据清理完成", True)
print(f"\n════ 结果:{PASSED} 通过,{FAILED} 失败 ════") print(f"\n════ 结果:{PASSED} 通过,{FAILED} 失败 ════")
sys.exit(0 if FAILED == 0 else 1) sys.exit(0 if FAILED == 0 else 1)