From dba3388567818cb5c60be9d406d3e1cccc84b3ea Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 29 Apr 2026 14:22:03 +0200 Subject: Refactor database connections and add integration tests - Use context managers for sqlite3 connections in cron, vclogs, and database utils - Add URL helper utility for yt-dlp with clean_url_for_ytdlp function - Add slow integration test markers and new integration test files - Fix test imports to use conftest directly instead of tests.conftest - Improve downloader error handling and use COPYPARTY_URL_UPLOAD env var - Update pytest.ini with slow test markers and warning filters - Document slow test usage in AGENTS.md --- tests/cogs/test_music_integration.py | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/cogs/test_music_integration.py (limited to 'tests/cogs/test_music_integration.py') diff --git a/tests/cogs/test_music_integration.py b/tests/cogs/test_music_integration.py new file mode 100644 index 0000000..1c0260a --- /dev/null +++ b/tests/cogs/test_music_integration.py @@ -0,0 +1,44 @@ +import pytest +from unittest.mock import MagicMock, AsyncMock, patch, PropertyMock +import sys +sys.path.insert(0, '/home/salmon/Documents/botcode/senator-sperma/tests') +from conftest import MockApplicationContext + + +@pytest.fixture +def music_cog(bot): + from cogs.music.play_commands import PlayCommands + cog = PlayCommands(bot) + return cog + + +@pytest.mark.slow +@pytest.mark.asyncio +async def test_music_join_stop(music_cog, bot): + """Test music join and stop commands.""" + from cogs.music.join import Join + from cogs.music.stop import Stop + + join_cog = Join(bot) + stop_cog = Stop(bot) + + ctx = MockApplicationContext(bot=bot) + ctx.author.voice = MagicMock() + ctx.author.voice.channel = MagicMock() + ctx.guild = MagicMock() + + voice_client = AsyncMock() + ctx.voice_client = voice_client + + # Test join + ctx.author.voice.channel.connect = AsyncMock(return_value=voice_client) + with patch.object(ctx, 'respond', new_callable=AsyncMock): + with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): + await join_cog.join.callback(join_cog, ctx) + ctx.author.voice.channel.connect.assert_called_once() + + # Test stop + with patch.object(ctx, 'respond', new_callable=AsyncMock): + with patch.object(ctx.interaction, 'delete_original_response', new_callable=AsyncMock): + await stop_cog.stop.callback(stop_cog, ctx) + voice_client.disconnect.assert_called_once() -- cgit v1.2.3