fix
This commit is contained in:
32
tests/test_jobs.py
Normal file
32
tests/test_jobs.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import asyncio
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from assistant_bot.jobs import post_init, post_shutdown
|
||||
|
||||
|
||||
class ReminderJobLifecycleTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_reminder_task_is_cancelled_on_shutdown(self) -> None:
|
||||
started = asyncio.Event()
|
||||
|
||||
async def fake_reminder_loop(application) -> None:
|
||||
started.set()
|
||||
await asyncio.Event().wait()
|
||||
|
||||
application = SimpleNamespace(bot_data={})
|
||||
with patch("assistant_bot.jobs.reminder_loop", fake_reminder_loop):
|
||||
await post_init(application)
|
||||
await started.wait()
|
||||
|
||||
task = application.bot_data["reminder_task"]
|
||||
self.assertFalse(task.done())
|
||||
|
||||
await post_shutdown(application)
|
||||
|
||||
self.assertTrue(task.cancelled())
|
||||
self.assertNotIn("reminder_task", application.bot_data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -7,6 +7,7 @@ from assistant_bot.yandex_ai import (
|
||||
YandexAIClient,
|
||||
YandexSpeechRecognizer,
|
||||
describe_yandex_error,
|
||||
prepare_chat_messages,
|
||||
)
|
||||
|
||||
|
||||
@@ -38,6 +39,28 @@ class FakeChatCompletions:
|
||||
|
||||
|
||||
class YandexAIClientTests(unittest.IsolatedAsyncioTestCase):
|
||||
def test_multiple_system_messages_are_merged_at_the_beginning(self) -> None:
|
||||
self.assertEqual(
|
||||
prepare_chat_messages(
|
||||
[
|
||||
{"role": "system", "content": "Primary instructions"},
|
||||
{"role": "user", "content": "Earlier question"},
|
||||
{"role": "system", "content": "Runtime context"},
|
||||
{"role": "assistant", "content": "Earlier answer"},
|
||||
{"role": "user", "content": "Current question"},
|
||||
]
|
||||
),
|
||||
[
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Primary instructions\n\nRuntime context",
|
||||
},
|
||||
{"role": "user", "content": "Earlier question"},
|
||||
{"role": "assistant", "content": "Earlier answer"},
|
||||
{"role": "user", "content": "Current question"},
|
||||
],
|
||||
)
|
||||
|
||||
def test_http_error_includes_safe_response_body(self) -> None:
|
||||
error = RuntimeError("forbidden")
|
||||
error.response = SimpleNamespace(
|
||||
|
||||
Reference in New Issue
Block a user