Base implementation

This commit is contained in:
Alex Root Junior 2022-04-17 00:05:29 +03:00
parent 286cf39c8a
commit 8bb8fe7ad7
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
68 changed files with 1826 additions and 78 deletions

View file

@ -0,0 +1,34 @@
import pytest
from aiogram.methods import AnswerWebAppQuery, Request
from aiogram.types import SentWebAppMessage
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestAnswerWebAppQuery:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerWebAppQuery, ok=True, result=None)
response: SentWebAppMessage = await AnswerWebAppQuery(
web_app_query_id=...,
result=...,
)
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=None)
response: SentWebAppMessage = await bot.answer_web_app_query(
web_app_query_id=...,
result=...,
)
request: Request = bot.get_request()
assert request.method == "answerWebAppQuery"
# assert request.data == {}
assert response == prepare_result.result

View file

@ -1,20 +1,22 @@
import pytest
from aiogram.methods import ApproveChatJoinRequest, Request
from aiogram.api.methods import ApproveChatJoinRequest, Request
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestApproveChatJoinRequest:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(ApproveChatJoinRequest, ok=True, result=True)
prepare_result = bot.add_result_for(ApproveChatJoinRequest, ok=True, result=None)
response: bool = await ApproveChatJoinRequest(
chat_id=-42,
user_id=42,
chat_id=...,
user_id=...,
)
request: Request = bot.get_request()
assert request.method == "approveChatJoinRequest"
# assert request.data == {}
assert response == prepare_result.result
@pytest.mark.asyncio
@ -22,9 +24,10 @@ class TestApproveChatJoinRequest:
prepare_result = bot.add_result_for(ApproveChatJoinRequest, ok=True, result=None)
response: bool = await bot.approve_chat_join_request(
chat_id=-42,
user_id=42,
chat_id=...,
user_id=...,
)
request: Request = bot.get_request()
assert request.method == "approveChatJoinRequest"
# assert request.data == {}
assert response == prepare_result.result

View file

@ -1,17 +1,18 @@
import pytest
from aiogram.methods import BanChatSenderChat, Request
from aiogram.api.methods import BanChatSenderChat, Request
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestBanChatSenderChat:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(BanChatSenderChat, ok=True, result=True)
prepare_result = bot.add_result_for(BanChatSenderChat, ok=True, result=None)
response: bool = await BanChatSenderChat(
chat_id=-42,
sender_chat_id=-1337,
chat_id=...,
sender_chat_id=...,
)
request: Request = bot.get_request()
assert request.method == "banChatSenderChat"
@ -20,11 +21,11 @@ class TestBanChatSenderChat:
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(BanChatSenderChat, ok=True, result=True)
prepare_result = bot.add_result_for(BanChatSenderChat, ok=True, result=None)
response: bool = await bot.ban_chat_sender_chat(
chat_id=-42,
sender_chat_id=-1337,
chat_id=...,
sender_chat_id=...,
)
request: Request = bot.get_request()
assert request.method == "banChatSenderChat"

View file

@ -1,30 +1,33 @@
import pytest
from aiogram.methods import DeclineChatJoinRequest, Request
from aiogram.api.methods import DeclineChatJoinRequest, Request
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestDeclineChatJoinRequest:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(DeclineChatJoinRequest, ok=True, result=True)
prepare_result = bot.add_result_for(DeclineChatJoinRequest, ok=True, result=None)
response: bool = await DeclineChatJoinRequest(
chat_id=-42,
user_id=42,
chat_id=...,
user_id=...,
)
request: Request = bot.get_request()
assert request.method == "declineChatJoinRequest"
# 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(DeclineChatJoinRequest, ok=True, result=True)
prepare_result = bot.add_result_for(DeclineChatJoinRequest, ok=True, result=None)
response: bool = await bot.decline_chat_join_request(
chat_id=-42,
user_id=42,
chat_id=...,
user_id=...,
)
request: Request = bot.get_request()
assert request.method == "declineChatJoinRequest"
# assert request.data == {}
assert response == prepare_result.result

View file

@ -0,0 +1,28 @@
import pytest
from aiogram.methods import GetChatMenuButton, Request
from aiogram.types import MenuButton
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestGetChatMenuButton:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(GetChatMenuButton, ok=True, result=None)
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=None)
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,28 @@
import pytest
from aiogram.methods import GetMyDefaultAdministratorRights, Request
from aiogram.types import ChatAdministratorRights
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestGetMyDefaultAdministratorRights:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(GetMyDefaultAdministratorRights, ok=True, result=None)
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=None)
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

@ -0,0 +1,27 @@
import pytest
from aiogram.api.methods import Request, SetChatMenuButton
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestSetChatMenuButton:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SetChatMenuButton, ok=True, result=None)
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=None)
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,27 @@
import pytest
from aiogram.api.methods import Request, SetMyDefaultAdministratorRights
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestSetMyDefaultAdministratorRights:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SetMyDefaultAdministratorRights, ok=True, result=None)
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=None)
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

@ -1,17 +1,18 @@
import pytest
from aiogram.methods import Request, UnbanChatSenderChat
from aiogram.api.methods import Request, UnbanChatSenderChat
from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestUnbanChatSenderChat:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(UnbanChatSenderChat, ok=True, result=True)
prepare_result = bot.add_result_for(UnbanChatSenderChat, ok=True, result=None)
response: bool = await UnbanChatSenderChat(
chat_id=-42,
sender_chat_id=-1337,
chat_id=...,
sender_chat_id=...,
)
request: Request = bot.get_request()
assert request.method == "unbanChatSenderChat"
@ -20,11 +21,11 @@ class TestUnbanChatSenderChat:
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(UnbanChatSenderChat, ok=True, result=True)
prepare_result = bot.add_result_for(UnbanChatSenderChat, ok=True, result=None)
response: bool = await bot.unban_chat_sender_chat(
chat_id=-42,
sender_chat_id=-1337,
chat_id=...,
sender_chat_id=...,
)
request: Request = bot.get_request()
assert request.method == "unbanChatSenderChat"

View file

@ -82,11 +82,11 @@ class TestDispatcher:
assert dp.get("foo", 42) == 42
dp["foo"] = 1
assert dp._data["foo"] == 1
assert dp.workflow_data["foo"] == 1
assert dp["foo"] == 1
del dp["foo"]
assert "foo" not in dp._data
assert "foo" not in dp.workflow_data
def test_storage_property(self, dispatcher: Dispatcher):
assert dispatcher.storage is dispatcher.fsm.storage