import requests import json def test_null_goalid(): """ 测试当goalId为null时会发生什么 """ print("=== 测试goalId为null的情况 ===") # 测试1: goalId为null test_data_null = { "userId": 1, "goalId": None, # 设置为null "subject": "数学", "knowledgePoint": "测试null goalId", "difficulty": "简单", "type": "选择题", "totalQuantity": 1 } print(f"测试数据1 (goalId=null): {json.dumps(test_data_null, indent=2, ensure_ascii=False)}") try: response = requests.post( "http://localhost:8080/api/coze/generate-questions", json=test_data_null, timeout=30 ) print(f"响应状态码: {response.status_code}") if response.status_code == 200: result = response.json() print(f"API响应: {json.dumps(result, ensure_ascii=False, indent=2)}") if result.get('success') and result.get('questions'): for question in result['questions']: print(f"生成的题目goalId: {question.get('goalId')}") else: print(f"请求失败: {response.text}") except Exception as e: print(f"请求异常: {e}") print("\n" + "="*50 + "\n") # 测试2: 不传goalId字段 test_data_missing = { "userId": 1, # 完全不传goalId字段 "subject": "数学", "knowledgePoint": "测试缺失goalId", "difficulty": "简单", "type": "选择题", "totalQuantity": 1 } print(f"测试数据2 (不传goalId): {json.dumps(test_data_missing, indent=2, ensure_ascii=False)}") try: response = requests.post( "http://localhost:8080/api/coze/generate-questions", json=test_data_missing, timeout=30 ) print(f"响应状态码: {response.status_code}") if response.status_code == 200: result = response.json() print(f"API响应: {json.dumps(result, ensure_ascii=False, indent=2)}") if result.get('success') and result.get('questions'): for question in result['questions']: print(f"生成的题目goalId: {question.get('goalId')}") else: print(f"请求失败: {response.text}") except Exception as e: print(f"请求异常: {e}") if __name__ == "__main__": test_null_goalid()