45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import pytest
|
|
from unittest.mock import AsyncMock, patch
|
|
from api_calls.draft_data import get_draft_data, DraftData
|
|
from exceptions import ApiException
|
|
import datetime
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_draft_data_success():
|
|
mock_data = {
|
|
"id": 42,
|
|
"currentpick": 3,
|
|
"timer": True,
|
|
"pick_deadline": datetime.datetime(2025, 6, 7, 12, 30).isoformat(),
|
|
"result_channel": 123456, # will be cast to string
|
|
"ping_channel": None, # will become 'None' as string
|
|
"pick_minutes": 5
|
|
}
|
|
|
|
with patch("api_calls.draft_data.db_get", new_callable=AsyncMock) as mock_db_get:
|
|
mock_db_get.return_value = mock_data
|
|
|
|
result = await get_draft_data()
|
|
|
|
assert isinstance(result, DraftData)
|
|
assert result.id == 42
|
|
assert result.currentpick == 3
|
|
assert result.timer is True
|
|
assert isinstance(result.pick_deadline, datetime.datetime)
|
|
assert result.result_channel == "123456"
|
|
assert result.ping_channel == "None"
|
|
assert result.pick_minutes == 5
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_draft_data_none_response_raises():
|
|
with patch("api_calls.draft_data.db_get", new_callable=AsyncMock) as mock_db_get, \
|
|
patch("api_calls.draft_data.log_exception") as mock_log_exception:
|
|
|
|
mock_db_get.return_value = None
|
|
mock_log_exception.side_effect = ApiException("Mocked exception")
|
|
|
|
with pytest.raises(ApiException, match="Mocked exception"):
|
|
await get_draft_data()
|