Update Bot API to 6.4

This commit is contained in:
Alex Root Junior 2022-12-30 22:09:21 +02:00
parent da0fb50e39
commit 38d911ad23
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
64 changed files with 1512 additions and 159 deletions

View file

@ -0,0 +1,20 @@
from aiogram.methods import CloseGeneralForumTopic, Request
from tests.mocked_bot import MockedBot
class TestCloseGeneralForumTopic:
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(CloseGeneralForumTopic, ok=True, result=True)
response: bool = await bot(CloseGeneralForumTopic(chat_id=42))
request: Request = bot.get_request()
assert request.method == "closeGeneralForumTopic"
assert response == prepare_result.result
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(CloseGeneralForumTopic, ok=True, result=True)
response: bool = await bot.close_general_forum_topic(chat_id=42)
request: Request = bot.get_request()
assert request.method == "closeGeneralForumTopic"
assert response == prepare_result.result

View file

@ -0,0 +1,20 @@
from aiogram.methods import EditGeneralForumTopic, Request
from tests.mocked_bot import MockedBot
class TestCloseGeneralForumTopic:
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(EditGeneralForumTopic, ok=True, result=True)
response: bool = await bot(EditGeneralForumTopic(chat_id=42, name="Test"))
request: Request = bot.get_request()
assert request.method == "editGeneralForumTopic"
assert response == prepare_result.result
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(EditGeneralForumTopic, ok=True, result=True)
response: bool = await bot.edit_general_forum_topic(chat_id=42, name="Test")
request: Request = bot.get_request()
assert request.method == "editGeneralForumTopic"
assert response == prepare_result.result

View file

@ -0,0 +1,20 @@
from aiogram.methods import HideGeneralForumTopic, Request
from tests.mocked_bot import MockedBot
class TestHideGeneralForumTopic:
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(HideGeneralForumTopic, ok=True, result=True)
response: bool = await bot(HideGeneralForumTopic(chat_id=42))
request: Request = bot.get_request()
assert request.method == "hideGeneralForumTopic"
assert response == prepare_result.result
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(HideGeneralForumTopic, ok=True, result=True)
response: bool = await bot.hide_general_forum_topic(chat_id=42)
request: Request = bot.get_request()
assert request.method == "hideGeneralForumTopic"
assert response == prepare_result.result

View file

@ -0,0 +1,20 @@
from aiogram.methods import ReopenGeneralForumTopic, Request
from tests.mocked_bot import MockedBot
class TestReopenGeneralForumTopic:
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(ReopenGeneralForumTopic, ok=True, result=True)
response: bool = await bot(ReopenGeneralForumTopic(chat_id=42))
request: Request = bot.get_request()
assert request.method == "reopenGeneralForumTopic"
assert response == prepare_result.result
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(ReopenGeneralForumTopic, ok=True, result=True)
response: bool = await bot.reopen_general_forum_topic(chat_id=42)
request: Request = bot.get_request()
assert request.method == "reopenGeneralForumTopic"
assert response == prepare_result.result

View file

@ -0,0 +1,20 @@
from aiogram.methods import Request, UnhideGeneralForumTopic
from tests.mocked_bot import MockedBot
class TestUnhideGeneralForumTopic:
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(UnhideGeneralForumTopic, ok=True, result=True)
response: bool = await bot(UnhideGeneralForumTopic(chat_id=42))
request: Request = bot.get_request()
assert request.method == "unhideGeneralForumTopic"
assert response == prepare_result.result
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(UnhideGeneralForumTopic, ok=True, result=True)
response: bool = await bot.unhide_general_forum_topic(chat_id=42)
request: Request = bot.get_request()
assert request.method == "unhideGeneralForumTopic"
assert response == prepare_result.result

View file

@ -1,5 +1,8 @@
from decimal import Decimal
from enum import Enum, auto
from fractions import Fraction
from typing import Optional
from uuid import UUID
import pytest
from magic_filter import MagicFilter
@ -45,36 +48,35 @@ class TestCallbackData:
class MyInvalidCallback(CallbackData, prefix="sp@m", sep="@"):
pass
#
# @pytest.mark.parametrize(
# "value,success,expected",
# [
# [None, True, ""],
# [42, True, "42"],
# ["test", True, "test"],
# [9.99, True, "9.99"],
# [Decimal("9.99"), True, "9.99"],
# [Fraction("3/2"), True, "3/2"],
# [
# UUID("123e4567-e89b-12d3-a456-426655440000"),
# True,
# "123e4567-e89b-12d3-a456-426655440000",
# ],
# [MyIntEnum.FOO, True, "1"],
# [MyStringEnum.FOO, True, "FOO"],
# [..., False, "..."],
# [object, False, "..."],
# [object(), False, "..."],
# [User(id=42, is_bot=False, first_name="test"), False, "..."],
# ],
# )
# def test_encode_value(self, value, success, expected):
# callback = MyCallback(foo="test", bar=42)
# if success:
# assert callback._encode_value("test", value) == expected
# else:
# with pytest.raises(ValueError):
# assert callback._encode_value("test", value) == expected
@pytest.mark.parametrize(
"value,success,expected",
[
[None, True, ""],
[42, True, "42"],
["test", True, "test"],
[9.99, True, "9.99"],
[Decimal("9.99"), True, "9.99"],
[Fraction("3/2"), True, "3/2"],
[
UUID("123e4567-e89b-12d3-a456-426655440000"),
True,
"123e4567-e89b-12d3-a456-426655440000",
],
[MyIntEnum.FOO, True, "1"],
[MyStringEnum.FOO, True, "FOO"],
[..., False, "..."],
[object, False, "..."],
[object(), False, "..."],
[User(id=42, is_bot=False, first_name="test"), False, "..."],
],
)
def test_encode_value(self, value, success, expected):
callback = MyCallback(foo="test", bar=42)
if success:
assert callback._encode_value("test", value) == expected
else:
with pytest.raises(ValueError):
assert callback._encode_value("test", value) == expected
def test_pack(self):
with pytest.raises(ValueError, match="Separator symbol .+"):