LPC/test_interview_flow.py

104 lines
3.6 KiB
Python
Raw Permalink 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.

#!/usr/bin/env python3
import requests
import json
import time
base_url = "http://127.0.0.1:5000"
def test_interview_flow():
print("=== 测试面试完整流程 ===")
# 1. 开始面试
print("\n1. 开始面试...")
start_response = requests.post(
f"{base_url}/api/interview/start",
headers={"Content-Type": "application/json"},
json={"job_position": "前端开发工程师", "difficulty": "medium"}
)
if start_response.status_code != 200:
print(f"开始面试失败: {start_response.status_code}")
print(start_response.text)
return False
start_data = start_response.json()
interview_id = start_data.get("interview_id")
print(f"面试ID: {interview_id}")
print(f"第一个问题: {start_data.get('question')}")
# 2. 回答第一个问题
print("\n2. 回答第一个问题...")
answer1 = "我有3年前端开发经验熟悉React和Vue框架。"
answer1_response = requests.post(
f"{base_url}/api/interview/answer",
headers={"Content-Type": "application/json"},
json={"interview_id": interview_id, "answer": answer1, "request_feedback": False}
)
if answer1_response.status_code != 200:
print(f"回答问题失败: {answer1_response.status_code}")
print(answer1_response.text)
return False
answer1_data = answer1_response.json()
print(f"第二个问题: {answer1_data.get('question')}")
# 3. 回答第二个问题
print("\n3. 回答第二个问题...")
answer2 = "我在项目中使用过React Hooks特别是useState、useEffect和useContext能够有效管理组件状态和副作用。"
answer2_response = requests.post(
f"{base_url}/api/interview/answer",
headers={"Content-Type": "application/json"},
json={"interview_id": interview_id, "answer": answer2, "request_feedback": False}
)
if answer2_response.status_code != 200:
print(f"回答问题失败: {answer2_response.status_code}")
print(answer2_response.text)
return False
answer2_data = answer2_response.json()
if answer2_data.get('ended'):
print("面试结束")
else:
print(f"第三个问题: {answer2_data.get('question')}")
# 4. 生成面试反馈
print("\n4. 生成面试反馈...")
# 构造对话历史
conversation_history = [
{"role": "assistant", "content": start_data.get('question')},
{"role": "user", "content": answer1},
{"role": "assistant", "content": answer1_data.get('question')},
{"role": "user", "content": answer2}
]
if not answer2_data.get('ended') and answer2_data.get('question'):
conversation_history.append({"role": "assistant", "content": answer2_data.get('question')})
feedback_response = requests.post(
f"{base_url}/api/interview/feedback",
headers={"Content-Type": "application/json"},
json={"interview_id": interview_id, "conversation_history": conversation_history}
)
if feedback_response.status_code != 200:
print(f"生成反馈失败: {feedback_response.status_code}")
print(feedback_response.text)
return False
feedback_data = feedback_response.json()
print("\n=== 面试反馈 ===")
print(feedback_data.get('feedback', ''))
return True
if __name__ == "__main__":
success = test_interview_flow()
if success:
print("\n=== 测试成功!完整的面试流程正常工作 ===")
else:
print("\n=== 测试失败!请检查相关代码 ===")