diff options
| author | salmonik <raisersoft@proton.me> | 2026-07-08 02:13:35 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-07-08 02:13:35 +0200 |
| commit | cd8ed8bc5793985df2c1692072a932ceee517b95 (patch) | |
| tree | 42d18a4140259b5c68b4dd05b7fcb398f78b8d7f /tests/cogs/test_ai.py | |
| parent | Merge pull request 'Voice related fixes, alongside simplifying assistant' (#5... (diff) | |
| download | senator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.tar.gz senator-sperma-cd8ed8bc5793985df2c1692072a932ceee517b95.zip | |
OPEN THE RUST GATES
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to '')
| -rw-r--r-- | tests/cogs/test_ai.py | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/tests/cogs/test_ai.py b/tests/cogs/test_ai.py deleted file mode 100644 index 6d92f55..0000000 --- a/tests/cogs/test_ai.py +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | import pytest | ||
| 2 | from unittest.mock import AsyncMock, patch, MagicMock | ||
| 3 | import discord | ||
| 4 | import httpx | ||
| 5 | from conftest import MockApplicationContext | ||
| 6 | |||
| 7 | |||
| 8 | @pytest.fixture | ||
| 9 | def ai_cog(bot): | ||
| 10 | from cogs.ai import AI | ||
| 11 | cog = AI(bot) | ||
| 12 | return cog | ||
| 13 | |||
| 14 | |||
| 15 | @pytest.fixture | ||
| 16 | def mock_ai_response(): | ||
| 17 | return { | ||
| 18 | "choices": [ | ||
| 19 | { | ||
| 20 | "message": { | ||
| 21 | "content": "Test response from AI" | ||
| 22 | } | ||
| 23 | } | ||
| 24 | ] | ||
| 25 | } | ||
| 26 | |||
| 27 | |||
| 28 | @pytest.mark.asyncio | ||
| 29 | async def test_senator_command_success(ai_cog, mock_channel, mock_guild, bot, mock_ai_response): | ||
| 30 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 31 | |||
| 32 | mock_response = MagicMock() | ||
| 33 | mock_response.json = MagicMock(return_value=mock_ai_response) | ||
| 34 | |||
| 35 | mock_client = MagicMock() | ||
| 36 | mock_client.post = AsyncMock(return_value=mock_response) | ||
| 37 | mock_client.__aenter__ = AsyncMock(return_value=mock_response) | ||
| 38 | mock_client.__aexit__ = AsyncMock(return_value=None) | ||
| 39 | |||
| 40 | with patch('cogs.ai.httpx.AsyncClient') as mock_httpx: | ||
| 41 | instance = mock_httpx.return_value.__aenter__.return_value | ||
| 42 | instance.post = AsyncMock(return_value=mock_response) | ||
| 43 | with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: | ||
| 44 | await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False) | ||
| 45 | mock_followup.assert_called_once_with("Test response from AI") | ||
| 46 | |||
| 47 | |||
| 48 | @pytest.mark.asyncio | ||
| 49 | async def test_senator_command_empty_choices(ai_cog, mock_channel, mock_guild, bot): | ||
| 50 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 51 | |||
| 52 | mock_response = MagicMock() | ||
| 53 | mock_response.json = MagicMock(return_value={"choices": []}) | ||
| 54 | |||
| 55 | mock_client = MagicMock() | ||
| 56 | mock_client.post = AsyncMock(return_value=mock_response) | ||
| 57 | mock_client.__aenter__ = AsyncMock(return_value=mock_response) | ||
| 58 | mock_client.__aexit__ = AsyncMock(return_value=None) | ||
| 59 | |||
| 60 | with patch('cogs.ai.httpx.AsyncClient') as mock_httpx: | ||
| 61 | instance = mock_httpx.return_value.__aenter__.return_value | ||
| 62 | instance.post = AsyncMock(return_value=mock_response) | ||
| 63 | with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: | ||
| 64 | await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False) | ||
| 65 | mock_followup.assert_called_once_with("bot siem zesroĊ") | ||
| 66 | |||
| 67 | |||
| 68 | @pytest.mark.asyncio | ||
| 69 | async def test_senator_command_no_choices_key(ai_cog, mock_channel, mock_guild, bot): | ||
| 70 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 71 | |||
| 72 | mock_response = MagicMock() | ||
| 73 | mock_response.json = MagicMock(return_value={}) | ||
| 74 | |||
| 75 | with patch('cogs.ai.httpx.AsyncClient') as mock_httpx: | ||
| 76 | instance = mock_httpx.return_value.__aenter__.return_value | ||
| 77 | instance.post = AsyncMock(return_value=mock_response) | ||
| 78 | with patch('cogs.ai.logger') as mock_logger: | ||
| 79 | try: | ||
| 80 | await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False) | ||
| 81 | except KeyError: | ||
| 82 | pass | ||
| 83 | assert mock_logger.info.called | ||
