Fix send_copy helper parse mode (#1332)

* Fix send_copy helper parse mode

* Add changelog for bugfix 1332
This commit is contained in:
Suren Khorenyan 2023-10-08 18:56:30 +03:00 committed by GitHub
parent cad42580dd
commit 564292dd79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View file

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