merge 2
This commit is contained in:
@@ -183,42 +183,46 @@ class TestDownloadAndSaveAudio:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_download_and_save_audio_no_message(self, audio_service, mock_bot):
|
||||
"""Тест скачивания когда сообщение отсутствует"""
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, None, "test_audio")
|
||||
|
||||
"""Тест скачивания когда сообщение отсутствует."""
|
||||
with patch('helper_bot.handlers.voice.services.asyncio.sleep', new_callable=AsyncMock):
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, None, "test_audio")
|
||||
|
||||
assert "Сообщение или голосовое сообщение не найдено" in str(exc_info.value)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_download_and_save_audio_no_voice(self, audio_service, mock_bot):
|
||||
"""Тест скачивания когда у сообщения нет voice атрибута"""
|
||||
"""Тест скачивания когда у сообщения нет voice атрибута."""
|
||||
message = Mock()
|
||||
message.voice = None
|
||||
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, message, "test_audio")
|
||||
|
||||
|
||||
with patch('helper_bot.handlers.voice.services.asyncio.sleep', new_callable=AsyncMock):
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, message, "test_audio")
|
||||
|
||||
assert "Сообщение или голосовое сообщение не найдено" in str(exc_info.value)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_download_and_save_audio_download_failed(self, audio_service, mock_bot, mock_message, mock_file_info):
|
||||
"""Тест скачивания когда загрузка не удалась"""
|
||||
"""Тест скачивания когда загрузка не удалась."""
|
||||
mock_bot.get_file.return_value = mock_file_info
|
||||
mock_bot.download_file.return_value = None
|
||||
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, mock_message, "test_audio")
|
||||
|
||||
|
||||
with patch('helper_bot.handlers.voice.services.asyncio.sleep', new_callable=AsyncMock):
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, mock_message, "test_audio")
|
||||
|
||||
assert "Не удалось скачать файл" in str(exc_info.value)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_download_and_save_audio_exception_handling(self, audio_service, mock_bot, mock_message):
|
||||
"""Тест обработки исключений при скачивании"""
|
||||
"""Тест обработки исключений при скачивании."""
|
||||
mock_bot.get_file.side_effect = Exception("Network error")
|
||||
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, mock_message, "test_audio")
|
||||
|
||||
|
||||
with patch('helper_bot.handlers.voice.services.asyncio.sleep', new_callable=AsyncMock):
|
||||
with pytest.raises(FileOperationError) as exc_info:
|
||||
await audio_service.download_and_save_audio(mock_bot, mock_message, "test_audio")
|
||||
|
||||
assert "Не удалось скачать и сохранить аудио" in str(exc_info.value)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user