From b343381fea3eab26e334a1b3bba202d715f9ea2e Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 19 Apr 2026 15:44:33 +0200 Subject: test: improve test assertions and edge cases --- tests/cogs/test_search.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/cogs/test_search.py') 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, ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) ctx.user = mock_user ctx.author = mock_user - + search_cog._cached_results[mock_user.id] = { "testfile.mp4": "https://example.com/files/testfile.mp4" } - + with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: await search_cog.search.callback(search_cog, ctx, filename="testfile.mp4") 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 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) ctx.user = mock_user ctx.author = mock_user - + with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: await search_cog.search.callback(search_cog, ctx, filename="testfile.mp4") 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 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) ctx.user = mock_user ctx.author = mock_user - + search_cog._cached_results[mock_user.id] = { "testfile.mp4": "https://example.com/files/testfile.mp4" } - + with patch.object(ctx, 'send_followup', new_callable=AsyncMock) as mock_followup: await search_cog.search.callback(search_cog, ctx, filename="nonexistent.mp4") 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 ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) ctx.user = mock_user ctx.author = mock_user - + with patch.object(ctx, 'reply', new_callable=AsyncMock) as mock_reply: await search_cog.search.callback(search_cog, ctx, filename="") 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 mock_autocomplete_ctx.value = "test" mock_autocomplete_ctx.interaction = MagicMock() mock_autocomplete_ctx.interaction.user = mock_user - + with patch('cogs.utils.file_search.UniversalSearcher.search_copyparty_autocomplete', new_callable=AsyncMock) as mock_search: mock_search.return_value = [ "https://example.com/files/test1.mp4", "https://example.com/files/test2.mp4" ] - + choices = await search_cog.file_autocomplete(mock_autocomplete_ctx) - + assert len(choices) == 2 - assert mock_user.id in search_cog._cached_results \ No newline at end of file + assert mock_user.id in search_cog._cached_results -- cgit v1.2.3