feat: remove /idea_voice, revert to text-only ideas
This commit is contained in:
1 parent
7b76bef889
commit
2941cb2a24
13 files changed
+152
-124
No files matched your search
@@ -10,9 +10,10 @@ import user_store
|
||||
|
||||
|
||||
class FakeResponse:
|
||||
def __init__(self, status, payload):
|
||||
def __init__(self, status, payload, headers=None):
|
||||
self.status = status
|
||||
self.payload = payload
|
||||
self.headers = headers or {}
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
@@ -23,6 +24,12 @@ class FakeResponse:
|
||||
async def json(self, content_type=None):
|
||||
return self.payload
|
||||
|
||||
async def text(self):
|
||||
if isinstance(self.payload, bytes):
|
||||
return self.payload.decode("utf-8", errors="replace")
|
||||
return str(self.payload)
|
||||
|
||||
|
||||
|
||||
class FakeClientSession:
|
||||
def __init__(self, response, **kwargs):
|
||||
@@ -195,38 +202,6 @@ class ApinexTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertEqual(captured["system_prompt"], apinex_client.TONE_PROFILE_SYSTEM_PROMPT)
|
||||
self.assertEqual(tone, "Разговорный стиль, короткие абзацы")
|
||||
|
||||
async def test_idea_voice_sends_one_audio_message_and_persists_idea_after_send(self):
|
||||
message = SimpleNamespace(answer_voice=AsyncMock())
|
||||
idea = {"title": "Заголовок", "angle": "Угол", "why": "Причина"}
|
||||
|
||||
async def run_in_thread(function, *args):
|
||||
return function(*args)
|
||||
|
||||
with (
|
||||
patch.object(bot, "synthesize_idea_voice", new=AsyncMock(return_value=b"OggS-audio")),
|
||||
patch.object(bot, "save_idea") as save_idea,
|
||||
patch.object(bot.asyncio, "to_thread", side_effect=run_in_thread),
|
||||
):
|
||||
await bot._send_idea_voice(message, idea, 91)
|
||||
|
||||
message.answer_voice.assert_awaited_once()
|
||||
voice_file = message.answer_voice.await_args.args[0]
|
||||
self.assertEqual(voice_file.filename, "idea.mp3")
|
||||
save_idea.assert_called_once_with(91, idea)
|
||||
|
||||
async def test_synthesize_idea_voice_returns_mp3_audio(self):
|
||||
def fake_run(command, **kwargs):
|
||||
output_path = command[-1] if command[0].endswith("lame") else command[command.index("-w") + 1]
|
||||
with open(output_path, "wb") as output_file:
|
||||
output_file.write(b"ID3" + b"x" * 1200)
|
||||
|
||||
with (
|
||||
patch.object(apinex_client.shutil, "which", side_effect=["/usr/bin/espeak-ng", "/usr/bin/lame"]),
|
||||
patch.object(apinex_client.subprocess, "run", side_effect=fake_run),
|
||||
):
|
||||
audio = await apinex_client.synthesize_idea_voice("Идея для поста о кофе")
|
||||
self.assertTrue(audio.startswith(b"ID3"))
|
||||
self.assertGreater(len(audio), 1000)
|
||||
|
||||
async def test_idea_generation_returns_topics_only_and_uses_history(self):
|
||||
captured = {}
|
||||
|
||||
Reference in new issue
Block a user