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
|
|
@ -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