[3.x] Bot API 6.0 (#890)

* Base implementation

* Bump license

* Revert re-generated tests

* Fix tests, improved docs

* Remove TODO

* Removed unreachable code

* Changed type of `last_synchronization_error_date`

* Fixed wrongly cleaned code
This commit is contained in:
Alex Root Junior 2022-04-19 22:03:24 +03:00 committed by GitHub
parent 286cf39c8a
commit 497436595d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
81 changed files with 1942 additions and 147 deletions

View file

@ -0,0 +1,33 @@
import pytest
from aiogram.methods import AnswerWebAppQuery, Request
from aiogram.types import InlineQueryResult, SentWebAppMessage
from tests.mocked_bot import MockedBot
class TestAnswerWebAppQuery:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerWebAppQuery, ok=True, result=SentWebAppMessage())
response: SentWebAppMessage = await AnswerWebAppQuery(
web_app_query_id="test",
result=InlineQueryResult(),
)
request: Request = bot.get_request()
assert request.method == "answerWebAppQuery"
# assert request.data == {}
assert response == prepare_result.result
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerWebAppQuery, ok=True, result=SentWebAppMessage())
response: SentWebAppMessage = await bot.answer_web_app_query(
web_app_query_id="test",
result=InlineQueryResult(),
)
request: Request = bot.get_request()
assert request.method == "answerWebAppQuery"
# assert request.data == {}
assert response == prepare_result.result

View file

View file

View file

View file

@ -0,0 +1,27 @@
import pytest
from aiogram.methods import GetChatMenuButton, Request
from aiogram.types import MenuButton, MenuButtonDefault
from tests.mocked_bot import MockedBot
class TestGetChatMenuButton:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(GetChatMenuButton, ok=True, result=MenuButtonDefault())
response: MenuButton = await GetChatMenuButton()
request: Request = bot.get_request()
assert request.method == "getChatMenuButton"
# assert request.data == {}
assert response == prepare_result.result
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(GetChatMenuButton, ok=True, result=MenuButtonDefault())
response: MenuButton = await bot.get_chat_menu_button()
request: Request = bot.get_request()
assert request.method == "getChatMenuButton"
# assert request.data == {}
assert response == prepare_result.result

View file

@ -0,0 +1,53 @@
import pytest
from aiogram.methods import GetMyDefaultAdministratorRights, Request
from aiogram.types import ChatAdministratorRights
from tests.mocked_bot import MockedBot
class TestGetMyDefaultAdministratorRights:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
GetMyDefaultAdministratorRights,
ok=True,
result=ChatAdministratorRights(
is_anonymous=False,
can_manage_chat=False,
can_delete_messages=False,
can_manage_video_chats=False,
can_restrict_members=False,
can_promote_members=False,
can_change_info=False,
can_invite_users=False,
),
)
response: ChatAdministratorRights = await GetMyDefaultAdministratorRights()
request: Request = bot.get_request()
assert request.method == "getMyDefaultAdministratorRights"
# assert request.data == {}
assert response == prepare_result.result
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
GetMyDefaultAdministratorRights,
ok=True,
result=ChatAdministratorRights(
is_anonymous=False,
can_manage_chat=False,
can_delete_messages=False,
can_manage_video_chats=False,
can_restrict_members=False,
can_promote_members=False,
can_change_info=False,
can_invite_users=False,
),
)
response: ChatAdministratorRights = await bot.get_my_default_administrator_rights()
request: Request = bot.get_request()
assert request.method == "getMyDefaultAdministratorRights"
# assert request.data == {}
assert response == prepare_result.result

View file

@ -16,6 +16,7 @@ class TestGetStickerSet:
name="test",
title="test",
is_animated=False,
is_video=False,
contains_masks=False,
stickers=[
Sticker(
@ -23,6 +24,7 @@ class TestGetStickerSet:
width=42,
height=42,
is_animated=False,
is_video=False,
file_unique_id="file id",
)
],
@ -42,6 +44,7 @@ class TestGetStickerSet:
name="test",
title="test",
is_animated=False,
is_video=False,
contains_masks=False,
stickers=[
Sticker(
@ -49,6 +52,7 @@ class TestGetStickerSet:
width=42,
height=42,
is_animated=False,
is_video=False,
file_unique_id="file id",
)
],

View file

@ -22,6 +22,7 @@ class TestSendSticker:
width=42,
height=42,
is_animated=False,
is_video=False,
file_unique_id="file id",
),
chat=Chat(id=42, type="private"),
@ -45,6 +46,7 @@ class TestSendSticker:
width=42,
height=42,
is_animated=False,
is_video=False,
file_unique_id="file id",
),
chat=Chat(id=42, type="private"),

View file

@ -0,0 +1,26 @@
import pytest
from aiogram.methods import Request, SetChatMenuButton
from tests.mocked_bot import MockedBot
class TestSetChatMenuButton:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SetChatMenuButton, ok=True, result=True)
response: bool = await SetChatMenuButton()
request: Request = bot.get_request()
assert request.method == "setChatMenuButton"
# assert request.data == {}
assert response == prepare_result.result
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SetChatMenuButton, ok=True, result=True)
response: bool = await bot.set_chat_menu_button()
request: Request = bot.get_request()
assert request.method == "setChatMenuButton"
# assert request.data == {}
assert response == prepare_result.result

View file

@ -0,0 +1,26 @@
import pytest
from aiogram.methods import Request, SetMyDefaultAdministratorRights
from tests.mocked_bot import MockedBot
class TestSetMyDefaultAdministratorRights:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SetMyDefaultAdministratorRights, ok=True, result=True)
response: bool = await SetMyDefaultAdministratorRights()
request: Request = bot.get_request()
assert request.method == "setMyDefaultAdministratorRights"
# assert request.data == {}
assert response == prepare_result.result
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SetMyDefaultAdministratorRights, ok=True, result=True)
response: bool = await bot.set_my_default_administrator_rights()
request: Request = bot.get_request()
assert request.method == "setMyDefaultAdministratorRights"
# assert request.data == {}
assert response == prepare_result.result

View file