Files
soul-yongping/scripts/test/process/cleanup_test_data.py
Alex-larget e75092eaad Refactor mini program environment configuration and remove deprecated debug features
- Simplified the environment configuration in app.js by removing the debug environment options and related functions.
- Set a default API base URL for production while allowing commented options for local and testing environments.
- Cleaned up settings.js by removing the debug environment label and switching functionality, streamlining the user interface.
- Updated documentation to reflect the removal of debug features and added a summary of synchronization requirements in the planning document.
2026-03-16 13:30:05 +08:00

76 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
清理流程测试产生的数据persons测试自动创建_、测试新人物_、chapterst 开头的 6 位数字 id
用法cd scripts/test && python process/cleanup_test_data.py
"""
import os
import re
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import requests
API_BASE = os.environ.get("SOUL_API_BASE", "http://localhost:8080").rstrip("/")
ADMIN_USER = os.environ.get("SOUL_ADMIN_USERNAME", "admin")
ADMIN_PASS = os.environ.get("SOUL_ADMIN_PASSWORD", "admin123")
def main():
r = requests.post(
f"{API_BASE}/api/admin",
json={"username": ADMIN_USER, "password": ADMIN_PASS},
timeout=10,
)
if not r.json().get("success") or not r.json().get("token"):
print("登录失败")
return 1
token = r.json()["token"]
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
# 1. 删除测试 Person
rp = requests.get(f"{API_BASE}/api/db/persons", headers=headers, timeout=10)
if rp.json().get("success"):
persons = rp.json().get("persons") or []
for p in persons:
name = p.get("name") or ""
if name.startswith("测试自动创建_") or name.startswith("测试新人物_"):
pid = p.get("personId")
rd = requests.delete(
f"{API_BASE}/api/db/persons?personId={pid}",
headers=headers,
timeout=10,
)
if rd.json().get("success"):
print(f" 已删除 Person: {name} ({pid})")
else:
print(f" 删除 Person 失败: {name} - {rd.json()}")
# 2. 删除测试 Chapterid 形如 t123456
rl = requests.get(
f"{API_BASE}/api/db/book?action=list",
headers=headers,
timeout=10,
)
if rl.json().get("success"):
sections = rl.json().get("sections") or []
for s in sections:
sid = s.get("id") or ""
if re.match(r"^t\d{6}$", sid):
rd = requests.delete(
f"{API_BASE}/api/db/book?id={sid}",
headers=headers,
timeout=10,
)
if rd.json().get("success"):
print(f" 已删除 Chapter: {sid} ({s.get('title', '')})")
else:
print(f" 删除 Chapter 失败: {sid} - {rd.json()}")
print("清理完成")
return 0
if __name__ == "__main__":
sys.exit(main())