Enhance bot functionality with new features and improvements
- Added a new `/status` endpoint in `server_prometheus.py` to provide process status information, including uptime and resource usage metrics. - Implemented a PID manager in `run_helper.py` to track the bot's process, improving monitoring capabilities. - Introduced a method to delete audio moderation records in `audio_repository.py`, enhancing database management. - Updated voice message handling in callback handlers to ensure proper deletion of audio moderation records. - Improved error handling and logging in various services, ensuring better tracking of media processing and file downloads. - Refactored media handling functions to streamline operations and improve code readability. - Enhanced metrics tracking for file downloads and media processing, providing better insights into bot performance.
This commit is contained in:
@@ -288,15 +288,20 @@ class TestDownloadFile:
|
||||
# Мокаем download_file
|
||||
mock_message.bot.download_file = AsyncMock()
|
||||
|
||||
# Мокаем os.makedirs
|
||||
# Мокаем os.makedirs и другие зависимости
|
||||
with patch('os.makedirs') as mock_makedirs:
|
||||
with patch('os.path.join', return_value="files/photos/file_123.jpg"):
|
||||
result = await download_file(mock_message, "file_id_123")
|
||||
|
||||
assert result == "files/photos/file_123.jpg"
|
||||
mock_makedirs.assert_called()
|
||||
mock_message.bot.get_file.assert_called_once_with("file_id_123")
|
||||
mock_message.bot.download_file.assert_called_once()
|
||||
with patch('os.path.exists', return_value=True):
|
||||
with patch('os.path.getsize', return_value=1024):
|
||||
with patch('os.path.basename', return_value='file_123.jpg'):
|
||||
with patch('os.path.splitext', return_value=('file_123', '.jpg')):
|
||||
with patch('helper_bot.utils.helper_func.metrics') as mock_metrics:
|
||||
result = await download_file(mock_message, "file_id_123", "photo")
|
||||
|
||||
assert result == "files/photos/file_123.jpg"
|
||||
mock_makedirs.assert_called()
|
||||
mock_message.bot.get_file.assert_called_once_with("file_id_123")
|
||||
mock_message.bot.download_file.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_download_file_exception(self):
|
||||
|
||||
Reference in New Issue
Block a user