refactor: centralize settings and application services
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from assistant_bot import application as application_module
|
||||
from assistant_bot.auth import authentication_guard
|
||||
from assistant_bot.config import AppSettings
|
||||
from assistant_bot.handlers import (
|
||||
ask_command,
|
||||
help_command,
|
||||
@@ -22,23 +22,26 @@ from assistant_bot.handlers import (
|
||||
|
||||
class ApplicationRegistrationTests(unittest.TestCase):
|
||||
def test_registers_the_current_public_handlers_in_order(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as directory, patch.multiple(
|
||||
application_module,
|
||||
get_assistant_password=Mock(return_value="secret"),
|
||||
get_bot_token=Mock(return_value="123456:TEST"),
|
||||
get_db_path=Mock(
|
||||
return_value=Path(directory) / "assistant.sqlite3"
|
||||
),
|
||||
get_assistant_mode=Mock(return_value="local"),
|
||||
get_ollama_base_url=Mock(return_value="http://localhost:11434"),
|
||||
get_whisper_model=Mock(return_value="small"),
|
||||
get_whisper_device=Mock(return_value="cpu"),
|
||||
get_whisper_compute_type=Mock(return_value="int8"),
|
||||
get_whisper_language=Mock(return_value="ru"),
|
||||
get_local_timezone=Mock(return_value=ZoneInfo("UTC")),
|
||||
get_voice_max_duration_seconds=Mock(return_value=120),
|
||||
):
|
||||
application = application_module.create_application()
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
settings = AppSettings(
|
||||
bot_token="123456:TEST",
|
||||
assistant_password="secret",
|
||||
db_path=Path(directory) / "assistant.sqlite3",
|
||||
mode="local",
|
||||
timezone=ZoneInfo("UTC"),
|
||||
voice_max_duration_seconds=120,
|
||||
ollama_base_url="http://localhost:11434",
|
||||
ollama_model="qwen3.5:9b",
|
||||
yandex_cloud_folder=None,
|
||||
yandex_cloud_model="yandexgpt/latest",
|
||||
yandex_stt_model="general",
|
||||
yandex_stt_language="ru-RU",
|
||||
whisper_model="small",
|
||||
whisper_device="cpu",
|
||||
whisper_compute_type="int8",
|
||||
whisper_language="ru",
|
||||
)
|
||||
application = application_module.create_application(settings)
|
||||
|
||||
self.assertEqual(
|
||||
[handler.callback for handler in application.handlers[-1]],
|
||||
|
||||
Reference in New Issue
Block a user