40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""COS key collection for conversation TTS URLs."""
|
|
|
|
from app.core.cos_url_keys import (
|
|
collect_cos_keys_from_conversation_history,
|
|
collect_cos_keys_from_tts_url_list,
|
|
)
|
|
|
|
|
|
def test_collect_from_history_empty():
|
|
assert collect_cos_keys_from_conversation_history([]) == set()
|
|
|
|
|
|
def test_collect_from_history_ai_tts_urls(monkeypatch):
|
|
monkeypatch.setattr(
|
|
"app.core.cos_url_keys.settings.tencent_cos_bucket",
|
|
"bucket",
|
|
raising=False,
|
|
)
|
|
monkeypatch.setattr(
|
|
"app.core.cos_url_keys.settings.tencent_cos_region",
|
|
"ap-guangzhou",
|
|
raising=False,
|
|
)
|
|
url = "https://bucket.cos.ap-guangzhou.myqcloud.com/conversations/c1/tts/a.mp3"
|
|
hist = [
|
|
{"role": "human", "content": "hi", "messageType": "text"},
|
|
{
|
|
"role": "ai",
|
|
"content": "hello",
|
|
"messageType": "text",
|
|
"ttsAudioUrls": [url],
|
|
},
|
|
]
|
|
keys = collect_cos_keys_from_conversation_history(hist)
|
|
assert keys == {"conversations/c1/tts/a.mp3"}
|
|
|
|
|
|
def test_collect_from_tts_url_list_none():
|
|
assert collect_cos_keys_from_tts_url_list(None) == set()
|