mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added support for Telegram Bot API 9.5 (#1780)
* Update API methods and types for Telegram Bot API 9.5 * Draft: follow-up for Bot API 9.5 (#1780) (#1781) * Add set_chat_member_tag shortcut coverage * Add set_member_tag shortcut tests and align decoration expectations * Fix follow-up test coverage for sender_tag and can_edit_tag * Add changelog fragment for PR 1781 * Align changelog with base PR #1780 * Expand 1780 changelog to cover base and follow-up scope * Treat sender_tag as metadata, not message content type --------- Co-authored-by: Latand <latand@users.noreply.github.com> Co-authored-by: Codex Agent <codex@openclaw.local> * Add tests for date_time formatting with Unix time and datetime objects * Update changelog with Telegram Bot API 9.5 changes --------- Co-authored-by: Kostiantyn Kriuchkov <36363097+Latand@users.noreply.github.com> Co-authored-by: Latand <latand@users.noreply.github.com> Co-authored-by: Codex Agent <codex@openclaw.local>
This commit is contained in:
parent
73710acb4c
commit
f68c24d620
52 changed files with 872 additions and 79 deletions
|
|
@ -6,6 +6,11 @@ class TestPromoteChatMember:
|
|||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(PromoteChatMember, ok=True, result=True)
|
||||
|
||||
response: bool = await bot.promote_chat_member(chat_id=-42, user_id=42)
|
||||
bot.get_request()
|
||||
response: bool = await bot.promote_chat_member(
|
||||
chat_id=-42,
|
||||
user_id=42,
|
||||
can_manage_tags=True,
|
||||
)
|
||||
request = bot.get_request()
|
||||
assert request.can_manage_tags is True
|
||||
assert response == prepare_result.result
|
||||
|
|
|
|||
14
tests/test_api/test_methods/test_set_chat_member_tag.py
Normal file
14
tests/test_api/test_methods/test_set_chat_member_tag.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from aiogram.methods import SetChatMemberTag
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
class TestSetChatMemberTag:
|
||||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(SetChatMemberTag, ok=True, result=True)
|
||||
|
||||
response: bool = await bot.set_chat_member_tag(chat_id=-42, user_id=42, tag="test")
|
||||
request = bot.get_request()
|
||||
assert request.chat_id == -42
|
||||
assert request.user_id == 42
|
||||
assert request.tag == "test"
|
||||
assert response == prepare_result.result
|
||||
|
|
@ -115,6 +115,14 @@ class TestChat:
|
|||
method = chat.set_administrator_custom_title(user_id=1, custom_title="test")
|
||||
assert method.chat_id == chat.id
|
||||
|
||||
def test_set_member_tag(self):
|
||||
chat = Chat(id=-42, type="supergroup")
|
||||
|
||||
method = chat.set_member_tag(user_id=42, tag="test")
|
||||
assert method.chat_id == chat.id
|
||||
assert method.user_id == 42
|
||||
assert method.tag == "test"
|
||||
|
||||
def test_set_permissions(self):
|
||||
chat = Chat(id=-42, type="supergroup")
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
from datetime import datetime
|
||||
|
||||
from aiogram.types import (
|
||||
ChatAdministratorRights,
|
||||
ChatMemberAdministrator,
|
||||
ChatMemberMember,
|
||||
ChatMemberRestricted,
|
||||
ChatPermissions,
|
||||
User,
|
||||
)
|
||||
|
||||
|
||||
class TestChatMemberTagPermissions:
|
||||
def test_chat_administrator_rights_can_manage_tags(self):
|
||||
rights = ChatAdministratorRights(
|
||||
is_anonymous=False,
|
||||
can_manage_chat=True,
|
||||
can_delete_messages=True,
|
||||
can_manage_video_chats=True,
|
||||
can_restrict_members=True,
|
||||
can_promote_members=True,
|
||||
can_change_info=True,
|
||||
can_invite_users=True,
|
||||
can_post_stories=True,
|
||||
can_edit_stories=True,
|
||||
can_delete_stories=True,
|
||||
can_manage_tags=True,
|
||||
)
|
||||
assert rights.can_manage_tags is True
|
||||
|
||||
def test_chat_member_administrator_can_manage_tags(self):
|
||||
admin = ChatMemberAdministrator(
|
||||
user=User(id=42, is_bot=False, first_name="User"),
|
||||
can_be_edited=True,
|
||||
is_anonymous=False,
|
||||
can_manage_chat=True,
|
||||
can_delete_messages=True,
|
||||
can_manage_video_chats=True,
|
||||
can_restrict_members=True,
|
||||
can_promote_members=True,
|
||||
can_change_info=True,
|
||||
can_invite_users=True,
|
||||
can_post_stories=True,
|
||||
can_edit_stories=True,
|
||||
can_delete_stories=True,
|
||||
can_manage_tags=True,
|
||||
)
|
||||
assert admin.can_manage_tags is True
|
||||
|
||||
def test_chat_permissions_can_edit_tag(self):
|
||||
permissions = ChatPermissions(can_edit_tag=True)
|
||||
assert permissions.can_edit_tag is True
|
||||
|
||||
def test_chat_member_member_tag(self):
|
||||
member = ChatMemberMember(
|
||||
user=User(id=42, is_bot=False, first_name="User"),
|
||||
tag="premium",
|
||||
)
|
||||
assert member.tag == "premium"
|
||||
|
||||
def test_chat_member_restricted_can_edit_tag_and_tag(self):
|
||||
restricted = ChatMemberRestricted(
|
||||
user=User(id=42, is_bot=False, first_name="User"),
|
||||
is_member=True,
|
||||
can_send_messages=True,
|
||||
can_send_audios=True,
|
||||
can_send_documents=True,
|
||||
can_send_photos=True,
|
||||
can_send_videos=True,
|
||||
can_send_video_notes=True,
|
||||
can_send_voice_notes=True,
|
||||
can_send_polls=True,
|
||||
can_send_other_messages=True,
|
||||
can_add_web_page_previews=True,
|
||||
can_edit_tag=True,
|
||||
can_change_info=True,
|
||||
can_invite_users=True,
|
||||
can_pin_messages=True,
|
||||
can_manage_topics=True,
|
||||
until_date=datetime.now(),
|
||||
tag="premium",
|
||||
)
|
||||
assert restricted.can_edit_tag is True
|
||||
assert restricted.tag == "premium"
|
||||
|
|
@ -314,6 +314,7 @@ class TestChatMemberUpdatedStatusFilter:
|
|||
"can_send_polls": True,
|
||||
"can_send_other_messages": True,
|
||||
"can_add_web_page_previews": True,
|
||||
"can_edit_tag": True,
|
||||
"can_post_stories": True,
|
||||
"can_edit_stories": True,
|
||||
"can_delete_stories": True,
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ CHAT_MEMBER_RESTRICTED = ChatMemberRestricted(
|
|||
can_send_polls=False,
|
||||
can_send_other_messages=False,
|
||||
can_add_web_page_previews=False,
|
||||
can_edit_tag=False,
|
||||
can_change_info=False,
|
||||
can_invite_users=False,
|
||||
can_pin_messages=False,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.enums import MessageEntityType
|
||||
|
|
@ -9,6 +11,7 @@ from aiogram.utils.formatting import (
|
|||
CashTag,
|
||||
Code,
|
||||
CustomEmoji,
|
||||
DateTime,
|
||||
Email,
|
||||
ExpandableBlockQuote,
|
||||
HashTag,
|
||||
|
|
@ -93,7 +96,7 @@ class TestNode:
|
|||
],
|
||||
[
|
||||
Pre("test", language="python"),
|
||||
'<pre><code class="language-python">test</code></pre>',
|
||||
'<pre><code language="language-python">test</code></pre>',
|
||||
],
|
||||
[
|
||||
TextLink("test", url="https://example.com"),
|
||||
|
|
@ -105,7 +108,7 @@ class TestNode:
|
|||
],
|
||||
[
|
||||
CustomEmoji("test", custom_emoji_id="42"),
|
||||
'<tg-emoji emoji-id="42">test</tg-emoji>',
|
||||
'<tg-emoji emoji_id="42">test</tg-emoji>',
|
||||
],
|
||||
[
|
||||
BlockQuote("test"),
|
||||
|
|
@ -115,6 +118,14 @@ class TestNode:
|
|||
ExpandableBlockQuote("test"),
|
||||
"<blockquote expandable>test</blockquote>",
|
||||
],
|
||||
[
|
||||
DateTime("test", unix_time=42, date_time_format="yMd"),
|
||||
'<tg-time unix="42" format="yMd">test</tg-time>',
|
||||
],
|
||||
[
|
||||
DateTime("test", unix_time=42),
|
||||
'<tg-time unix="42">test</tg-time>',
|
||||
],
|
||||
],
|
||||
)
|
||||
def test_render_plain_only(self, node: Text, result: str):
|
||||
|
|
@ -358,6 +369,38 @@ class TestUtils:
|
|||
assert isinstance(node, Bold)
|
||||
assert node._body == ("test",)
|
||||
|
||||
def test_apply_entity_date_time(self):
|
||||
node = _apply_entity(
|
||||
MessageEntity(
|
||||
type=MessageEntityType.DATE_TIME,
|
||||
offset=0,
|
||||
length=4,
|
||||
unix_time=42,
|
||||
date_time_format="yMd",
|
||||
),
|
||||
"test",
|
||||
)
|
||||
assert isinstance(node, DateTime)
|
||||
assert node._body == ("test",)
|
||||
assert node._params["unix_time"] == 42
|
||||
assert node._params["date_time_format"] == "yMd"
|
||||
|
||||
def test_date_time_with_datetime_object(self):
|
||||
dt = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
|
||||
node = DateTime("test", unix_time=dt)
|
||||
assert isinstance(node, DateTime)
|
||||
assert node._params["unix_time"] == 1704067200
|
||||
|
||||
def test_date_time_with_datetime_and_format(self):
|
||||
dt = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
|
||||
node = DateTime("test", unix_time=dt, date_time_format="yMd")
|
||||
assert node._params["unix_time"] == 1704067200
|
||||
assert node._params["date_time_format"] == "yMd"
|
||||
|
||||
def test_date_time_as_markdown(self):
|
||||
node = DateTime("test", unix_time=42, date_time_format="yMd")
|
||||
assert node.as_markdown() == ""
|
||||
|
||||
def test_as_line(self):
|
||||
node = as_line("test", "test", "test")
|
||||
assert isinstance(node, Text)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.types import MessageEntity, User
|
||||
|
|
@ -25,7 +27,7 @@ class TestTextDecoration:
|
|||
[
|
||||
html_decoration,
|
||||
MessageEntity(type="pre", offset=0, length=5, language="python"),
|
||||
'<pre><code class="language-python">test</code></pre>',
|
||||
'<pre><code language="language-python">test</code></pre>',
|
||||
],
|
||||
[html_decoration, MessageEntity(type="underline", offset=0, length=5), "<u>test</u>"],
|
||||
[
|
||||
|
|
@ -57,7 +59,7 @@ class TestTextDecoration:
|
|||
[
|
||||
html_decoration,
|
||||
MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"),
|
||||
'<tg-emoji emoji-id="42">test</tg-emoji>',
|
||||
'<tg-emoji emoji_id="42">test</tg-emoji>',
|
||||
],
|
||||
[
|
||||
html_decoration,
|
||||
|
|
@ -74,6 +76,17 @@ class TestTextDecoration:
|
|||
MessageEntity(type="expandable_blockquote", offset=0, length=5),
|
||||
"<blockquote expandable>test</blockquote>",
|
||||
],
|
||||
[
|
||||
html_decoration,
|
||||
MessageEntity(
|
||||
type="date_time",
|
||||
offset=0,
|
||||
length=5,
|
||||
unix_time=42,
|
||||
date_time_format="yMd",
|
||||
),
|
||||
'<tg-time unix="42" format="yMd">test</tg-time>',
|
||||
],
|
||||
[markdown_decoration, MessageEntity(type="bold", offset=0, length=5), "*test*"],
|
||||
[markdown_decoration, MessageEntity(type="italic", offset=0, length=5), "_\rtest_\r"],
|
||||
[markdown_decoration, MessageEntity(type="code", offset=0, length=5), "`test`"],
|
||||
|
|
@ -102,7 +115,7 @@ class TestTextDecoration:
|
|||
[
|
||||
markdown_decoration,
|
||||
MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"),
|
||||
"",
|
||||
"",
|
||||
],
|
||||
[
|
||||
markdown_decoration,
|
||||
|
|
@ -124,6 +137,27 @@ class TestTextDecoration:
|
|||
MessageEntity(type="expandable_blockquote", offset=0, length=5),
|
||||
">test||",
|
||||
],
|
||||
[
|
||||
markdown_decoration,
|
||||
MessageEntity(
|
||||
type="date_time",
|
||||
offset=0,
|
||||
length=5,
|
||||
unix_time=42,
|
||||
date_time_format="yMd",
|
||||
),
|
||||
"",
|
||||
],
|
||||
[
|
||||
html_decoration,
|
||||
MessageEntity(type="date_time", offset=0, length=5, unix_time=42),
|
||||
'<tg-time unix="42">test</tg-time>',
|
||||
],
|
||||
[
|
||||
markdown_decoration,
|
||||
MessageEntity(type="date_time", offset=0, length=5, unix_time=42),
|
||||
"",
|
||||
],
|
||||
],
|
||||
)
|
||||
def test_apply_single_entity(
|
||||
|
|
@ -131,6 +165,38 @@ class TestTextDecoration:
|
|||
):
|
||||
assert decorator.apply_entity(entity, "test") == result
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"decorator,date_time_format,expected",
|
||||
[
|
||||
(
|
||||
html_decoration,
|
||||
None,
|
||||
'<tg-time unix="1704067200">test</tg-time>',
|
||||
),
|
||||
(
|
||||
html_decoration,
|
||||
"yMd",
|
||||
'<tg-time unix="1704067200" format="yMd">test</tg-time>',
|
||||
),
|
||||
(
|
||||
markdown_decoration,
|
||||
None,
|
||||
"",
|
||||
),
|
||||
(
|
||||
markdown_decoration,
|
||||
"yMd",
|
||||
"",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_date_time_with_datetime_object(
|
||||
self, decorator: TextDecoration, date_time_format: str | None, expected: str
|
||||
):
|
||||
dt = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
|
||||
result = decorator.date_time("test", unix_time=dt, date_time_format=date_time_format)
|
||||
assert result == expected
|
||||
|
||||
def test_unknown_apply_entity(self):
|
||||
assert (
|
||||
html_decoration.apply_entity(
|
||||
|
|
@ -296,6 +362,22 @@ class TestTextDecoration:
|
|||
],
|
||||
"<b>test@example.com</b>",
|
||||
],
|
||||
[
|
||||
html_decoration,
|
||||
"test",
|
||||
[MessageEntity(type="date_time", offset=0, length=4, unix_time=42)],
|
||||
'<tg-time unix="42">test</tg-time>',
|
||||
],
|
||||
[
|
||||
html_decoration,
|
||||
"test",
|
||||
[
|
||||
MessageEntity(
|
||||
type="date_time", offset=0, length=4, unix_time=42, date_time_format="yMd"
|
||||
)
|
||||
],
|
||||
'<tg-time unix="42" format="yMd">test</tg-time>',
|
||||
],
|
||||
],
|
||||
)
|
||||
def test_unparse(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue