mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-15 11:25:54 +00:00
Fix send_copy helper parse mode (#1332)
* Fix send_copy helper parse mode * Add changelog for bugfix 1332
This commit is contained in:
parent
cad42580dd
commit
564292dd79
3 changed files with 44 additions and 2 deletions
1
CHANGES/1332.bugfix.rst
Normal file
1
CHANGES/1332.bugfix.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fixed ``parse_mode`` in ``send_copy`` helper. Disable by default.
|
||||
|
|
@ -2803,6 +2803,7 @@ class Message(TelegramObject):
|
|||
reply_markup: Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, None] = None,
|
||||
allow_sending_without_reply: Optional[bool] = None,
|
||||
message_thread_id: Optional[int] = None,
|
||||
parse_mode: Optional[str] = None,
|
||||
) -> Union[
|
||||
ForwardMessage,
|
||||
SendAnimation,
|
||||
|
|
@ -2837,6 +2838,7 @@ class Message(TelegramObject):
|
|||
:param reply_markup:
|
||||
:param allow_sending_without_reply:
|
||||
:param message_thread_id:
|
||||
:param parse_mode:
|
||||
:return:
|
||||
"""
|
||||
from ..methods import (
|
||||
|
|
@ -2864,6 +2866,9 @@ class Message(TelegramObject):
|
|||
"reply_to_message_id": reply_to_message_id,
|
||||
"message_thread_id": message_thread_id,
|
||||
"allow_sending_without_reply": allow_sending_without_reply,
|
||||
# when sending a copy, we don't need any parse mode
|
||||
# because all entities are already prepared
|
||||
"parse_mode": parse_mode,
|
||||
}
|
||||
|
||||
if self.text:
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from typing import Any, Dict, Optional, Type, Union
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.enums import ParseMode
|
||||
from aiogram.methods import (
|
||||
CopyMessage,
|
||||
DeleteMessage,
|
||||
|
|
@ -74,6 +75,7 @@ from aiogram.types import (
|
|||
VideoNote,
|
||||
Voice,
|
||||
WebAppData,
|
||||
UNSET_PARSE_MODE,
|
||||
)
|
||||
from aiogram.types.message import ContentType, Message
|
||||
|
||||
|
|
@ -688,10 +690,44 @@ class TestMessage:
|
|||
return
|
||||
|
||||
method = message.send_copy(chat_id=42)
|
||||
if method:
|
||||
assert isinstance(method, expected_method)
|
||||
if hasattr(method, "parse_mode"):
|
||||
# default parse mode in send_copy
|
||||
assert method.parse_mode is None
|
||||
# TODO: Check additional fields
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"custom_parse_mode",
|
||||
[
|
||||
UNSET_PARSE_MODE,
|
||||
*list(ParseMode),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"message,expected_method",
|
||||
[
|
||||
[TEST_MESSAGE_TEXT, SendMessage],
|
||||
[TEST_MESSAGE_AUDIO, SendAudio],
|
||||
[TEST_MESSAGE_ANIMATION, SendAnimation],
|
||||
[TEST_MESSAGE_DOCUMENT, SendDocument],
|
||||
[TEST_MESSAGE_PHOTO, SendPhoto],
|
||||
[TEST_MESSAGE_VIDEO, SendVideo],
|
||||
[TEST_MESSAGE_VOICE, SendVoice],
|
||||
],
|
||||
)
|
||||
def test_send_copy_custom_parse_mode(
|
||||
self,
|
||||
message: Message,
|
||||
expected_method: Optional[Type[TelegramMethod]],
|
||||
custom_parse_mode: Optional[str],
|
||||
):
|
||||
method = message.send_copy(
|
||||
chat_id=42,
|
||||
parse_mode=custom_parse_mode,
|
||||
)
|
||||
assert isinstance(method, expected_method)
|
||||
assert method.parse_mode == custom_parse_mode
|
||||
|
||||
def test_edit_text(self):
|
||||
message = Message(
|
||||
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue