aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_search.py
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/test_search.py
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_search.py20
1 files changed, 10 insertions, 10 deletions
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