aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_ai.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-04-18 16:24:42 +0200
committersalmonik <raisersoft@proton.me>2026-04-18 16:24:42 +0200
commit857a7364ddb9b10529593c5e9c3578eb95c1da9b (patch)
treecc160ed8685039fcb08663226395fb97d78fcea6 /tests/cogs/test_ai.py
parentadd support for x^2+y^2=0,4 and alike (diff)
downloadsenator-sperma-857a7364ddb9b10529593c5e9c3578eb95c1da9b.tar.gz
senator-sperma-857a7364ddb9b10529593c5e9c3578eb95c1da9b.zip
add a test suite
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to 'tests/cogs/test_ai.py')
-rw-r--r--tests/cogs/test_ai.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/cogs/test_ai.py b/tests/cogs/test_ai.py
new file mode 100644
index 0000000..bd8f813
--- /dev/null
+++ b/tests/cogs/test_ai.py
@@ -0,0 +1,69 @@
1import pytest
2from unittest.mock import AsyncMock, patch, MagicMock
3import discord
4from tests.conftest import MockApplicationContext
5
6
7@pytest.fixture
8def ai_cog(bot):
9 from cogs.ai import AI
10 cog = AI(bot)
11 return cog
12
13
14@pytest.fixture
15def mock_ai_response():
16 return {
17 "choices": [
18 {
19 "message": {
20 "content": "Test response from AI"
21 }
22 }
23 ]
24 }
25
26
27@pytest.mark.asyncio
28async def test_senator_command_success(ai_cog, mock_channel, mock_guild, bot, mock_ai_response):
29 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
30
31 mock_response = MagicMock()
32 mock_response.json = MagicMock(return_value=mock_ai_response)
33 mock_response.status_code = 200
34
35 with patch('cogs.ai.requests.post', return_value=mock_response):
36 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
37 await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
38 mock_followup.assert_called_once_with("Test response from AI")
39
40
41@pytest.mark.asyncio
42async def test_senator_command_empty_choices(ai_cog, mock_channel, mock_guild, bot):
43 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
44
45 mock_response = MagicMock()
46 mock_response.json = MagicMock(return_value={"choices": []})
47 mock_response.status_code = 200
48
49 with patch('cogs.ai.requests.post', return_value=mock_response):
50 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
51 await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
52 mock_followup.assert_called_once_with("bot siem zesroĊ‚")
53
54
55@pytest.mark.asyncio
56async def test_senator_command_no_choices_key(ai_cog, mock_channel, mock_guild, bot):
57 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
58
59 mock_response = MagicMock()
60 mock_response.json = MagicMock(return_value={})
61 mock_response.status_code = 200
62
63 with patch('cogs.ai.requests.post', return_value=mock_response):
64 with patch('cogs.ai.logger') as mock_logger:
65 try:
66 await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
67 except KeyError:
68 pass
69 assert mock_logger.info.called \ No newline at end of file