test fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
|
||||
import pytest
|
||||
@@ -268,14 +268,16 @@ class TestAudioRepository:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_date_by_file_name(self, audio_repository):
|
||||
"""Тест получения даты по имени файла"""
|
||||
timestamp = 1642404600 # 2022-01-17 10:30:00
|
||||
"""Тест получения даты по имени файла (UTC, без зависимости от локали)"""
|
||||
timestamp = 1642404600 # 2022-01-17 10:30:00 UTC
|
||||
audio_repository._execute_query_with_result.return_value = [(timestamp,)]
|
||||
|
||||
result = await audio_repository.get_date_by_file_name("test_audio.ogg")
|
||||
|
||||
# Должна вернуться читаемая дата
|
||||
assert result == "17.01.2022 10:30"
|
||||
expected = datetime.fromtimestamp(timestamp, tz=timezone.utc).strftime(
|
||||
"%d.%m.%Y %H:%M"
|
||||
)
|
||||
assert result == expected
|
||||
audio_repository._execute_query_with_result.assert_called_once_with(
|
||||
"SELECT date_added FROM audio_message_reference WHERE file_name = ?",
|
||||
("test_audio.ogg",),
|
||||
@@ -403,17 +405,19 @@ class TestAudioRepository:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_date_by_file_name_logging(self, audio_repository):
|
||||
"""Тест логирования при получении даты по имени файла"""
|
||||
timestamp = 1642404600 # 2022-01-17 10:30:00
|
||||
"""Тест логирования при получении даты по имени файла (UTC)"""
|
||||
timestamp = 1642404600 # 2022-01-17 10:30:00 UTC
|
||||
audio_repository._execute_query_with_result.return_value = [(timestamp,)]
|
||||
|
||||
await audio_repository.get_date_by_file_name("test_audio.ogg")
|
||||
|
||||
# Проверяем, что лог записан
|
||||
expected = datetime.fromtimestamp(timestamp, tz=timezone.utc).strftime(
|
||||
"%d.%m.%Y %H:%M"
|
||||
)
|
||||
audio_repository.logger.info.assert_called_once()
|
||||
log_message = audio_repository.logger.info.call_args[0][0]
|
||||
assert "Получена дата" in log_message
|
||||
assert "17.01.2022 10:30" in log_message
|
||||
assert expected in log_message
|
||||
assert "test_audio.ogg" in log_message
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user