aiogram/tests/test_api/test_methods/test_base.py
Alex Root Junior 5cf8d7b565
Add MediaGroupBuilder for media group construction (#1293)
Implemented a MediaGroupBuilder class in 'aiogram/utils/media_group.py' to help construct media groups. The class supports addition of different media types (audio, photo, video, document) to the media group with a maximum limit of 10 files. The functionality is demonstrated and usage is documented in 'docs/utils/media_group.rst'. Added related test cases in 'tests/test_utils/test_media_group.py'. This is to streamline and simplify the process of media group creation
2023-09-03 00:25:31 +03:00

40 lines
1.3 KiB
Python

from unittest.mock import sentinel
import pytest
from aiogram.methods import GetMe, TelegramMethod
from aiogram.types import 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(values)
assert set(validated.keys()) == names
@pytest.mark.parametrize("obj", [TelegramMethod, TelegramObject])
def test_remove_unset_non_dict(self, obj):
assert obj.remove_unset("") == ""
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)