完成请求推送,但组装mes还有问题
This commit is contained in:
82
test_regex_api.py
Normal file
82
test_regex_api.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
测试正则规则系统
|
||||
"""
|
||||
import requests
|
||||
import json
|
||||
|
||||
BASE_URL = "http://localhost:23338"
|
||||
|
||||
def test_get_settings():
|
||||
"""测试获取系统设置"""
|
||||
print("=" * 50)
|
||||
print("测试:获取系统设置")
|
||||
print("=" * 50)
|
||||
|
||||
response = requests.get(f"{BASE_URL}/api/regex/settings")
|
||||
print(f"状态码: {response.status_code}")
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"响应: {json.dumps(data, indent=2, ensure_ascii=False)}")
|
||||
else:
|
||||
print(f"错误: {response.text}")
|
||||
|
||||
print()
|
||||
|
||||
def test_get_rules():
|
||||
"""测试获取规则列表"""
|
||||
print("=" * 50)
|
||||
print("测试:获取规则列表")
|
||||
print("=" * 50)
|
||||
|
||||
response = requests.get(f"{BASE_URL}/api/regex/rules")
|
||||
print(f"状态码: {response.status_code}")
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"规则数量: {data.get('count', 0)}")
|
||||
if data.get('rules'):
|
||||
for rule in data['rules'][:2]: # 只显示前2条
|
||||
print(f" - {rule.get('scriptName', 'N/A')}")
|
||||
else:
|
||||
print(f"错误: {response.text}")
|
||||
|
||||
print()
|
||||
|
||||
def test_update_settings():
|
||||
"""测试更新系统设置"""
|
||||
print("=" * 50)
|
||||
print("测试:更新系统设置")
|
||||
print("=" * 50)
|
||||
|
||||
payload = {
|
||||
"thinkingTagPrefix": "<think>",
|
||||
"thinkingTagSuffix": "</think>"
|
||||
}
|
||||
|
||||
response = requests.put(
|
||||
f"{BASE_URL}/api/regex/settings",
|
||||
json=payload
|
||||
)
|
||||
|
||||
print(f"状态码: {response.status_code}")
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"响应: {json.dumps(data, indent=2, ensure_ascii=False)}")
|
||||
else:
|
||||
print(f"错误: {response.text}")
|
||||
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
test_get_settings()
|
||||
test_get_rules()
|
||||
test_update_settings()
|
||||
|
||||
print("✅ 所有测试完成!")
|
||||
except Exception as e:
|
||||
print(f"❌ 测试失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
Reference in New Issue
Block a user