45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
|
|
"""session_history 纯映射测试(ConversationService 的会话层,非 Agent)。"""
|
|||
|
|
|
|||
|
|
import unittest
|
|||
|
|
from datetime import datetime, timezone
|
|||
|
|
|
|||
|
|
from app.features.conversation.models import Segment
|
|||
|
|
from app.features.conversation.session_history import segments_to_redis_history
|
|||
|
|
|
|||
|
|
|
|||
|
|
class SegmentsToRedisHistoryTest(unittest.TestCase):
|
|||
|
|
def test_text_turn_maps_to_human_and_ai(self):
|
|||
|
|
seg = Segment(
|
|||
|
|
id="s1",
|
|||
|
|
conversation_id="c1",
|
|||
|
|
transcript_text="我在杭州长大",
|
|||
|
|
audio_url=None,
|
|||
|
|
created_at=datetime(2024, 1, 2, 3, 4, 5, tzinfo=timezone.utc),
|
|||
|
|
agent_response="听起来很温润的城市。",
|
|||
|
|
)
|
|||
|
|
h = segments_to_redis_history([seg])
|
|||
|
|
self.assertEqual(len(h), 2)
|
|||
|
|
self.assertEqual(h[0]["role"], "human")
|
|||
|
|
self.assertEqual(h[0]["messageType"], "text")
|
|||
|
|
self.assertEqual(h[0]["content"], "我在杭州长大")
|
|||
|
|
self.assertEqual(h[1]["role"], "ai")
|
|||
|
|
self.assertEqual(h[1]["content"], "听起来很温润的城市。")
|
|||
|
|
|
|||
|
|
def test_voice_segment_sets_voice_session_id(self):
|
|||
|
|
seg = Segment(
|
|||
|
|
id="s1",
|
|||
|
|
conversation_id="c1",
|
|||
|
|
transcript_text="嗯",
|
|||
|
|
audio_url="audio-segment:vs-9:0",
|
|||
|
|
created_at=datetime(2024, 1, 2, tzinfo=timezone.utc),
|
|||
|
|
agent_response=None,
|
|||
|
|
)
|
|||
|
|
h = segments_to_redis_history([seg])
|
|||
|
|
self.assertEqual(len(h), 1)
|
|||
|
|
self.assertEqual(h[0]["messageType"], "audio")
|
|||
|
|
self.assertEqual(h[0]["voiceSessionId"], "vs-9")
|
|||
|
|
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
unittest.main()
|