123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import requests
- import json
- def test_goalid_consistency():
- print("=== 测试goalId一致性 ===")
-
- # 测试数据
- test_data = {
- "userId": 1,
- "goalId": 6, # 使用新的goalId进行测试
- "subject": "数学",
- "type": "选择题",
- "difficulty": "中等",
- "totalQuantity": 1,
- "knowledgePoint": "导数的应用"
- }
-
- print(f"测试请求参数: {json.dumps(test_data, indent=2, ensure_ascii=False)}")
- print()
-
- try:
- # 1. 调用Coze生成题目API
- print("=== 步骤1: 调用Coze生成题目API ===")
- response = requests.post(
- "http://localhost:8080/api/coze/generate-questions",
- json=test_data,
- timeout=60
- )
-
- if response.status_code == 200:
- result = response.json()
- print(f"API调用成功: {json.dumps(result, indent=2, ensure_ascii=False)}")
- print()
-
- # 2. 查询数据库中的题目
- print("=== 步骤2: 查询数据库中的题目 ===")
- db_response = requests.get(f"http://localhost:8080/api/ai/questions/{test_data['goalId']}")
-
- if db_response.status_code == 200:
- db_result = db_response.json()
- print(f"数据库查询结果: {json.dumps(db_result, indent=2, ensure_ascii=False)}")
- print()
-
- # 3. 检查goalId一致性
- print("=== 步骤3: 检查goalId一致性 ===")
- expected_goal_id = test_data['goalId']
-
- if 'data' in db_result and db_result['data']:
- questions = db_result['data']
- print(f"找到 {len(questions)} 道题目")
-
- for i, question in enumerate(questions, 1):
- actual_goal_id = question.get('goalId')
- detail_id = question.get('detailId')
-
- print(f"题目 {i}: detail_id={detail_id}, 预期goalId={expected_goal_id}, 实际goalId={actual_goal_id}")
-
- if actual_goal_id == expected_goal_id:
- print(f"✅ 题目 {i} goalId一致")
- else:
- print(f"❌ 题目 {i} goalId不一致!预期: {expected_goal_id}, 实际: {actual_goal_id}")
- print()
- else:
- print("❌ 数据库中没有找到题目")
- else:
- print(f"❌ 数据库查询失败: {db_response.status_code}")
- print(db_response.text)
- else:
- print(f"❌ API调用失败: {response.status_code}")
- print(response.text)
-
- except requests.exceptions.Timeout:
- print("❌ 请求超时")
- except Exception as e:
- print(f"❌ 请求异常: {e}")
- if __name__ == "__main__":
- test_goalid_consistency()
|