Backport text decorations. Improve timeouts in tests. Improve TelegramAPIServer

This commit is contained in:
Alex Root Junior 2021-01-24 23:12:07 +02:00
parent 4292b3934f
commit 1a185928a2
11 changed files with 82 additions and 48 deletions

View file

@ -1,4 +1,4 @@
from aiogram.client.telegram import PRODUCTION
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
class TestAPIServer:
@ -9,3 +9,13 @@ class TestAPIServer:
def test_file_url(self):
file_url = PRODUCTION.file_url(token="42:TEST", path="path")
assert file_url == "https://api.telegram.org/file/bot42:TEST/path"
def test_from_base(self):
local_server = TelegramAPIServer.from_base("http://localhost:8081", is_local=True)
method_url = local_server.api_url("42:TEST", method="apiMethod")
file_url = local_server.file_url(token="42:TEST", path="path")
assert method_url == "http://localhost:8081/bot42:TEST/apiMethod"
assert file_url == "http://localhost:8081/file/bot42:TEST/path"
assert local_server.is_local

View file

@ -1,4 +1,5 @@
import pytest
from aiogram.methods import Close, Request
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,5 @@
import pytest
from aiogram.methods import CopyMessage, Request
from aiogram.types import MessageId
from tests.mocked_bot import MockedBot
@ -10,7 +11,9 @@ class TestCopyMessage:
prepare_result = bot.add_result_for(CopyMessage, ok=True, result=MessageId(message_id=42))
response: MessageId = await CopyMessage(
chat_id=42, from_chat_id=42, message_id=42,
chat_id=42,
from_chat_id=42,
message_id=42,
)
request: Request = bot.get_request()
assert request.method == "copyMessage"
@ -22,7 +25,9 @@ class TestCopyMessage:
prepare_result = bot.add_result_for(CopyMessage, ok=True, result=MessageId(message_id=42))
response: MessageId = await bot.copy_message(
chat_id=42, from_chat_id=42, message_id=42,
chat_id=42,
from_chat_id=42,
message_id=42,
)
request: Request = bot.get_request()
assert request.method == "copyMessage"

View file

@ -1,4 +1,5 @@
import pytest
from aiogram.methods import LogOut, Request
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,5 @@
import pytest
from aiogram.methods import Request, UnpinAllChatMessages
from tests.mocked_bot import MockedBot
@ -8,7 +9,9 @@ class TestUnpinAllChatMessages:
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(UnpinAllChatMessages, ok=True, result=True)
response: bool = await UnpinAllChatMessages(chat_id=42,)
response: bool = await UnpinAllChatMessages(
chat_id=42,
)
request: Request = bot.get_request()
assert request.method == "unpinAllChatMessages"
# assert request.data == {}
@ -18,7 +21,9 @@ class TestUnpinAllChatMessages:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(UnpinAllChatMessages, ok=True, result=True)
response: bool = await bot.unpin_all_chat_messages(chat_id=42,)
response: bool = await bot.unpin_all_chat_messages(
chat_id=42,
)
request: Request = bot.get_request()
assert request.method == "unpinAllChatMessages"
# assert request.data == {}