38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
from app.config import AccountConfig, AppConfig
|
|
from app.manager import AccountManager
|
|
|
|
|
|
class AccountManagerQrTests(unittest.IsolatedAsyncioTestCase):
|
|
async def test_qr_flag_is_passed_when_starting_account(self) -> None:
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
config = AppConfig(
|
|
api_id=123456,
|
|
api_hash="hash",
|
|
session_dir=Path(temp_dir),
|
|
accounts=[AccountConfig(name="personal", session="personal", use_qr=True)],
|
|
)
|
|
manager = AccountManager(config)
|
|
client = MagicMock()
|
|
client.start = AsyncMock()
|
|
client.get_me = AsyncMock(return_value=MagicMock(id=42))
|
|
|
|
with (
|
|
patch.object(AccountManager, "_make_client", return_value=client),
|
|
patch("app.manager.register_common_handlers"),
|
|
):
|
|
await manager.start_account(manager.states[0])
|
|
|
|
client.start.assert_awaited_once_with(use_qr=True)
|
|
self.assertEqual(manager.states[0].status, "running")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|