mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
The order of Union types for media properties in various files was reversed to `Union[str, InputFile]` for consistency. The changes were made in the following files: - aiogram/types/input_media_video.py - aiogram/types/input_media_audio.py - aiogram/types/input_media_document.py - aiogram/types/input_media_animation.py - aiogram/types/input_media_photo.py - aiogram/utils/media_group.py fix: update type check in base.py for TelegramObject (dev-3) Replaced BotContextController with TelegramObject in the type check to ensure proper handling of non-standard objects. test: add TODO comments in test files (dev-3) Added TODO comments to highlight parts of the code that need future improvements in the following test files: - tests/test_api/test_types/test_input_file.py - tests/test_api/test_client/test_session/test
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from typing import Any, Dict
|
|
from unittest.mock import sentinel
|
|
|
|
import pytest
|
|
|
|
from aiogram.client.default import Default
|
|
from aiogram.methods import GetMe, SendMessage, TelegramMethod
|
|
from aiogram.types import LinkPreviewOptions, TelegramObject, User
|
|
from tests.mocked_bot import MockedBot
|
|
|
|
|
|
class TestTelegramMethodRemoveUnset:
|
|
@pytest.mark.parametrize(
|
|
"values,names",
|
|
[
|
|
[{}, set()],
|
|
[{"foo": "bar"}, {"foo"}],
|
|
[{"foo": "bar", "baz": sentinel.DEFAULT}, {"foo"}],
|
|
],
|
|
)
|
|
@pytest.mark.parametrize("obj", [TelegramMethod, TelegramObject])
|
|
def test_remove_unset(self, values, names, obj):
|
|
validated = obj.remove_unset.wrapped(values)
|
|
assert set(validated.keys()) == names
|
|
|
|
@pytest.mark.parametrize("obj", [TelegramMethod, TelegramObject])
|
|
def test_remove_unset_non_dict(self, obj):
|
|
assert obj.remove_unset.wrapped("") == ""
|
|
|
|
|
|
class TestTelegramMethodModelDumpJson:
|
|
@pytest.mark.parametrize(
|
|
"obj",
|
|
[
|
|
SendMessage(
|
|
chat_id=1,
|
|
text="test",
|
|
),
|
|
LinkPreviewOptions(),
|
|
],
|
|
)
|
|
def test_model_dump_json(self, obj):
|
|
def has_defaults(dump: Dict[str, Any]) -> bool:
|
|
return any(isinstance(value, Default) for value in dump.values())
|
|
|
|
assert has_defaults(obj.model_dump())
|
|
assert not has_defaults(obj.model_dump(mode="json"))
|
|
|
|
|
|
class TestTelegramMethodCall:
|
|
async def test_async_emit_unsuccessful(self, bot: MockedBot):
|
|
with pytest.raises(
|
|
RuntimeError,
|
|
match="This method is not mounted to a any bot instance.+",
|
|
):
|
|
await GetMe()
|
|
|
|
async def test_async_emit(self, bot: MockedBot):
|
|
bot.add_result_for(GetMe, ok=True, result=User(id=42, is_bot=True, first_name="Test"))
|
|
method = GetMe().as_(bot)
|
|
assert isinstance(await method, User)
|