-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
91 lines (77 loc) · 3.07 KB
/
Copy pathtest_api.py
File metadata and controls
91 lines (77 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
"""
测试前后端通信的简单脚本
"""
import requests
import json
def test_backend():
base_url = "http://127.0.0.1:8000"
print("=== 测试后端服务 ===")
# 1. 健康检查
try:
response = requests.get(f"{base_url}/health", timeout=5)
print(f"✅ 健康检查: {response.status_code}")
print(f" 响应: {response.json()}")
except Exception as e:
print(f"❌ 健康检查失败: {e}")
return False
# 2. 自动评分接口测试
try:
test_data = {
"answer": "这是一个测试答案,包含了一些关键词。",
"reference": "这是参考答案,也包含了一些关键词。",
"core_keywords": ["测试", "答案", "关键词"],
"related_keywords": ["相关", "内容"],
"assist_keywords": ["辅助", "信息"],
"abbr_map": {}
}
response = requests.post(
f"{base_url}/api/autograde/score",
json=test_data,
timeout=10
)
print(f"✅ 自动评分接口: {response.status_code}")
result = response.json()
print(f" 语义相似度: {result.get('semantic', 'N/A')}")
print(f" 关键词得分: {result.get('keyterm', 'N/A')}")
print(f" 连贯性得分: {result.get('coherence', 'N/A')}")
print(f" 最终得分: {result.get('final', 'N/A')}")
except Exception as e:
print(f"❌ 自动评分接口失败: {e}")
return False
# 3. 材料管理接口测试
try:
response = requests.get(f"{base_url}/api/materials", timeout=5)
print(f"✅ 材料管理接口: {response.status_code}")
print(f" 响应: {response.json()}")
except Exception as e:
print(f"❌ 材料管理接口失败: {e}")
# 4. 考试管理接口测试
try:
response = requests.get(f"{base_url}/api/exams", timeout=5)
print(f"✅ 考试管理接口: {response.status_code}")
print(f" 响应: {response.json()}")
except Exception as e:
print(f"❌ 考试管理接口失败: {e}")
return True
def test_frontend():
print("\n=== 测试前端服务 ===")
try:
response = requests.get("http://127.0.0.1:9527/test.html", timeout=5)
print(f"✅ 前端测试页面: {response.status_code}")
return True
except Exception as e:
print(f"❌ 前端测试页面失败: {e}")
return False
if __name__ == "__main__":
print("开始测试前后端通信...")
backend_ok = test_backend()
frontend_ok = test_frontend()
print("\n=== 测试结果 ===")
print(f"后端服务: {'✅ 正常' if backend_ok else '❌ 异常'}")
print(f"前端服务: {'✅ 正常' if frontend_ok else '❌ 异常'}")
if backend_ok and frontend_ok:
print("\n🎉 前后端通信测试成功!")
print("可以在浏览器中访问 http://127.0.0.1:9527/test.html 进行交互测试")
else:
print("\n⚠️ 部分服务存在问题,请检查日志")