mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
* PoC: Mount objects to the Bot instance, bind shortcuts to configured instance * Fixe docstring of the bind method * Pass Bot instance explicitly to the URLInputFile * Added tests * Added changelog * Refactor aiogram client and update tests Refactored base.py to improve code readability by separating response_type operation from model_validate(). Also, adjusted the parameters in URLInputFile() within test_input_file.py for better test coverage. Updated input_file.py to streamline read method and avoid unnecessary instantiation of Bot class. Lastly, adjusted typing in methods/base.py to enhance code clarity. * Update changelog
35 lines
1 KiB
Python
35 lines
1 KiB
Python
from unittest.mock import sentinel
|
|
|
|
import pytest
|
|
|
|
from aiogram.methods import GetMe, TelegramMethod
|
|
from aiogram.types import User
|
|
from tests.mocked_bot import MockedBot
|
|
|
|
|
|
class TestTelegramMethodRemoveUnset:
|
|
@pytest.mark.parametrize(
|
|
"values,names",
|
|
[
|
|
[{}, set()],
|
|
[{"foo": "bar"}, {"foo"}],
|
|
[{"foo": "bar", "baz": sentinel.DEFAULT}, {"foo"}],
|
|
],
|
|
)
|
|
def test_remove_unset(self, values, names):
|
|
validated = TelegramMethod.remove_unset(values)
|
|
assert set(validated.keys()) == names
|
|
|
|
|
|
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)
|