Skip to content

Commit a63d3e4

Browse files
committed
test: add pytest tests for authorized client connection handling
1 parent 40f8d71 commit a63d3e4

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

tests/test_runner.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
3+
from telegram_mcp import runner
4+
5+
6+
class _FakeClient:
7+
def __init__(self, *, authorized: bool):
8+
self.authorized = authorized
9+
self.connected = False
10+
self.started = False
11+
12+
async def connect(self):
13+
self.connected = True
14+
15+
async def is_user_authorized(self):
16+
return self.authorized
17+
18+
async def start(self):
19+
self.started = True
20+
21+
22+
@pytest.mark.asyncio
23+
async def test_connect_authorized_client_uses_existing_session_without_interactive_start():
24+
client = _FakeClient(authorized=True)
25+
26+
await runner._connect_authorized_client("default", client)
27+
28+
assert client.connected is True
29+
assert client.started is False
30+
31+
32+
@pytest.mark.asyncio
33+
async def test_connect_authorized_client_rejects_unauthorized_session():
34+
client = _FakeClient(authorized=False)
35+
36+
with pytest.raises(RuntimeError, match="Interactive phone login is disabled"):
37+
await runner._connect_authorized_client("default", client)
38+
39+
assert client.connected is True
40+
assert client.started is False

0 commit comments

Comments
 (0)