- Surface Protocol: unified IncomingMessage/OutgoingUI/ChatContext - Telegram: Forum Topics (group + topics per chat) - Matrix: Space + rooms per chat - MockPlatformClient with PlatformClient Protocol - docs: surface-protocol, telegram/matrix specs, api-contract, claude-code-guide - project scaffold: src/, tests/, pyproject.toml Co-Authored-By: Claude Sonnet 4-6 <noreply@anthropic.com>
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""Тесты для MockPlatformClient — проверяем что заглушка работает корректно."""
|
|
|
|
import pytest
|
|
from src.mock_platform import MockPlatformClient, SessionNotFoundError
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
return MockPlatformClient()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_session_returns_ids(client):
|
|
result = await client.create_session(user_id="tg-123", platform="telegram")
|
|
|
|
assert "session_id" in result
|
|
assert "agent_id" in result
|
|
assert "expires_at" in result
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_send_message_returns_response(client):
|
|
session = await client.create_session(user_id="tg-123", platform="telegram")
|
|
result = await client.send_message(session["session_id"], "Привет!")
|
|
|
|
assert "response" in result
|
|
assert len(result["response"]) > 0
|
|
assert result["finished"] is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_session_not_found_raises(client):
|
|
with pytest.raises(SessionNotFoundError):
|
|
await client.get_session("non-existent-id")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_close_session(client):
|
|
session = await client.create_session(user_id="tg-123", platform="telegram")
|
|
result = await client.close_session(session["session_id"])
|
|
|
|
assert result is True
|
|
|
|
# Повторное закрытие — уже закрыта
|
|
result2 = await client.close_session(session["session_id"])
|
|
assert result2 is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_or_create_user(client):
|
|
user = await client.get_or_create_user(
|
|
external_id="12345",
|
|
platform="telegram",
|
|
display_name="Test User",
|
|
)
|
|
|
|
assert user["user_id"].startswith("user-telegram-")
|
|
assert user["external_id"] == "12345"
|
|
assert user["platform"] == "telegram"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_message_history(client):
|
|
session = await client.create_session(user_id="tg-123", platform="telegram")
|
|
sid = session["session_id"]
|
|
|
|
await client.send_message(sid, "Первое сообщение")
|
|
await client.send_message(sid, "Второе сообщение")
|
|
|
|
history = await client.get_message_history(sid, limit=10)
|
|
assert len(history) == 2
|