Spaces:
Sleeping
Sleeping
# tests/test_travel_assistant.py | |
import pytest | |
from unittest.mock import Mock, patch | |
from modules.travel_assistant import TravelAssistant | |
class TestTravelAssistant: | |
def mock_travel_assistant(self): | |
"""创建模拟的旅游助手""" | |
with patch('modules.travel_assistant.ConfigLoader') as mock_config, \ | |
patch('modules.travel_assistant.KnowledgeBase') as mock_kb, \ | |
patch('modules.travel_assistant.AIModel') as mock_ai: | |
# 设置模拟对象 | |
mock_config.return_value.cities = {"巴黎": {"name": "巴黎", "country": "法国"}} | |
mock_config.return_value.personas = {"planner": {"name": "规划型"}} | |
assistant = TravelAssistant() | |
yield assistant | |
def test_chat_basic_flow(self, mock_travel_assistant): | |
"""测试基本聊天流程""" | |
reply, session_id, status_info, history = mock_travel_assistant.chat( | |
message="我想去巴黎旅游", | |
session_id=None, | |
history=[] | |
) | |
assert isinstance(reply, str) | |
assert len(session_id) == 8 # UUID前8位 | |
assert isinstance(status_info, str) | |
assert len(history) == 1 | |
assert history[0][0] == "我想去巴黎旅游" | |
def test_session_persistence(self, mock_travel_assistant): | |
"""测试会话持久性""" | |
# 第一次对话 | |
_, session_id, _, _ = mock_travel_assistant.chat( | |
message="我想去巴黎", | |
session_id=None, | |
history=[] | |
) | |
# 第二次对话使用相同session_id | |
reply, same_session_id, _, _ = mock_travel_assistant.chat( | |
message="3天行程", | |
session_id=session_id, | |
history=[] | |
) | |
assert session_id == same_session_id |