66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
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.handlers import (
|
|
ask_command,
|
|
help_command,
|
|
history_command,
|
|
inline_query,
|
|
model_command,
|
|
models_command,
|
|
new_conversation_command,
|
|
private_text,
|
|
private_voice,
|
|
start,
|
|
)
|
|
|
|
|
|
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()
|
|
|
|
self.assertEqual(
|
|
[handler.callback for handler in application.handlers[-1]],
|
|
[authentication_guard],
|
|
)
|
|
self.assertEqual(
|
|
[handler.callback for handler in application.handlers[0]],
|
|
[
|
|
start,
|
|
help_command,
|
|
ask_command,
|
|
models_command,
|
|
model_command,
|
|
new_conversation_command,
|
|
history_command,
|
|
inline_query,
|
|
private_voice,
|
|
private_text,
|
|
],
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|