mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Added more aliases, refactor CallbackData factory, added base exceptions classification mechanism
This commit is contained in:
parent
9451a085d1
commit
f022b4441c
18 changed files with 364 additions and 664 deletions
|
|
@ -172,14 +172,10 @@ class TestAiohttpSession:
|
|||
return Request(method="method", data={})
|
||||
|
||||
call = TestMethod()
|
||||
with patch(
|
||||
"aiogram.client.session.base.BaseSession.raise_for_status"
|
||||
) as patched_raise_for_status:
|
||||
result = await session.make_request(bot, call)
|
||||
assert isinstance(result, int)
|
||||
assert result == 42
|
||||
|
||||
assert patched_raise_for_status.called_once()
|
||||
result = await session.make_request(bot, call)
|
||||
assert isinstance(result, int)
|
||||
assert result == 42
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_content(self, aresponses: ResponsesMockServer):
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ from typing import AsyncContextManager, AsyncGenerator, Optional
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.client.session.base import BaseSession, T
|
||||
from aiogram.client.session.base import BaseSession, TelegramType
|
||||
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from aiogram.methods import GetMe, Response, TelegramMethod
|
||||
from aiogram.methods import DeleteMessage, GetMe, Response, TelegramMethod
|
||||
from aiogram.types import UNSET
|
||||
|
||||
try:
|
||||
|
|
@ -20,7 +20,7 @@ class CustomSession(BaseSession):
|
|||
async def close(self):
|
||||
pass
|
||||
|
||||
async def make_request(self, token: str, method: TelegramMethod[T], timeout: Optional[int] = UNSET) -> None: # type: ignore
|
||||
async def make_request(self, token: str, method: TelegramMethod[TelegramType], timeout: Optional[int] = UNSET) -> None: # type: ignore
|
||||
assert isinstance(token, str)
|
||||
assert isinstance(method, TelegramMethod)
|
||||
|
||||
|
|
@ -135,12 +135,20 @@ class TestBaseSession:
|
|||
|
||||
assert session.clean_json(42) == 42
|
||||
|
||||
def test_raise_for_status(self):
|
||||
def check_response(self):
|
||||
session = CustomSession()
|
||||
|
||||
session.raise_for_status(Response[bool](ok=True, result=True))
|
||||
session.check_response(
|
||||
method=DeleteMessage(chat_id=42, message_id=42),
|
||||
status_code=200,
|
||||
content='{"ok":true,"result":true}',
|
||||
)
|
||||
with pytest.raises(Exception):
|
||||
session.raise_for_status(Response[bool](ok=False, description="Error", error_code=400))
|
||||
session.check_response(
|
||||
method=DeleteMessage(chat_id=42, message_id=42),
|
||||
status_code=400,
|
||||
content='{"ok":false,"description":"test"}',
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_make_request(self):
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import pytest
|
|||
|
||||
from aiogram.methods import (
|
||||
CopyMessage,
|
||||
DeleteMessage,
|
||||
EditMessageCaption,
|
||||
EditMessageText,
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
|
|
@ -549,3 +552,28 @@ class TestMessage:
|
|||
if method:
|
||||
assert isinstance(method, expected_method)
|
||||
# TODO: Check additional fields
|
||||
|
||||
def test_edit_text(self):
|
||||
message = Message(
|
||||
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
|
||||
)
|
||||
method = message.edit_text(text="test")
|
||||
assert isinstance(method, EditMessageText)
|
||||
assert method.chat_id == message.chat.id
|
||||
|
||||
def test_edit_caption(self):
|
||||
message = Message(
|
||||
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
|
||||
)
|
||||
method = message.edit_caption(caption="test")
|
||||
assert isinstance(method, EditMessageCaption)
|
||||
assert method.chat_id == message.chat.id
|
||||
|
||||
def test_delete(self):
|
||||
message = Message(
|
||||
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
|
||||
)
|
||||
method = message.delete()
|
||||
assert isinstance(method, DeleteMessage)
|
||||
assert method.chat_id == message.chat.id
|
||||
assert method.message_id == message.message_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue