From b728e3e75022897ac3da57d52144cd71754ee52d Mon Sep 17 00:00:00 2001 From: someqst Date: Sun, 19 Apr 2026 00:43:07 +0300 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20action=20=D0=BA=D0=B0=D0=BA=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maxapi/bot.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/maxapi/bot.py b/maxapi/bot.py index a434982..054ef97 100644 --- a/maxapi/bot.py +++ b/maxapi/bot.py @@ -410,7 +410,7 @@ async def send_message( async def send_action( self, chat_id: int | None = None, - action: SenderAction = SenderAction.TYPING_ON, + action: SenderAction | str = SenderAction.TYPING_ON, ) -> SendedAction: """ Отправляет действие в чат (например, "печатает"). @@ -419,11 +419,18 @@ async def send_action( Args: chat_id (Optional[int]): ID чата. - action (SenderAction): Тип действия. + action (SenderAction | str): Тип действия. Returns: SendedAction: Результат отправки действия. """ + try: + action = SenderAction(action) + except ValueError as e: + allowed = ", ".join(item.value for item in SenderAction) + raise ValueError( + f"Неверный action: {action!r}. Ожидается: {allowed}" + ) from e return await SendAction( bot=self, chat_id=chat_id, action=action From 5b0ff98853feab48aa1a8c29589b07fbc65c2389 Mon Sep 17 00:00:00 2001 From: someqst Date: Thu, 23 Apr 2026 11:01:26 +0300 Subject: [PATCH 2/6] =?UTF-8?q?test:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20send=5Faction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_bot.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/test_bot.py b/tests/test_bot.py index 661f8a6..4c758a5 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -185,6 +185,57 @@ async def test_send_action_call(self, bot): assert mock_fetch.called + @pytest.mark.asyncio + async def test_send_invalid_action_as_string(self, bot): + """Тест вызова send_action с неверными данными.""" + # Core Stuff + from maxapi.methods.send_action import SendAction + + available_actions = ", ".join(action.value for action in SenderAction) + + with patch.object( + SendAction, "fetch", new_callable=AsyncMock + ) as mock_fetch: + mock_fetch.return_value = Mock() + + with pytest.raises(ValueError) as exc_info: # noqa: PT011 + await bot.send_action(chat_id=12345, action="fake_action") + + exc_message = str(exc_info.value) + + assert "Неверный" in exc_message + assert available_actions in exc_message + + @pytest.mark.asyncio + async def test_send_valid_action_as_string(self, bot): + """Тест вызова send_action с верными данными.""" + # Core Stuff + from maxapi.methods.send_action import SendAction + + with patch.object( + SendAction, "fetch", new_callable=AsyncMock + ) as mock_fetch: + mock_fetch.return_value = Mock() + + await bot.send_action(chat_id=12345, action="typing_on") + + assert mock_fetch.called + + @pytest.mark.asyncio + async def test_send_none_action(self, bot): + """Тест вызова send_action без передачи action""" + # Core Stuff + from maxapi.methods.send_action import SendAction + + with patch.object( + SendAction, "fetch", new_callable=AsyncMock + ) as mock_fetch: + mock_fetch.return_value = Mock() + + await bot.send_action(chat_id=12345) + + assert mock_fetch.called + @pytest.mark.asyncio async def test_get_me_structure(self, bot): """Тест структуры вызова get_me.""" From 0005cc5ef3bb63b3aac4f97e0ae699966089dc39 Mon Sep 17 00:00:00 2001 From: someqst Date: Thu, 23 Apr 2026 11:01:46 +0300 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3=D0=B0=20SenderAction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maxapi/bot.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/maxapi/bot.py b/maxapi/bot.py index 054ef97..7a2a707 100644 --- a/maxapi/bot.py +++ b/maxapi/bot.py @@ -424,13 +424,14 @@ async def send_action( Returns: SendedAction: Результат отправки действия. """ - try: - action = SenderAction(action) - except ValueError as e: - allowed = ", ".join(item.value for item in SenderAction) - raise ValueError( - f"Неверный action: {action!r}. Ожидается: {allowed}" - ) from e + if not isinstance(action, SenderAction): + try: + action = SenderAction(action) + except ValueError as e: + allowed = ", ".join(item.value for item in SenderAction) + raise ValueError( + f"Неверный action: {action!r}. Ожидается: {allowed}" + ) from e return await SendAction( bot=self, chat_id=chat_id, action=action From a911f80c2e14e2647fe4993debf9f5a8fc662590 Mon Sep 17 00:00:00 2001 From: Aleksandrov Nikita <129618584+someqst@users.noreply.github.com> Date: Fri, 1 May 2026 04:10:30 +0300 Subject: [PATCH 4/6] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tests/test_bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_bot.py b/tests/test_bot.py index 4c758a5..7244fc7 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -222,8 +222,8 @@ async def test_send_valid_action_as_string(self, bot): assert mock_fetch.called @pytest.mark.asyncio - async def test_send_none_action(self, bot): - """Тест вызова send_action без передачи action""" + async def test_send_action_without_action_param(self, bot): + """Тест вызова send_action без передачи action.""" # Core Stuff from maxapi.methods.send_action import SendAction From 72b330af43213418679ed69fef857c3d8fc3de4c Mon Sep 17 00:00:00 2001 From: someqst Date: Fri, 1 May 2026 05:28:05 +0300 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=B2=20=20SendAction.init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maxapi/bot.py | 9 --------- maxapi/methods/send_action.py | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/maxapi/bot.py b/maxapi/bot.py index 7a2a707..0828d7c 100644 --- a/maxapi/bot.py +++ b/maxapi/bot.py @@ -424,15 +424,6 @@ async def send_action( Returns: SendedAction: Результат отправки действия. """ - if not isinstance(action, SenderAction): - try: - action = SenderAction(action) - except ValueError as e: - allowed = ", ".join(item.value for item in SenderAction) - raise ValueError( - f"Неверный action: {action!r}. Ожидается: {allowed}" - ) from e - return await SendAction( bot=self, chat_id=chat_id, action=action ).fetch() diff --git a/maxapi/methods/send_action.py b/maxapi/methods/send_action.py index 54ed424..af8c748 100644 --- a/maxapi/methods/send_action.py +++ b/maxapi/methods/send_action.py @@ -21,7 +21,7 @@ class SendAction(BaseConnection): bot (Bot): Экземпляр бота для выполнения запроса. chat_id (Optional[int]): Идентификатор чата. Если None, действие не отправляется. - action (Optional[SenderAction]): Тип действия. По умолчанию + action (SenderAction | str): Тип действия. По умолчанию SenderAction.TYPING_ON. """ @@ -29,9 +29,25 @@ def __init__( self, bot: "Bot", chat_id: int | None = None, - action: SenderAction = SenderAction.TYPING_ON, + action: SenderAction | str = SenderAction.TYPING_ON, ): super().__init__() + + if not isinstance(action, SenderAction): + if not isinstance(action, str): + raise TypeError( + f"action должен быть SenderAction или str, " + f"получено: {type(action).__name__}" + ) + + try: + action = SenderAction(action) + except ValueError as e: + allowed = ", ".join(item.value for item in SenderAction) + raise ValueError( + f"Неверный action: {action!r}. Ожидается: {allowed}" + ) from e + self.bot = bot self.chat_id = chat_id self.action = action From 0b6877b80ee26c1530bf87d7eb04e9ce13e7eb43 Mon Sep 17 00:00:00 2001 From: someqst Date: Fri, 1 May 2026 05:28:49 +0300 Subject: [PATCH 6/6] =?UTF-8?q?test:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=B2=D0=B5=D1=80=D0=BD=D1=8B=D0=B9=20=D1=82=D0=B8?= =?UTF-8?q?=D0=BF=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_bot.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_bot.py b/tests/test_bot.py index 7244fc7..b388792 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -236,6 +236,27 @@ async def test_send_action_without_action_param(self, bot): assert mock_fetch.called + @pytest.mark.asyncio + async def test_send_action_with_wrong_action_type(self, bot): + """Тест вызова send_action с передачей неверного типа (не SenderAction, не str).""" # noqa: E501 + # Core Stuff + from maxapi.methods.send_action import SendAction + + with patch.object( + SendAction, "fetch", new_callable=AsyncMock + ) as mock_fetch: + mock_fetch.return_value = Mock() + + wrong_action = 123 + wrong_action_type = type(wrong_action).__name__ + + with pytest.raises(TypeError) as exc_info: + await bot.send_action(chat_id=12345, action=wrong_action) + + exc_message = str(exc_info.value) + + assert wrong_action_type in exc_message + @pytest.mark.asyncio async def test_get_me_structure(self, bot): """Тест структуры вызова get_me."""