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ł")