aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-04-19 15:44:33 +0200
committersalmonik <raisersoft@proton.me>2026-04-19 15:44:33 +0200
commitb343381fea3eab26e334a1b3bba202d715f9ea2e (patch)
tree792210018d1e11ac3b160edfe29cf878eb4e3f56 /tests/cogs
parentchore: add pycord dependency, update main (diff)
downloadsenator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.tar.gz
senator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.zip
test: improve test assertions and edge cases
Diffstat (limited to '')
-rw-r--r--tests/cogs/test_ai.py40
-rw-r--r--tests/cogs/test_assistant.py20
-rw-r--r--tests/cogs/test_compression_conversion.py26
-rw-r--r--tests/cogs/test_downloader.py18
-rw-r--r--tests/cogs/test_math_commands.py12
-rw-r--r--tests/cogs/test_music_audio.py36
-rw-r--r--tests/cogs/test_music_join.py14
-rw-r--r--tests/cogs/test_music_play.py20
-rw-r--r--tests/cogs/test_plot.py85
-rw-r--r--tests/cogs/test_qr.py14
-rw-r--r--tests/cogs/test_say.py8
-rw-r--r--tests/cogs/test_search.py20
-rw-r--r--tests/cogs/test_trigger.py22
-rw-r--r--tests/cogs/test_tts.py14
-rw-r--r--tests/cogs/test_vclogs.py20
-rw-r--r--tests/cogs/test_voice.py32
-rw-r--r--tests/cogs/test_web.py14
17 files changed, 172 insertions, 243 deletions
diff --git a/tests/cogs/test_ai.py b/tests/cogs/test_ai.py
index bd8f813..a1c3fd4 100644
--- a/tests/cogs/test_ai.py
+++ b/tests/cogs/test_ai.py
@@ -1,6 +1,7 @@
1import pytest 1import pytest
2from unittest.mock import AsyncMock, patch, MagicMock 2from unittest.mock import AsyncMock, patch, MagicMock
3import discord 3import discord
4import httpx
4from tests.conftest import MockApplicationContext 5from tests.conftest import MockApplicationContext
5 6
6 7
@@ -27,12 +28,18 @@ def mock_ai_response():
27@pytest.mark.asyncio 28@pytest.mark.asyncio
28async def test_senator_command_success(ai_cog, mock_channel, mock_guild, bot, mock_ai_response): 29async 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 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
30 31
31 mock_response = MagicMock() 32 mock_response = MagicMock()
32 mock_response.json = MagicMock(return_value=mock_ai_response) 33 mock_response.json = MagicMock(return_value=mock_ai_response)
33 mock_response.status_code = 200 34
34 35 mock_client = MagicMock()
35 with patch('cogs.ai.requests.post', return_value=mock_response): 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)
36 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: 43 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) 44 await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
38 mock_followup.assert_called_once_with("Test response from AI") 45 mock_followup.assert_called_once_with("Test response from AI")
@@ -41,12 +48,18 @@ async def test_senator_command_success(ai_cog, mock_channel, mock_guild, bot, mo
41@pytest.mark.asyncio 48@pytest.mark.asyncio
42async def test_senator_command_empty_choices(ai_cog, mock_channel, mock_guild, bot): 49async def test_senator_command_empty_choices(ai_cog, mock_channel, mock_guild, bot):
43 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 50 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
44 51
45 mock_response = MagicMock() 52 mock_response = MagicMock()
46 mock_response.json = MagicMock(return_value={"choices": []}) 53 mock_response.json = MagicMock(return_value={"choices": []})
47 mock_response.status_code = 200 54
48 55 mock_client = MagicMock()
49 with patch('cogs.ai.requests.post', return_value=mock_response): 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)
50 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: 63 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) 64 await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
52 mock_followup.assert_called_once_with("bot siem zesroł") 65 mock_followup.assert_called_once_with("bot siem zesroł")
@@ -55,15 +68,16 @@ async def test_senator_command_empty_choices(ai_cog, mock_channel, mock_guild, b
55@pytest.mark.asyncio 68@pytest.mark.asyncio
56async def test_senator_command_no_choices_key(ai_cog, mock_channel, mock_guild, bot): 69async 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) 70 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
58 71
59 mock_response = MagicMock() 72 mock_response = MagicMock()
60 mock_response.json = MagicMock(return_value={}) 73 mock_response.json = MagicMock(return_value={})
61 mock_response.status_code = 200 74
62 75 with patch('cogs.ai.httpx.AsyncClient') as mock_httpx:
63 with patch('cogs.ai.requests.post', return_value=mock_response): 76 instance = mock_httpx.return_value.__aenter__.return_value
77 instance.post = AsyncMock(return_value=mock_response)
64 with patch('cogs.ai.logger') as mock_logger: 78 with patch('cogs.ai.logger') as mock_logger:
65 try: 79 try:
66 await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False) 80 await ai_cog.senator.callback(ai_cog, ctx, text="Hello", tts=False)
67 except KeyError: 81 except KeyError:
68 pass 82 pass
69 assert mock_logger.info.called \ No newline at end of file 83 assert mock_logger.info.called
diff --git a/tests/cogs/test_assistant.py b/tests/cogs/test_assistant.py
index 09c3934..9a33232 100644
--- a/tests/cogs/test_assistant.py
+++ b/tests/cogs/test_assistant.py
@@ -7,11 +7,11 @@ from tests.conftest import MockApplicationContext
7def assistant_cog(): 7def assistant_cog():
8 with patch('os.getenv', return_value="test_keyword"): 8 with patch('os.getenv', return_value="test_keyword"):
9 from cogs.assistant import Jarvis 9 from cogs.assistant import Jarvis
10 10
11 mock_bot = MagicMock() 11 mock_bot = MagicMock()
12 mock_bot.user = MagicMock() 12 mock_bot.user = MagicMock()
13 mock_bot.user.id = 111 13 mock_bot.user.id = 111
14 14
15 cog = Jarvis(mock_bot) 15 cog = Jarvis(mock_bot)
16 return cog 16 return cog
17 17
@@ -25,10 +25,10 @@ async def test_assistant_on_message_ignored_bot_message(assistant_cog):
25 mock_author = MagicMock() 25 mock_author = MagicMock()
26 mock_author.id = 456 26 mock_author.id = 456
27 mock_author.bot = True 27 mock_author.bot = True
28 28
29 mock_message = MagicMock() 29 mock_message = MagicMock()
30 mock_message.author = mock_author 30 mock_message.author = mock_author
31 31
32 with patch.object(assistant_cog, 'assistant', new_callable=AsyncMock) as mock_assistant: 32 with patch.object(assistant_cog, 'assistant', new_callable=AsyncMock) as mock_assistant:
33 await assistant_cog.on_message(mock_message) 33 await assistant_cog.on_message(mock_message)
34 mock_assistant.assert_not_called() 34 mock_assistant.assert_not_called()
@@ -39,12 +39,12 @@ async def test_assistant_on_message_mentions_bot(assistant_cog):
39 mock_message = MagicMock() 39 mock_message = MagicMock()
40 mock_message.author = MagicMock() 40 mock_message.author = MagicMock()
41 mock_message.author.id = 123 41 mock_message.author.id = 123
42 42
43 mock_mention = MagicMock() 43 mock_mention = MagicMock()
44 mock_mention.id = 111 44 mock_mention.id = 111
45 mock_message.mentions = [mock_mention] 45 mock_message.mentions = [mock_mention]
46 mock_message.content = "test" 46 mock_message.content = "test"
47 47
48 with patch.object(assistant_cog, 'assistant', new_callable=AsyncMock) as mock_assistant: 48 with patch.object(assistant_cog, 'assistant', new_callable=AsyncMock) as mock_assistant:
49 await assistant_cog.on_message(mock_message) 49 await assistant_cog.on_message(mock_message)
50 mock_assistant.assert_called_once_with(mock_message) 50 mock_assistant.assert_called_once_with(mock_message)
@@ -53,14 +53,14 @@ async def test_assistant_on_message_mentions_bot(assistant_cog):
53@pytest.mark.asyncio 53@pytest.mark.asyncio
54async def test_assistant_on_message_keyword_match(assistant_cog): 54async def test_assistant_on_message_keyword_match(assistant_cog):
55 assistant_cog.keyword = "test" 55 assistant_cog.keyword = "test"
56 56
57 mock_message = MagicMock() 57 mock_message = MagicMock()
58 mock_message.author = MagicMock() 58 mock_message.author = MagicMock()
59 mock_message.author.id = 123 59 mock_message.author.id = 123
60 60
61 mock_message.mentions = [] 61 mock_message.mentions = []
62 mock_message.content = "test message with test keyword" 62 mock_message.content = "test message with test keyword"
63 63
64 with patch.object(assistant_cog, 'assistant', new_callable=AsyncMock) as mock_assistant: 64 with patch.object(assistant_cog, 'assistant', new_callable=AsyncMock) as mock_assistant:
65 await assistant_cog.on_message(mock_message) 65 await assistant_cog.on_message(mock_message)
66 mock_assistant.assert_called_once_with(mock_message) \ No newline at end of file 66 mock_assistant.assert_called_once_with(mock_message)
diff --git a/tests/cogs/test_compression_conversion.py b/tests/cogs/test_compression_conversion.py
index f9f74ad..f9d3427 100644
--- a/tests/cogs/test_compression_conversion.py
+++ b/tests/cogs/test_compression_conversion.py
@@ -40,11 +40,11 @@ async def test_build_conversion_command_video():
40 import cogs.conversion 40 import cogs.conversion
41 importlib.reload(cogs.conversion) 41 importlib.reload(cogs.conversion)
42 from cogs.conversion import Conversion 42 from cogs.conversion import Conversion
43 43
44 cog = Conversion.__new__(Conversion) 44 cog = Conversion.__new__(Conversion)
45 cog._baseurl = "https://example.com" 45 cog._baseurl = "https://example.com"
46 cog._uploadurl = "https://example.com" 46 cog._uploadurl = "https://example.com"
47 47
48 cmd = cog._build_conversion_command("Video", "/tmp/test.mp4", "/tmp/output.mp4", "") 48 cmd = cog._build_conversion_command("Video", "/tmp/test.mp4", "/tmp/output.mp4", "")
49 assert cmd is not None 49 assert cmd is not None
50 assert "ffmpeg" in cmd 50 assert "ffmpeg" in cmd
@@ -59,11 +59,11 @@ async def test_build_conversion_command_image():
59 import cogs.conversion 59 import cogs.conversion
60 importlib.reload(cogs.conversion) 60 importlib.reload(cogs.conversion)
61 from cogs.conversion import Conversion 61 from cogs.conversion import Conversion
62 62
63 cog = Conversion.__new__(Conversion) 63 cog = Conversion.__new__(Conversion)
64 cog._baseurl = "https://example.com" 64 cog._baseurl = "https://example.com"
65 cog._uploadurl = "https://example.com" 65 cog._uploadurl = "https://example.com"
66 66
67 cmd = cog._build_conversion_command("Image", "/tmp/test.jpg", "/tmp/output.png", "") 67 cmd = cog._build_conversion_command("Image", "/tmp/test.jpg", "/tmp/output.png", "")
68 assert cmd is not None 68 assert cmd is not None
69 assert "magick" in cmd 69 assert "magick" in cmd
@@ -78,11 +78,11 @@ async def test_build_conversion_command_unknown():
78 import cogs.conversion 78 import cogs.conversion
79 importlib.reload(cogs.conversion) 79 importlib.reload(cogs.conversion)
80 from cogs.conversion import Conversion 80 from cogs.conversion import Conversion
81 81
82 cog = Conversion.__new__(Conversion) 82 cog = Conversion.__new__(Conversion)
83 cog._baseurl = "https://example.com" 83 cog._baseurl = "https://example.com"
84 cog._uploadurl = "https://example.com" 84 cog._uploadurl = "https://example.com"
85 85
86 cmd = cog._build_conversion_command("Unknown", "/tmp/test.xyz", "/tmp/output.abc", "") 86 cmd = cog._build_conversion_command("Unknown", "/tmp/test.xyz", "/tmp/output.abc", "")
87 assert cmd is None 87 assert cmd is None
88 88
@@ -96,10 +96,10 @@ async def test_compression_get_command_video():
96 import cogs.compression 96 import cogs.compression
97 importlib.reload(cogs.compression) 97 importlib.reload(cogs.compression)
98 from cogs.compression import Compression 98 from cogs.compression import Compression
99 99
100 cog = Compression.__new__(Compression) 100 cog = Compression.__new__(Compression)
101 cog.temp_dir = "/tmp" 101 cog.temp_dir = "/tmp"
102 102
103 cmd = cog._get_compression_command("Video", "/tmp/test.mp4", "/tmp/output.mp4") 103 cmd = cog._get_compression_command("Video", "/tmp/test.mp4", "/tmp/output.mp4")
104 assert cmd is not None 104 assert cmd is not None
105 assert "ffmpeg" in cmd 105 assert "ffmpeg" in cmd
@@ -114,10 +114,10 @@ async def test_compression_get_command_image():
114 import cogs.compression 114 import cogs.compression
115 importlib.reload(cogs.compression) 115 importlib.reload(cogs.compression)
116 from cogs.compression import Compression 116 from cogs.compression import Compression
117 117
118 cog = Compression.__new__(Compression) 118 cog = Compression.__new__(Compression)
119 cog.temp_dir = "/tmp" 119 cog.temp_dir = "/tmp"
120 120
121 cmd = cog._get_compression_command("Image", "/tmp/test.jpg", "/tmp/output.jpg") 121 cmd = cog._get_compression_command("Image", "/tmp/test.jpg", "/tmp/output.jpg")
122 assert cmd is not None 122 assert cmd is not None
123 123
@@ -131,9 +131,9 @@ async def test_compression_get_command_unknown():
131 import cogs.compression 131 import cogs.compression
132 importlib.reload(cogs.compression) 132 importlib.reload(cogs.compression)
133 from cogs.compression import Compression 133 from cogs.compression import Compression
134 134
135 cog = Compression.__new__(Compression) 135 cog = Compression.__new__(Compression)
136 cog.temp_dir = "/tmp" 136 cog.temp_dir = "/tmp"
137 137
138 cmd = cog._get_compression_command("Unknown", "/tmp/test.xyz", "/tmp/output.xyz") 138 cmd = cog._get_compression_command("Unknown", "/tmp/test.xyz", "/tmp/output.xyz")
139 assert cmd is None \ No newline at end of file 139 assert cmd is None
diff --git a/tests/cogs/test_downloader.py b/tests/cogs/test_downloader.py
index 91eef93..6ac8ae7 100644
--- a/tests/cogs/test_downloader.py
+++ b/tests/cogs/test_downloader.py
@@ -14,9 +14,9 @@ def downloader_cog(bot):
14@pytest.mark.asyncio 14@pytest.mark.asyncio
15async def test_download_command_success_file(downloader_cog, mock_channel, mock_guild, bot): 15async def test_download_command_success_file(downloader_cog, mock_channel, mock_guild, bot):
16 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 16 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
17 17
18 mock_file_path = "/tmp/test_video.mp4" 18 mock_file_path = "/tmp/test_video.mp4"
19 19
20 with patch('cogs.downloader.Downloader.download_standalone', return_value={ 20 with patch('cogs.downloader.Downloader.download_standalone', return_value={
21 "status": "success", 21 "status": "success",
22 "type": "file", 22 "type": "file",
@@ -34,7 +34,7 @@ async def test_download_command_success_file(downloader_cog, mock_channel, mock_
34@pytest.mark.asyncio 34@pytest.mark.asyncio
35async def test_download_command_success_url(downloader_cog, mock_channel, mock_guild, bot): 35async def test_download_command_success_url(downloader_cog, mock_channel, mock_guild, bot):
36 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 36 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
37 37
38 with patch('cogs.downloader.Downloader.download_standalone', return_value={ 38 with patch('cogs.downloader.Downloader.download_standalone', return_value={
39 "status": "success", 39 "status": "success",
40 "type": "url", 40 "type": "url",
@@ -50,7 +50,7 @@ async def test_download_command_success_url(downloader_cog, mock_channel, mock_g
50@pytest.mark.asyncio 50@pytest.mark.asyncio
51async def test_download_command_error(downloader_cog, mock_channel, mock_guild, bot): 51async def test_download_command_error(downloader_cog, mock_channel, mock_guild, bot):
52 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 52 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
53 53
54 with patch('cogs.downloader.Downloader.download_standalone', return_value={ 54 with patch('cogs.downloader.Downloader.download_standalone', return_value={
55 "status": "error", 55 "status": "error",
56 "type": "error", 56 "type": "error",
@@ -65,10 +65,10 @@ async def test_download_command_error(downloader_cog, mock_channel, mock_guild,
65@pytest.mark.asyncio 65@pytest.mark.asyncio
66async def test_message_download_with_url(downloader_cog, mock_channel, mock_guild, bot, mock_user): 66async def test_message_download_with_url(downloader_cog, mock_channel, mock_guild, bot, mock_user):
67 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 67 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
68 68
69 mock_message = MagicMock() 69 mock_message = MagicMock()
70 mock_message.content = "Check this out https://example.com/video" 70 mock_message.content = "Check this out https://example.com/video"
71 71
72 with patch('cogs.downloader.Downloader.download_standalone', return_value={ 72 with patch('cogs.downloader.Downloader.download_standalone', return_value={
73 "status": "success", 73 "status": "success",
74 "type": "file", 74 "type": "file",
@@ -82,12 +82,12 @@ async def test_message_download_with_url(downloader_cog, mock_channel, mock_guil
82@pytest.mark.asyncio 82@pytest.mark.asyncio
83async def test_message_download_no_url(downloader_cog, mock_channel, mock_guild, bot): 83async def test_message_download_no_url(downloader_cog, mock_channel, mock_guild, bot):
84 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 84 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
85 85
86 mock_message = MagicMock() 86 mock_message = MagicMock()
87 mock_message.content = "No URL here" 87 mock_message.content = "No URL here"
88 88
89 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 89 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
90 await downloader_cog.message_download.callback(downloader_cog, ctx, message=mock_message) 90 await downloader_cog.message_download.callback(downloader_cog, ctx, message=mock_message)
91 mock_respond.assert_called_once() 91 mock_respond.assert_called_once()
92 call_args = mock_respond.call_args 92 call_args = mock_respond.call_args
93 assert "Brak" in str(call_args) \ No newline at end of file 93 assert "Brak" in str(call_args)
diff --git a/tests/cogs/test_math_commands.py b/tests/cogs/test_math_commands.py
index 0acac4a..5c78027 100644
--- a/tests/cogs/test_math_commands.py
+++ b/tests/cogs/test_math_commands.py
@@ -13,11 +13,11 @@ def math_cog(bot):
13@pytest.mark.asyncio 13@pytest.mark.asyncio
14async def test_math_command_valid_expression(math_cog, mock_channel, mock_guild, bot): 14async def test_math_command_valid_expression(math_cog, mock_channel, mock_guild, bot):
15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
16 16
17 mock_process = MagicMock() 17 mock_process = MagicMock()
18 mock_process.returncode = 0 18 mock_process.returncode = 0
19 mock_process.communicate = AsyncMock(return_value=(b"4", b"")) 19 mock_process.communicate = AsyncMock(return_value=(b"4", b""))
20 20
21 with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process) as mock_subprocess: 21 with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process) as mock_subprocess:
22 with patch('cogs.math_commands.re.search', return_value=None): 22 with patch('cogs.math_commands.re.search', return_value=None):
23 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 23 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
@@ -29,7 +29,7 @@ async def test_math_command_valid_expression(math_cog, mock_channel, mock_guild,
29@pytest.mark.asyncio 29@pytest.mark.asyncio
30async def test_math_command_invalid_expression(math_cog, mock_channel, mock_guild, bot): 30async def test_math_command_invalid_expression(math_cog, mock_channel, mock_guild, bot):
31 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 31 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
32 32
33 with patch('cogs.math_commands.re.search', return_value=MagicMock()): 33 with patch('cogs.math_commands.re.search', return_value=MagicMock()):
34 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 34 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
35 await math_cog.math.callback(math_cog, ctx, equation="eval(1)") 35 await math_cog.math.callback(math_cog, ctx, equation="eval(1)")
@@ -41,15 +41,15 @@ async def test_math_command_invalid_expression(math_cog, mock_channel, mock_guil
41@pytest.mark.asyncio 41@pytest.mark.asyncio
42async def test_math_command_process_error(math_cog, mock_channel, mock_guild, bot): 42async def test_math_command_process_error(math_cog, mock_channel, mock_guild, bot):
43 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 43 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
44 44
45 mock_process = MagicMock() 45 mock_process = MagicMock()
46 mock_process.returncode = 1 46 mock_process.returncode = 1
47 mock_process.communicate = AsyncMock(return_value=(b"", b"Error: invalid expression")) 47 mock_process.communicate = AsyncMock(return_value=(b"", b"Error: invalid expression"))
48 48
49 with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process): 49 with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process):
50 with patch('cogs.math_commands.re.search', return_value=None): 50 with patch('cogs.math_commands.re.search', return_value=None):
51 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 51 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
52 await math_cog.math.callback(math_cog, ctx, equation="2++") 52 await math_cog.math.callback(math_cog, ctx, equation="2++")
53 mock_respond.assert_called_once() 53 mock_respond.assert_called_once()
54 args = mock_respond.call_args 54 args = mock_respond.call_args
55 assert "error" in str(args).lower() or "Error" in str(args) \ No newline at end of file 55 assert "error" in str(args).lower() or "Error" in str(args)
diff --git a/tests/cogs/test_music_audio.py b/tests/cogs/test_music_audio.py
index b53cf95..7ea902e 100644
--- a/tests/cogs/test_music_audio.py
+++ b/tests/cogs/test_music_audio.py
@@ -7,13 +7,13 @@ from tests.conftest import MockApplicationContext
7@pytest.mark.asyncio 7@pytest.mark.asyncio
8async def test_validate_voice_channel_not_in_voice(): 8async def test_validate_voice_channel_not_in_voice():
9 from cogs.music.audio_playback import AudioPlaybackManager 9 from cogs.music.audio_playback import AudioPlaybackManager
10 10
11 mock_ctx = MagicMock() 11 mock_ctx = MagicMock()
12 mock_ctx.author.voice = None 12 mock_ctx.author.voice = None
13 mock_ctx.respond = AsyncMock() 13 mock_ctx.respond = AsyncMock()
14 14
15 result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) 15 result = await AudioPlaybackManager.validate_voice_channel(mock_ctx)
16 16
17 assert result is None 17 assert result is None
18 mock_ctx.respond.assert_called_once() 18 mock_ctx.respond.assert_called_once()
19 19
@@ -21,24 +21,24 @@ async def test_validate_voice_channel_not_in_voice():
21@pytest.mark.asyncio 21@pytest.mark.asyncio
22async def test_validate_voice_channel_in_voice(): 22async def test_validate_voice_channel_in_voice():
23 from cogs.music.audio_playback import AudioPlaybackManager 23 from cogs.music.audio_playback import AudioPlaybackManager
24 24
25 mock_channel = MagicMock() 25 mock_channel = MagicMock()
26 mock_ctx = MagicMock() 26 mock_ctx = MagicMock()
27 mock_ctx.author.voice = MagicMock() 27 mock_ctx.author.voice = MagicMock()
28 mock_ctx.author.voice.channel = mock_channel 28 mock_ctx.author.voice.channel = mock_channel
29 mock_ctx.respond = AsyncMock() 29 mock_ctx.respond = AsyncMock()
30 30
31 result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) 31 result = await AudioPlaybackManager.validate_voice_channel(mock_ctx)
32 32
33 assert result == mock_channel 33 assert result == mock_channel
34 34
35 35
36@pytest.mark.asyncio 36@pytest.mark.asyncio
37async def test_prepare_file_source_file_not_found(): 37async def test_prepare_file_source_file_not_found():
38 from cogs.music.audio_playback import AudioPlaybackManager 38 from cogs.music.audio_playback import AudioPlaybackManager
39 39
40 display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3") 40 display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3")
41 41
42 assert display_name is None 42 assert display_name is None
43 assert absolute_path is None 43 assert absolute_path is None
44 44
@@ -46,11 +46,11 @@ async def test_prepare_file_source_file_not_found():
46@pytest.mark.asyncio 46@pytest.mark.asyncio
47async def test_prepare_file_source_absolute_path(): 47async def test_prepare_file_source_absolute_path():
48 from cogs.music.audio_playback import AudioPlaybackManager 48 from cogs.music.audio_playback import AudioPlaybackManager
49 49
50 with patch('os.path.exists', return_value=True): 50 with patch('os.path.exists', return_value=True):
51 with patch('os.path.isabs', return_value=True): 51 with patch('os.path.isabs', return_value=True):
52 display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/tmp/test.mp3") 52 display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/tmp/test.mp3")
53 53
54 assert display_name == "test" 54 assert display_name == "test"
55 assert absolute_path == "/tmp/test.mp3" 55 assert absolute_path == "/tmp/test.mp3"
56 56
@@ -58,9 +58,9 @@ async def test_prepare_file_source_absolute_path():
58@pytest.mark.asyncio 58@pytest.mark.asyncio
59async def test_prepare_source_url(): 59async def test_prepare_source_url():
60 from cogs.music.audio_playback import AudioPlaybackManager 60 from cogs.music.audio_playback import AudioPlaybackManager
61 61
62 source, display_name, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "https://example.com/stream") 62 source, _, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "https://example.com/stream")
63 63
64 assert is_url == True 64 assert is_url == True
65 assert source == "https://example.com/stream" 65 assert source == "https://example.com/stream"
66 66
@@ -68,10 +68,10 @@ async def test_prepare_source_url():
68@pytest.mark.asyncio 68@pytest.mark.asyncio
69async def test_prepare_source_local_file(): 69async def test_prepare_source_local_file():
70 from cogs.music.audio_playback import AudioPlaybackManager 70 from cogs.music.audio_playback import AudioPlaybackManager
71 71
72 with patch('os.path.exists', return_value=True): 72 with patch('os.path.exists', return_value=True):
73 source, display_name, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "/tmp/test.mp3") 73 source, display_name, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "/tmp/test.mp3")
74 74
75 assert is_url == False 75 assert is_url == False
76 assert display_name == "test" 76 assert display_name == "test"
77 77
@@ -79,7 +79,7 @@ async def test_prepare_source_local_file():
79@pytest.mark.asyncio 79@pytest.mark.asyncio
80async def test_cleanup_temp_file(): 80async def test_cleanup_temp_file():
81 from cogs.music.audio_playback import AudioPlaybackManager 81 from cogs.music.audio_playback import AudioPlaybackManager
82 82
83 with patch('os.path.exists', return_value=True): 83 with patch('os.path.exists', return_value=True):
84 with patch('os.remove'): 84 with patch('os.remove'):
85 await AudioPlaybackManager.cleanup_temp_file("/tmp/test.mp3") 85 await AudioPlaybackManager.cleanup_temp_file("/tmp/test.mp3")
@@ -88,6 +88,6 @@ async def test_cleanup_temp_file():
88@pytest.mark.asyncio 88@pytest.mark.asyncio
89async def test_cleanup_temp_file_not_exists(): 89async def test_cleanup_temp_file_not_exists():
90 from cogs.music.audio_playback import AudioPlaybackManager 90 from cogs.music.audio_playback import AudioPlaybackManager
91 91
92 with patch('os.path.exists', return_value=False): 92 with patch('os.path.exists', return_value=False):
93 await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") \ No newline at end of file 93 await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3")
diff --git a/tests/cogs/test_music_join.py b/tests/cogs/test_music_join.py
index 5fc66f6..3c7ca6e 100644
--- a/tests/cogs/test_music_join.py
+++ b/tests/cogs/test_music_join.py
@@ -22,14 +22,14 @@ async def test_join_command_success(join_cog, mock_channel, mock_guild, bot, moc
22 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 22 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
23 ctx.user = mock_user 23 ctx.user = mock_user
24 ctx.author = mock_user 24 ctx.author = mock_user
25 25
26 mock_voice_channel = MagicMock() 26 mock_voice_channel = MagicMock()
27 mock_voice = MagicMock() 27 mock_voice = MagicMock()
28 mock_voice_channel.connect = AsyncMock(return_value=mock_voice) 28 mock_voice_channel.connect = AsyncMock(return_value=mock_voice)
29 29
30 ctx.author.voice = MagicMock() 30 ctx.author.voice = MagicMock()
31 ctx.author.voice.channel = mock_voice_channel 31 ctx.author.voice.channel = mock_voice_channel
32 32
33 with patch.object(mock_voice_channel, 'connect', new_callable=AsyncMock, return_value=mock_voice): 33 with patch.object(mock_voice_channel, 'connect', new_callable=AsyncMock, return_value=mock_voice):
34 with patch.object(ctx, 'respond', new_callable=AsyncMock): 34 with patch.object(ctx, 'respond', new_callable=AsyncMock):
35 with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): 35 with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock):
@@ -41,13 +41,13 @@ async def test_stop_command_success(stop_cog, mock_channel, mock_guild, bot, moc
41 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 41 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
42 ctx.user = mock_user 42 ctx.user = mock_user
43 ctx.author = mock_user 43 ctx.author = mock_user
44 44
45 mock_voice_client = MagicMock() 45 mock_voice_client = MagicMock()
46 mock_voice_client.disconnect = AsyncMock() 46 mock_voice_client.disconnect = AsyncMock()
47 ctx.voice_client = mock_voice_client 47 ctx.voice_client = mock_voice_client
48 48
49 with patch.object(ctx, 'respond', new_callable=AsyncMock): 49 with patch.object(ctx, 'respond', new_callable=AsyncMock):
50 with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): 50 with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock):
51 await stop_cog.stop.callback(stop_cog, ctx) 51 await stop_cog.stop.callback(stop_cog, ctx)
52 52
53 mock_voice_client.disconnect.assert_called_once() \ No newline at end of file 53 mock_voice_client.disconnect.assert_called_once()
diff --git a/tests/cogs/test_music_play.py b/tests/cogs/test_music_play.py
index abdd81c..e720c9a 100644
--- a/tests/cogs/test_music_play.py
+++ b/tests/cogs/test_music_play.py
@@ -22,7 +22,7 @@ def loop_cog(bot):
22@pytest.mark.asyncio 22@pytest.mark.asyncio
23async def test_create_search_embed_empty(play_commands_cog): 23async def test_create_search_embed_empty(play_commands_cog):
24 embed, view = await play_commands_cog._create_search_embed([]) 24 embed, view = await play_commands_cog._create_search_embed([])
25 25
26 assert embed.title == "Wyniki wyszukiwania" 26 assert embed.title == "Wyniki wyszukiwania"
27 assert len(view.children) == 0 27 assert len(view.children) == 0
28 28
@@ -33,9 +33,9 @@ async def test_create_search_embed_with_candidates(play_commands_cog):
33 "https://example.com/test1.mp3", 33 "https://example.com/test1.mp3",
34 "https://example.com/test2.mp3" 34 "https://example.com/test2.mp3"
35 ] 35 ]
36 36
37 embed, view = await play_commands_cog._create_search_embed(candidates) 37 embed, view = await play_commands_cog._create_search_embed(candidates)
38 38
39 assert embed.title == "Wyniki wyszukiwania" 39 assert embed.title == "Wyniki wyszukiwania"
40 assert len(embed.fields) == 2 40 assert len(embed.fields) == 2
41 41
@@ -43,7 +43,7 @@ async def test_create_search_embed_with_candidates(play_commands_cog):
43@pytest.mark.asyncio 43@pytest.mark.asyncio
44async def test_play_command_no_file_or_search(play_commands_cog, mock_channel, mock_guild, bot): 44async def test_play_command_no_file_or_search(play_commands_cog, mock_channel, mock_guild, bot):
45 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 45 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
46 46
47 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 47 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
48 await play_commands_cog.play.callback(play_commands_cog, ctx, melodia=None, file=None, compressed=False) 48 await play_commands_cog.play.callback(play_commands_cog, ctx, melodia=None, file=None, compressed=False)
49 mock_respond.assert_called_once() 49 mock_respond.assert_called_once()
@@ -54,10 +54,10 @@ async def test_play_command_no_file_or_search(play_commands_cog, mock_channel, m
54@pytest.mark.asyncio 54@pytest.mark.asyncio
55async def test_play_command_both_file_and_search(play_commands_cog, mock_channel, mock_guild, bot): 55async def test_play_command_both_file_and_search(play_commands_cog, mock_channel, mock_guild, bot):
56 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 56 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
57 57
58 mock_file = MagicMock() 58 mock_file = MagicMock()
59 mock_file.filename = "test.mp3" 59 mock_file.filename = "test.mp3"
60 60
61 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 61 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
62 await play_commands_cog.play.callback(play_commands_cog, ctx, melodia="test", file=mock_file, compressed=False) 62 await play_commands_cog.play.callback(play_commands_cog, ctx, melodia="test", file=mock_file, compressed=False)
63 mock_respond.assert_called_once() 63 mock_respond.assert_called_once()
@@ -80,7 +80,7 @@ async def test_loop_command_toggle_on(loop_cog, mock_channel, mock_guild, bot, m
80 ctx.user = mock_user 80 ctx.user = mock_user
81 ctx.author = mock_user 81 ctx.author = mock_user
82 ctx.guild.id = 123 82 ctx.guild.id = 123
83 83
84 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 84 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
85 await loop_cog.loop.callback(loop_cog, ctx) 85 await loop_cog.loop.callback(loop_cog, ctx)
86 mock_respond.assert_called_once() 86 mock_respond.assert_called_once()
@@ -94,11 +94,11 @@ async def test_loop_command_toggle_off(loop_cog, mock_channel, mock_guild, bot,
94 ctx.user = mock_user 94 ctx.user = mock_user
95 ctx.author = mock_user 95 ctx.author = mock_user
96 ctx.guild.id = 456 96 ctx.guild.id = 456
97 97
98 loop_cog.set_looping(456, True) 98 loop_cog.set_looping(456, True)
99 99
100 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 100 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
101 await loop_cog.loop.callback(loop_cog, ctx) 101 await loop_cog.loop.callback(loop_cog, ctx)
102 mock_respond.assert_called_once() 102 mock_respond.assert_called_once()
103 args = mock_respond.call_args 103 args = mock_respond.call_args
104 assert "wyłączony" in str(args) \ No newline at end of file 104 assert "wyłączony" in str(args)
diff --git a/tests/cogs/test_plot.py b/tests/cogs/test_plot.py
deleted file mode 100644
index e38a2c7..0000000
--- a/tests/cogs/test_plot.py
+++ /dev/null
@@ -1,85 +0,0 @@
1import pytest
2from unittest.mock import AsyncMock, patch, MagicMock
3import os
4from tests.conftest import MockApplicationContext
5
6
7def test_parse_expression():
8 from cogs.plot import parse_expression
9
10 assert parse_expression("x^2") == "x**2"
11 assert parse_expression("x!") == "factorial(x)"
12 assert parse_expression("2x") == "2*x"
13 assert parse_expression("x2") == "x*2"
14 assert parse_expression("sin(x)") == "sin(x)"
15
16
17def test_is_implicit():
18 from cogs.plot import is_implicit
19
20 assert is_implicit("x^2 + y^2 = 1") == True
21 assert is_implicit("x^2 = y") == True
22 assert is_implicit("x^2 + 1") == False
23
24
25def test_parse_implicit():
26 from cogs.plot import parse_implicit
27
28 lhs, rhs = parse_implicit("x^2 + y = 2")
29 assert "x**2" in lhs
30 assert "+ y" in lhs or "+y" in lhs
31 assert rhs == "2"
32
33
34@pytest.fixture
35def plot_cog(bot):
36 from cogs.plot import Plot
37 cog = Plot(bot)
38 return cog
39
40
41@pytest.mark.asyncio
42async def test_plot_command_not_available(plot_cog, mock_channel, mock_guild, bot):
43 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
44
45 with patch('cogs.plot._ensure_plot', return_value=False):
46 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
47 await plot_cog.plot.callback(plot_cog, ctx, funkcja="x^2")
48 mock_respond.assert_called_once()
49 args = mock_respond.call_args
50 assert "matplotlib" in str(args).lower() or "nie jest dostępne" in str(args)
51
52
53@pytest.mark.asyncio
54async def test_plot_command_success(plot_cog, mock_channel, mock_guild, bot):
55 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
56
57 with patch('cogs.plot._ensure_plot', return_value=True):
58 with patch('cogs.plot._plt_module') as mock_plt:
59 with patch('cogs.utils.temp.get_temp_dir', return_value="/tmp"):
60 with patch('os.path.exists', return_value=True):
61 with patch('os.unlink'):
62 with patch.object(ctx, 'followup', send=AsyncMock()) as mock_followup:
63 mock_fig = MagicMock()
64 mock_plt.subplots.return_value = (mock_fig, MagicMock())
65
66 await plot_cog.plot.callback(plot_cog, ctx, funkcja="x^2")
67 mock_followup.send.assert_called_once()
68
69
70@pytest.mark.asyncio
71async def test_plot_command_error_handling(plot_cog, mock_channel, mock_guild, bot):
72 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
73
74 with patch('cogs.plot._ensure_plot', return_value=True):
75 with patch('cogs.plot._plt_module') as mock_plt:
76 with patch('cogs.utils.temp.get_temp_dir', return_value="/tmp"):
77 with patch('os.path.exists', return_value=True):
78 with patch('os.unlink'):
79 with patch.object(ctx, 'followup', send=AsyncMock()) as mock_followup:
80 mock_plt.subplots.side_effect = ValueError("Test error")
81
82 await plot_cog.plot.callback(plot_cog, ctx, funkcja="invalid!!")
83 mock_followup.send.assert_called_once()
84 args = mock_followup.send.call_args
85 assert "Nie można" in str(args) or "Błąd" in str(args) \ No newline at end of file
diff --git a/tests/cogs/test_qr.py b/tests/cogs/test_qr.py
index f3688e3..2a132ca 100644
--- a/tests/cogs/test_qr.py
+++ b/tests/cogs/test_qr.py
@@ -23,7 +23,7 @@ def mock_temp_file():
23@pytest.mark.asyncio 23@pytest.mark.asyncio
24async def test_qr_generate_success(qr_cog, mock_channel, mock_guild, bot, mock_temp_file): 24async def test_qr_generate_success(qr_cog, mock_channel, mock_guild, bot, mock_temp_file):
25 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 25 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
26 26
27 with patch('cogs.qr.QR._generate_qr') as mock_generate: 27 with patch('cogs.qr.QR._generate_qr') as mock_generate:
28 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 28 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
29 with patch('os.path.exists', return_value=True): 29 with patch('os.path.exists', return_value=True):
@@ -36,7 +36,7 @@ async def test_qr_generate_success(qr_cog, mock_channel, mock_guild, bot, mock_t
36@pytest.mark.asyncio 36@pytest.mark.asyncio
37async def test_qr_generate_empty_text(qr_cog, mock_channel, mock_guild, bot): 37async def test_qr_generate_empty_text(qr_cog, mock_channel, mock_guild, bot):
38 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 38 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
39 39
40 with patch('cogs.qr.QR._generate_qr'): 40 with patch('cogs.qr.QR._generate_qr'):
41 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 41 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
42 with patch('os.path.exists', return_value=False): 42 with patch('os.path.exists', return_value=False):
@@ -47,10 +47,10 @@ async def test_qr_generate_empty_text(qr_cog, mock_channel, mock_guild, bot):
47@pytest.mark.asyncio 47@pytest.mark.asyncio
48async def test_qr_decode_not_available(qr_cog, mock_channel, mock_guild, bot): 48async def test_qr_decode_not_available(qr_cog, mock_channel, mock_guild, bot):
49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
50 50
51 mock_attachment = MagicMock() 51 mock_attachment = MagicMock()
52 mock_attachment.url = "https://example.com/qr.png" 52 mock_attachment.url = "https://example.com/qr.png"
53 53
54 with patch('cogs.qr._ensure_qr', return_value=False): 54 with patch('cogs.qr._ensure_qr', return_value=False):
55 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 55 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
56 await qr_cog.decode.callback(qr_cog, ctx, image=mock_attachment) 56 await qr_cog.decode.callback(qr_cog, ctx, image=mock_attachment)
@@ -62,14 +62,14 @@ async def test_qr_decode_not_available(qr_cog, mock_channel, mock_guild, bot):
62@pytest.mark.asyncio 62@pytest.mark.asyncio
63async def test_qr_decode_download_failure(qr_cog, mock_channel, mock_guild, bot): 63async def test_qr_decode_download_failure(qr_cog, mock_channel, mock_guild, bot):
64 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 64 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
65 65
66 mock_attachment = MagicMock() 66 mock_attachment = MagicMock()
67 mock_attachment.url = "https://example.com/qr.png" 67 mock_attachment.url = "https://example.com/qr.png"
68 68
69 with patch('cogs.qr._ensure_qr', return_value=True): 69 with patch('cogs.qr._ensure_qr', return_value=True):
70 with patch.object(qr_cog, '_download_image', return_value=None): 70 with patch.object(qr_cog, '_download_image', return_value=None):
71 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 71 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
72 await qr_cog.decode.callback(qr_cog, ctx, image=mock_attachment) 72 await qr_cog.decode.callback(qr_cog, ctx, image=mock_attachment)
73 mock_respond.assert_called_once() 73 mock_respond.assert_called_once()
74 args = mock_respond.call_args 74 args = mock_respond.call_args
75 assert "Nie udało się" in str(args) or "failed" in str(args).lower() \ No newline at end of file 75 assert "Nie udało się" in str(args) or "failed" in str(args).lower()
diff --git a/tests/cogs/test_say.py b/tests/cogs/test_say.py
index 12f2d2a..13cad40 100644
--- a/tests/cogs/test_say.py
+++ b/tests/cogs/test_say.py
@@ -13,7 +13,7 @@ def say_cog(bot):
13@pytest.mark.asyncio 13@pytest.mark.asyncio
14async def test_say_command(say_cog, mock_channel, mock_guild, bot): 14async def test_say_command(say_cog, mock_channel, mock_guild, bot):
15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
16 16
17 with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send: 17 with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send:
18 await say_cog.say.callback(say_cog, ctx, "Hello World") 18 await say_cog.say.callback(say_cog, ctx, "Hello World")
19 mock_send.assert_called_once_with(content="Hello World") 19 mock_send.assert_called_once_with(content="Hello World")
@@ -22,7 +22,7 @@ async def test_say_command(say_cog, mock_channel, mock_guild, bot):
22@pytest.mark.asyncio 22@pytest.mark.asyncio
23async def test_say_command_empty_text(say_cog, mock_channel, mock_guild, bot): 23async def test_say_command_empty_text(say_cog, mock_channel, mock_guild, bot):
24 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 24 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
25 25
26 with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send: 26 with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send:
27 await say_cog.say.callback(say_cog, ctx, "") 27 await say_cog.say.callback(say_cog, ctx, "")
28 mock_send.assert_called_once_with(content="") 28 mock_send.assert_called_once_with(content="")
@@ -32,7 +32,7 @@ async def test_say_command_empty_text(say_cog, mock_channel, mock_guild, bot):
32async def test_say_command_long_text(say_cog, mock_channel, mock_guild, bot): 32async def test_say_command_long_text(say_cog, mock_channel, mock_guild, bot):
33 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 33 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
34 long_text = "A" * 2000 34 long_text = "A" * 2000
35 35
36 with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send: 36 with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send:
37 await say_cog.say.callback(say_cog, ctx, long_text) 37 await say_cog.say.callback(say_cog, ctx, long_text)
38 mock_send.assert_called_once_with(content=long_text) \ No newline at end of file 38 mock_send.assert_called_once_with(content=long_text)
diff --git a/tests/cogs/test_search.py b/tests/cogs/test_search.py
index 4fde494..8c04dfc 100644
--- a/tests/cogs/test_search.py
+++ b/tests/cogs/test_search.py
@@ -16,11 +16,11 @@ async def test_search_command_success(search_cog, mock_channel, mock_guild, bot,
16 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 16 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
17 ctx.user = mock_user 17 ctx.user = mock_user
18 ctx.author = mock_user 18 ctx.author = mock_user
19 19
20 search_cog._cached_results[mock_user.id] = { 20 search_cog._cached_results[mock_user.id] = {
21 "testfile.mp4": "https://example.com/files/testfile.mp4" 21 "testfile.mp4": "https://example.com/files/testfile.mp4"
22 } 22 }
23 23
24 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: 24 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
25 await search_cog.search.callback(search_cog, ctx, filename="testfile.mp4") 25 await search_cog.search.callback(search_cog, ctx, filename="testfile.mp4")
26 mock_followup.assert_called_once_with("https://example.com/files/testfile.mp4") 26 mock_followup.assert_called_once_with("https://example.com/files/testfile.mp4")
@@ -32,7 +32,7 @@ async def test_search_command_no_cache(search_cog, mock_channel, mock_guild, bot
32 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 32 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
33 ctx.user = mock_user 33 ctx.user = mock_user
34 ctx.author = mock_user 34 ctx.author = mock_user
35 35
36 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: 36 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
37 await search_cog.search.callback(search_cog, ctx, filename="testfile.mp4") 37 await search_cog.search.callback(search_cog, ctx, filename="testfile.mp4")
38 mock_followup.assert_called_once_with("Search results expired. Please search again.") 38 mock_followup.assert_called_once_with("Search results expired. Please search again.")
@@ -43,11 +43,11 @@ async def test_search_command_file_not_found(search_cog, mock_channel, mock_guil
43 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 43 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
44 ctx.user = mock_user 44 ctx.user = mock_user
45 ctx.author = mock_user 45 ctx.author = mock_user
46 46
47 search_cog._cached_results[mock_user.id] = { 47 search_cog._cached_results[mock_user.id] = {
48 "testfile.mp4": "https://example.com/files/testfile.mp4" 48 "testfile.mp4": "https://example.com/files/testfile.mp4"
49 } 49 }
50 50
51 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: 51 with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup:
52 await search_cog.search.callback(search_cog, ctx, filename="nonexistent.mp4") 52 await search_cog.search.callback(search_cog, ctx, filename="nonexistent.mp4")
53 mock_followup.assert_called_once_with("File 'nonexistent.mp4' not found.") 53 mock_followup.assert_called_once_with("File 'nonexistent.mp4' not found.")
@@ -58,7 +58,7 @@ async def test_search_command_empty_filename(search_cog, mock_channel, mock_guil
58 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 58 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
59 ctx.user = mock_user 59 ctx.user = mock_user
60 ctx.author = mock_user 60 ctx.author = mock_user
61 61
62 with patch.object(ctx, 'reply', new_callable=AsyncMock) as mock_reply: 62 with patch.object(ctx, 'reply', new_callable=AsyncMock) as mock_reply:
63 await search_cog.search.callback(search_cog, ctx, filename="") 63 await search_cog.search.callback(search_cog, ctx, filename="")
64 mock_reply.assert_called_once_with("Please select a file from the autocomplete options.") 64 mock_reply.assert_called_once_with("Please select a file from the autocomplete options.")
@@ -70,14 +70,14 @@ async def test_file_autocomplete(search_cog, mock_channel, mock_guild, bot, mock
70 mock_autocomplete_ctx.value = "test" 70 mock_autocomplete_ctx.value = "test"
71 mock_autocomplete_ctx.interaction = MagicMock() 71 mock_autocomplete_ctx.interaction = MagicMock()
72 mock_autocomplete_ctx.interaction.user = mock_user 72 mock_autocomplete_ctx.interaction.user = mock_user
73 73
74 with patch('cogs.utils.file_search.UniversalSearcher.search_copyparty_autocomplete', new_callable=AsyncMock) as mock_search: 74 with patch('cogs.utils.file_search.UniversalSearcher.search_copyparty_autocomplete', new_callable=AsyncMock) as mock_search:
75 mock_search.return_value = [ 75 mock_search.return_value = [
76 "https://example.com/files/test1.mp4", 76 "https://example.com/files/test1.mp4",
77 "https://example.com/files/test2.mp4" 77 "https://example.com/files/test2.mp4"
78 ] 78 ]
79 79
80 choices = await search_cog.file_autocomplete(mock_autocomplete_ctx) 80 choices = await search_cog.file_autocomplete(mock_autocomplete_ctx)
81 81
82 assert len(choices) == 2 82 assert len(choices) == 2
83 assert mock_user.id in search_cog._cached_results \ No newline at end of file 83 assert mock_user.id in search_cog._cached_results
diff --git a/tests/cogs/test_trigger.py b/tests/cogs/test_trigger.py
index befc360..6aaaa11 100644
--- a/tests/cogs/test_trigger.py
+++ b/tests/cogs/test_trigger.py
@@ -28,17 +28,17 @@ def mock_db_connection():
28@pytest.mark.asyncio 28@pytest.mark.asyncio
29async def test_trigger_create_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): 29async def test_trigger_create_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection):
30 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 30 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
31 31
32 mock_conn, mock_cursor = mock_db_connection 32 mock_conn, mock_cursor = mock_db_connection
33 mock_cursor.fetchone.return_value = None 33 mock_cursor.fetchone.return_value = None
34 34
35 with patch('cogs.trigger.get_connection') as mock_get_conn: 35 with patch('cogs.trigger.get_connection') as mock_get_conn:
36 mock_conn = MagicMock() 36 mock_conn = MagicMock()
37 mock_cursor = MagicMock() 37 mock_cursor = MagicMock()
38 mock_conn.cursor.return_value = mock_cursor 38 mock_conn.cursor.return_value = mock_cursor
39 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) 39 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn)
40 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) 40 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False)
41 41
42 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 42 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
43 await trigger_cog.create.callback(trigger_cog, ctx, name="test_trigger") 43 await trigger_cog.create.callback(trigger_cog, ctx, name="test_trigger")
44 mock_respond.assert_called_once_with("trigger added") 44 mock_respond.assert_called_once_with("trigger added")
@@ -47,7 +47,7 @@ async def test_trigger_create_command(trigger_cog, mock_channel, mock_guild, bot
47@pytest.mark.asyncio 47@pytest.mark.asyncio
48async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): 48async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection):
49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
50 50
51 with patch('cogs.trigger.get_connection') as mock_get_conn: 51 with patch('cogs.trigger.get_connection') as mock_get_conn:
52 mock_conn = MagicMock() 52 mock_conn = MagicMock()
53 mock_cursor = MagicMock() 53 mock_cursor = MagicMock()
@@ -55,7 +55,7 @@ async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, m
55 mock_conn.cursor.return_value = mock_cursor 55 mock_conn.cursor.return_value = mock_cursor
56 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) 56 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn)
57 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) 57 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False)
58 58
59 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 59 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
60 await trigger_cog.add.callback(trigger_cog, ctx, name="test_trigger", trigger="hello", response="Hi there!") 60 await trigger_cog.add.callback(trigger_cog, ctx, name="test_trigger", trigger="hello", response="Hi there!")
61 mock_respond.assert_called_once_with("trigger updated") 61 mock_respond.assert_called_once_with("trigger updated")
@@ -64,7 +64,7 @@ async def test_trigger_add_command(trigger_cog, mock_channel, mock_guild, bot, m
64@pytest.mark.asyncio 64@pytest.mark.asyncio
65async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): 65async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection):
66 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 66 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
67 67
68 with patch('cogs.trigger.get_connection') as mock_get_conn: 68 with patch('cogs.trigger.get_connection') as mock_get_conn:
69 mock_conn = MagicMock() 69 mock_conn = MagicMock()
70 mock_cursor = MagicMock() 70 mock_cursor = MagicMock()
@@ -72,7 +72,7 @@ async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_gui
72 mock_conn.cursor.return_value = mock_cursor 72 mock_conn.cursor.return_value = mock_cursor
73 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) 73 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn)
74 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) 74 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False)
75 75
76 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 76 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
77 await trigger_cog.add.callback(trigger_cog, ctx, name="nonexistent", trigger="hello", response="Hi") 77 await trigger_cog.add.callback(trigger_cog, ctx, name="nonexistent", trigger="hello", response="Hi")
78 mock_respond.assert_called_once_with("Trigger not found.") 78 mock_respond.assert_called_once_with("Trigger not found.")
@@ -81,7 +81,7 @@ async def test_trigger_add_command_not_found(trigger_cog, mock_channel, mock_gui
81@pytest.mark.asyncio 81@pytest.mark.asyncio
82async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection): 82async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot, mock_db_connection):
83 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 83 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
84 84
85 with patch('cogs.trigger.get_connection') as mock_get_conn: 85 with patch('cogs.trigger.get_connection') as mock_get_conn:
86 mock_conn = MagicMock() 86 mock_conn = MagicMock()
87 mock_cursor = MagicMock() 87 mock_cursor = MagicMock()
@@ -89,7 +89,7 @@ async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot
89 mock_conn.cursor.return_value = mock_cursor 89 mock_conn.cursor.return_value = mock_cursor
90 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn) 90 mock_get_conn.return_value.__enter__ = MagicMock(return_value=mock_conn)
91 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False) 91 mock_get_conn.return_value.__exit__ = MagicMock(return_value=False)
92 92
93 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 93 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
94 await trigger_cog.delete.callback(trigger_cog, ctx, name="test_trigger") 94 await trigger_cog.delete.callback(trigger_cog, ctx, name="test_trigger")
95 mock_respond.assert_called_once_with("trigger deleted") 95 mock_respond.assert_called_once_with("trigger deleted")
@@ -98,9 +98,9 @@ async def test_trigger_delete_command(trigger_cog, mock_channel, mock_guild, bot
98@pytest.mark.asyncio 98@pytest.mark.asyncio
99async def test_trigger_help_command(trigger_cog, mock_channel, mock_guild, bot): 99async def test_trigger_help_command(trigger_cog, mock_channel, mock_guild, bot):
100 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 100 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
101 101
102 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 102 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
103 await trigger_cog.help.callback(trigger_cog, ctx) 103 await trigger_cog.help.callback(trigger_cog, ctx)
104 mock_respond.assert_called_once() 104 mock_respond.assert_called_once()
105 args = mock_respond.call_args 105 args = mock_respond.call_args
106 assert "Trigger create" in str(args) \ No newline at end of file 106 assert "Trigger create" in str(args)
diff --git a/tests/cogs/test_tts.py b/tests/cogs/test_tts.py
index 8c95670..de68580 100644
--- a/tests/cogs/test_tts.py
+++ b/tests/cogs/test_tts.py
@@ -16,10 +16,10 @@ async def test_tts_file_output(tts_cog, mock_channel, mock_guild, bot, mock_user
16 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 16 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
17 ctx.user = mock_user 17 ctx.user = mock_user
18 ctx.author = mock_user 18 ctx.author = mock_user
19 19
20 mock_temp_path = "/tmp/test_tts.mp3" 20 "/tmp/test_tts.mp3"
21 21
22 with patch('cogs.tts.gTTS') as mock_gtts: 22 with patch('cogs.tts.gTTS') as _:
23 with patch('os.path.exists', return_value=True): 23 with patch('os.path.exists', return_value=True):
24 with patch('os.unlink'): 24 with patch('os.unlink'):
25 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 25 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
@@ -34,7 +34,7 @@ async def test_tts_voice_output_not_in_channel(tts_cog, mock_channel, mock_guild
34 ctx.user = mock_user 34 ctx.user = mock_user
35 ctx.author = mock_user 35 ctx.author = mock_user
36 ctx.author.voice = None 36 ctx.author.voice = None
37 37
38 with patch('cogs.tts.gTTS'): 38 with patch('cogs.tts.gTTS'):
39 with patch('os.path.exists', return_value=True): 39 with patch('os.path.exists', return_value=True):
40 with patch('os.unlink'): 40 with patch('os.unlink'):
@@ -48,11 +48,11 @@ async def test_tts_error_handling(tts_cog, mock_channel, mock_guild, bot, mock_u
48 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 48 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
49 ctx.user = mock_user 49 ctx.user = mock_user
50 ctx.author = mock_user 50 ctx.author = mock_user
51 51
52 with patch('cogs.tts.gTTS', side_effect=Exception("TTS Error")): 52 with patch('cogs.tts.gTTS', side_effect=Exception("TTS Error")):
53 with patch('os.path.exists', return_value=False): 53 with patch('os.path.exists', return_value=False):
54 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 54 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
55 await tts_cog.tts.callback(tts_cog, ctx, text="Hello", output="file") 55 await tts_cog.tts.callback(tts_cog, ctx, text="Hello", output="file")
56 mock_respond.assert_called_once() 56 mock_respond.assert_called_once()
57 args = mock_respond.call_args 57 args = mock_respond.call_args
58 assert "Error" in str(args) or "eror" in str(args) \ No newline at end of file 58 assert "Error" in str(args) or "eror" in str(args)
diff --git a/tests/cogs/test_vclogs.py b/tests/cogs/test_vclogs.py
index 14bc6d5..2003478 100644
--- a/tests/cogs/test_vclogs.py
+++ b/tests/cogs/test_vclogs.py
@@ -6,7 +6,7 @@ from tests.conftest import MockApplicationContext
6 6
7def test_format_duration(): 7def test_format_duration():
8 from cogs.vclogs import format_duration 8 from cogs.vclogs import format_duration
9 9
10 assert format_duration(30) == "30s" 10 assert format_duration(30) == "30s"
11 assert format_duration(90) == "1m 30s" 11 assert format_duration(90) == "1m 30s"
12 assert format_duration(3661) == "1h 1m 1s" 12 assert format_duration(3661) == "1h 1m 1s"
@@ -44,9 +44,9 @@ async def test_handle_state_change_deaf_true(vclogs_cog):
44 mock_member = MagicMock() 44 mock_member = MagicMock()
45 mock_member.display_name = "TestUser" 45 mock_member.display_name = "TestUser"
46 mock_channel = MagicMock() 46 mock_channel = MagicMock()
47 47
48 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'deaf', True, None) 48 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'deaf', True, None)
49 49
50 assert "jest bity przez ojca" in tts_text 50 assert "jest bity przez ojca" in tts_text
51 51
52 52
@@ -55,9 +55,9 @@ async def test_handle_state_change_deaf_false(vclogs_cog):
55 mock_member = MagicMock() 55 mock_member = MagicMock()
56 mock_member.display_name = "TestUser" 56 mock_member.display_name = "TestUser"
57 mock_channel = MagicMock() 57 mock_channel = MagicMock()
58 58
59 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'deaf', False, None) 59 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'deaf', False, None)
60 60
61 assert "uciek od ojca" in tts_text 61 assert "uciek od ojca" in tts_text
62 62
63 63
@@ -66,9 +66,9 @@ async def test_handle_state_change_mute_true(vclogs_cog):
66 mock_member = MagicMock() 66 mock_member = MagicMock()
67 mock_member.display_name = "TestUser" 67 mock_member.display_name = "TestUser"
68 mock_channel = MagicMock() 68 mock_channel = MagicMock()
69 69
70 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'mute', True, None) 70 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'mute', True, None)
71 71
72 assert "idzie robić jajecznice" in tts_text 72 assert "idzie robić jajecznice" in tts_text
73 73
74 74
@@ -77,7 +77,7 @@ async def test_handle_state_change_mute_false(vclogs_cog):
77 mock_member = MagicMock() 77 mock_member = MagicMock()
78 mock_member.display_name = "TestUser" 78 mock_member.display_name = "TestUser"
79 mock_channel = MagicMock() 79 mock_channel = MagicMock()
80 80
81 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'mute', False, None) 81 tts_text, channel = await vclogs_cog.handle_state_change(mock_member, mock_channel, 'mute', False, None)
82 82
83 assert "zrobił jajecznice" in tts_text \ No newline at end of file 83 assert "zrobił jajecznice" in tts_text
diff --git a/tests/cogs/test_voice.py b/tests/cogs/test_voice.py
index f5784f6..ade29cb 100644
--- a/tests/cogs/test_voice.py
+++ b/tests/cogs/test_voice.py
@@ -7,14 +7,14 @@ from tests.conftest import MockApplicationContext
7@pytest.mark.asyncio 7@pytest.mark.asyncio
8async def test_get_voice_manager(): 8async def test_get_voice_manager():
9 from cogs.voice import get_voice_manager, VoiceManager 9 from cogs.voice import get_voice_manager, VoiceManager
10 10
11 mock_bot = MagicMock() 11 mock_bot = MagicMock()
12 mock_bot.user = MagicMock() 12 mock_bot.user = MagicMock()
13 mock_bot.user.id = 12345 13 mock_bot.user.id = 12345
14 14
15 manager1 = get_voice_manager(mock_bot) 15 manager1 = get_voice_manager(mock_bot)
16 manager2 = get_voice_manager(mock_bot) 16 manager2 = get_voice_manager(mock_bot)
17 17
18 assert isinstance(manager1, VoiceManager) 18 assert isinstance(manager1, VoiceManager)
19 assert manager1 is manager2 19 assert manager1 is manager2
20 20
@@ -22,41 +22,41 @@ async def test_get_voice_manager():
22@pytest.mark.asyncio 22@pytest.mark.asyncio
23async def test_voice_manager_join_channel_not_found(): 23async def test_voice_manager_join_channel_not_found():
24 from cogs.voice import VoiceManager 24 from cogs.voice import VoiceManager
25 25
26 mock_bot = MagicMock() 26 mock_bot = MagicMock()
27 mock_bot.get_channel.return_value = None 27 mock_bot.get_channel.return_value = None
28 28
29 manager = VoiceManager(mock_bot) 29 manager = VoiceManager(mock_bot)
30 result = await manager.join_by_channel_id(999) 30 result = await manager.join_by_channel_id(999)
31 31
32 assert result is None 32 assert result is None
33 33
34 34
35@pytest.mark.asyncio 35@pytest.mark.asyncio
36async def test_voice_manager_join_invalid_channel(): 36async def test_voice_manager_join_invalid_channel():
37 from cogs.voice import VoiceManager 37 from cogs.voice import VoiceManager
38 38
39 mock_bot = MagicMock() 39 mock_bot = MagicMock()
40 mock_channel = MagicMock() 40 mock_channel = MagicMock()
41 mock_bot.get_channel.return_value = mock_channel 41 mock_bot.get_channel.return_value = mock_channel
42 42
43 manager = VoiceManager(mock_bot) 43 manager = VoiceManager(mock_bot)
44 result = await manager.join_by_channel_id(999) 44 result = await manager.join_by_channel_id(999)
45 45
46 assert result is None 46 assert result is None
47 47
48 48
49@pytest.mark.asyncio 49@pytest.mark.asyncio
50async def test_voice_manager_get_voice_status_not_connected(): 50async def test_voice_manager_get_voice_status_not_connected():
51 from cogs.voice import VoiceManager 51 from cogs.voice import VoiceManager
52 52
53 mock_bot = MagicMock() 53 mock_bot = MagicMock()
54 mock_guild = MagicMock() 54 mock_guild = MagicMock()
55 55
56 with patch('cogs.voice.VoiceManager.get_voice_client', return_value=None): 56 with patch('cogs.voice.VoiceManager.get_voice_client', return_value=None):
57 manager = VoiceManager(mock_bot) 57 manager = VoiceManager(mock_bot)
58 voice_client, is_connected, is_playing = await manager.get_voice_status(mock_guild) 58 voice_client, is_connected, is_playing = await manager.get_voice_status(mock_guild)
59 59
60 assert voice_client is None 60 assert voice_client is None
61 assert is_connected == False 61 assert is_connected == False
62 assert is_playing == False 62 assert is_playing == False
@@ -65,15 +65,15 @@ async def test_voice_manager_get_voice_status_not_connected():
65@pytest.mark.asyncio 65@pytest.mark.asyncio
66async def test_voice_manager_stop(): 66async def test_voice_manager_stop():
67 from cogs.voice import VoiceManager 67 from cogs.voice import VoiceManager
68 68
69 mock_bot = MagicMock() 69 mock_bot = MagicMock()
70 mock_guild = MagicMock() 70 mock_guild = MagicMock()
71 mock_voice_client = MagicMock() 71 mock_voice_client = MagicMock()
72 mock_voice_client.disconnect = AsyncMock() 72 mock_voice_client.disconnect = AsyncMock()
73 73
74 with patch('cogs.voice.VoiceManager.get_voice_client', return_value=mock_voice_client): 74 with patch('cogs.voice.VoiceManager.get_voice_client', return_value=mock_voice_client):
75 manager = VoiceManager(mock_bot) 75 manager = VoiceManager(mock_bot)
76 await manager.stop(mock_guild) 76 await manager.stop(mock_guild)
77 77
78 mock_voice_client.stop.assert_called_once() 78 mock_voice_client.stop.assert_called_once()
79 mock_voice_client.disconnect.assert_called_once() \ No newline at end of file 79 mock_voice_client.disconnect.assert_called_once()
diff --git a/tests/cogs/test_web.py b/tests/cogs/test_web.py
index 53a44e5..e0d2208 100644
--- a/tests/cogs/test_web.py
+++ b/tests/cogs/test_web.py
@@ -13,7 +13,7 @@ def web_cog(bot):
13@pytest.mark.asyncio 13@pytest.mark.asyncio
14async def test_web_command_success(web_cog, mock_channel, mock_guild, bot): 14async def test_web_command_success(web_cog, mock_channel, mock_guild, bot):
15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 15 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
16 16
17 mock_response = MagicMock() 17 mock_response = MagicMock()
18 mock_response.status_code = 200 18 mock_response.status_code = 200
19 mock_response.text = ''' 19 mock_response.text = '''
@@ -22,7 +22,7 @@ async def test_web_command_success(web_cog, mock_channel, mock_guild, bot):
22 <a class="result__a" href="https://example.com/2">Test Result 2</a> 22 <a class="result__a" href="https://example.com/2">Test Result 2</a>
23 </html> 23 </html>
24 ''' 24 '''
25 25
26 with patch('cogs.web.requests.get', return_value=mock_response) as mock_get: 26 with patch('cogs.web.requests.get', return_value=mock_response) as mock_get:
27 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 27 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
28 await web_cog.web.callback(web_cog, ctx, query="test query") 28 await web_cog.web.callback(web_cog, ctx, query="test query")
@@ -33,11 +33,11 @@ async def test_web_command_success(web_cog, mock_channel, mock_guild, bot):
33@pytest.mark.asyncio 33@pytest.mark.asyncio
34async def test_web_command_no_results(web_cog, mock_channel, mock_guild, bot): 34async def test_web_command_no_results(web_cog, mock_channel, mock_guild, bot):
35 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 35 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
36 36
37 mock_response = MagicMock() 37 mock_response = MagicMock()
38 mock_response.status_code = 200 38 mock_response.status_code = 200
39 mock_response.text = '<html><body></body></html>' 39 mock_response.text = '<html><body></body></html>'
40 40
41 with patch('cogs.web.requests.get', return_value=mock_response): 41 with patch('cogs.web.requests.get', return_value=mock_response):
42 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 42 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
43 await web_cog.web.callback(web_cog, ctx, query="test") 43 await web_cog.web.callback(web_cog, ctx, query="test")
@@ -47,11 +47,11 @@ async def test_web_command_no_results(web_cog, mock_channel, mock_guild, bot):
47@pytest.mark.asyncio 47@pytest.mark.asyncio
48async def test_web_command_http_error(web_cog, mock_channel, mock_guild, bot): 48async def test_web_command_http_error(web_cog, mock_channel, mock_guild, bot):
49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) 49 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
50 50
51 mock_response = MagicMock() 51 mock_response = MagicMock()
52 mock_response.status_code = 500 52 mock_response.status_code = 500
53 53
54 with patch('cogs.web.requests.get', return_value=mock_response): 54 with patch('cogs.web.requests.get', return_value=mock_response):
55 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: 55 with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond:
56 await web_cog.web.callback(web_cog, ctx, query="test") 56 await web_cog.web.callback(web_cog, ctx, query="test")
57 mock_respond.assert_called_once_with(content="Error: 500", ephemeral=True) \ No newline at end of file 57 mock_respond.assert_called_once_with(content="Error: 500", ephemeral=True)