From fca9623e63300af53bbde183496d1b9f3796a6bc Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 19 Apr 2026 18:00:14 +0200 Subject: fix: proper aiohttp async context manager mocking in test --- tests/cogs/test_music_external_play.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tests/cogs') diff --git a/tests/cogs/test_music_external_play.py b/tests/cogs/test_music_external_play.py index 25c14e0..fd4b625 100644 --- a/tests/cogs/test_music_external_play.py +++ b/tests/cogs/test_music_external_play.py @@ -99,13 +99,18 @@ async def test_upload_to_copyparty_async(play_commands_cog, temp_mp3_file, monke monkeypatch.setenv("COPYPARTY_URL_UPLOAD", "https://catbox.2137697.xyz/sperma/") monkeypatch.setenv("COPYPARTY_PASSWORD", "testpassword") - mock_post = AsyncMock() mock_response = AsyncMock() mock_response.status = 200 + mock_response.text = AsyncMock(return_value="") mock_response.json = AsyncMock(return_value={"fileurl": "https://example.com/file.mp3"}) - mock_post.return_value.__aenter__ = AsyncMock(return_value=mock_response) - mock_post.return_value.__aexit__ = AsyncMock() + mock_response.__aenter__ = AsyncMock(return_value=mock_response) + mock_response.__aexit__ = AsyncMock() - with patch('aiohttp.ClientSession.post', mock_post): + mock_session_context = AsyncMock() + mock_session_context.__aenter__ = AsyncMock(return_value=mock_session_context) + mock_session_context.__aexit__ = AsyncMock() + mock_session_context.post = MagicMock(return_value=mock_response) + + with patch('aiohttp.ClientSession', return_value=mock_session_context): await play_commands_cog._upload_to_copyparty_async(temp_mp3_file) - mock_post.assert_called_once() + mock_session_context.post.assert_called_once() -- cgit v1.2.3