mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-15 20:02:22 +00:00
* Ensure base type validation can handle non-dictionary values The update introduces a condition to verify whether the values being validated are a dictionary before attempting to handle UNSET_TYPE in the aiogram base type. This adjustment helps to prevent potential errors or incorrect validation when non-dictionary values are faced. * Added a test case for non-dictionary input in remove_unset method * Added changelog * Fixed tests
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from unittest.mock import sentinel
|
|
|
|
import pytest
|
|
|
|
from aiogram.methods import GetMe, TelegramMethod
|
|
from aiogram.types import User, TelegramObject
|
|
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)
|