49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
import pytest
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
|
|
def test_discord_reply_success():
|
|
mock_client = MagicMock()
|
|
mock_client.send_message = AsyncMock(
|
|
return_value={"id": "123456", "content": "test message"}
|
|
)
|
|
|
|
with patch(
|
|
"agent.tools.discord_reply.get_discord_client", return_value=mock_client
|
|
), patch.dict("os.environ", {"DISCORD_CHANNEL_ID": "999"}):
|
|
from agent.tools.discord_reply import discord_reply
|
|
result = discord_reply(message="test message")
|
|
assert result["success"] is True
|
|
mock_client.send_message.assert_called_once()
|
|
|
|
|
|
def test_discord_reply_empty_message():
|
|
from agent.tools.discord_reply import discord_reply
|
|
result = discord_reply(message="")
|
|
assert result["success"] is False
|
|
|
|
|
|
def test_discord_reply_no_channel_configured():
|
|
with patch.dict("os.environ", {"DISCORD_CHANNEL_ID": ""}, clear=False):
|
|
from agent.tools.discord_reply import discord_reply
|
|
result = discord_reply(message="test")
|
|
assert result["success"] is False
|
|
assert "DISCORD" in result.get("error", "")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_discord_client_send_message():
|
|
import httpx
|
|
mock_resp = MagicMock(spec=httpx.Response)
|
|
mock_resp.status_code = 200
|
|
mock_resp.json.return_value = {"id": "msg123", "content": "hello"}
|
|
mock_resp.raise_for_status = MagicMock()
|
|
|
|
from agent.utils.discord_client import DiscordClient
|
|
client = DiscordClient(token="test-token")
|
|
client._client.post = AsyncMock(return_value=mock_resp)
|
|
|
|
result = await client.send_message(channel_id="999", content="hello")
|
|
assert result["id"] == "msg123"
|
|
client._client.post.assert_called_once()
|