aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_ai.py
blob: aab9861768f65a07e06c530ef1c458e871fe20d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest
from unittest.mock import AsyncMock, patch, MagicMock
from conftest import MockApplicationContext


@pytest.fixture
def ai_cog(bot):
    from cogs.ai import AI
    cog = AI(bot)
    return cog


@pytest.mark.asyncio
async def test_senator_command_success(ai_cog, mock_channel, mock_guild, bot):
    ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)

    with patch('cogs.ai.llm_completion', new_callable=AsyncMock, return_value="Test response from AI") as mock_llm:
        with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
            await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
            mock_llm.assert_awaited_once()
            mock_followup.assert_called_once_with("Test response from AI")


@pytest.mark.asyncio
async def test_senator_command_empty_choices(ai_cog, mock_channel, mock_guild, bot):
    ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)

    with patch('cogs.ai.llm_completion', new_callable=AsyncMock, return_value=None) as mock_llm:
        with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
            await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
            mock_llm.assert_awaited_once()
            mock_followup.assert_called_once_with("bot siem zesroł")


@pytest.mark.asyncio
async def test_senator_command_no_choices_key(ai_cog, mock_channel, mock_guild, bot):
    ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)

    with patch('cogs.ai.llm_completion', new_callable=AsyncMock, return_value=None) as mock_llm:
        with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
            await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
            mock_llm.assert_awaited_once()
            mock_followup.assert_called_once_with("bot siem zesroł")