some test maintainence in test_bot.py

This commit is contained in:
Harshil 2024-05-22 08:25:50 -04:00
parent cb5425652d
commit 8404481254
No known key found for this signature in database
GPG key ID: 4AC061E441A1F727

View file

@ -86,7 +86,7 @@ from telegram.constants import (
ParseMode,
ReactionEmoji,
)
from telegram.error import BadRequest, EndPointNotFound, InvalidToken, NetworkError
from telegram.error import BadRequest, EndPointNotFound, InvalidToken
from telegram.ext import ExtBot, InvalidCallbackData
from telegram.helpers import escape_markdown
from telegram.request import BaseRequest, HTTPXRequest, RequestData
@ -2118,6 +2118,19 @@ class TestBotWithoutRequest:
obj = await bot.get_business_connection(business_connection_id=bci)
assert isinstance(obj, BusinessConnection)
async def test_send_chat_action_all_args(self, bot, chat_id, monkeypatch):
async def make_assertion(*args, **_):
kwargs = args[1]
return (
kwargs["chat_id"] == chat_id
and kwargs["action"] == "action"
and kwargs["message_thread_id"] == 1
and kwargs["business_connection_id"] == 3
)
monkeypatch.setattr(bot, "_post", make_assertion)
assert await bot.send_chat_action(chat_id, "action", 1, 3)
class TestBotWithRequest:
"""
@ -2209,8 +2222,6 @@ class TestBotWithRequest:
async def test_delete_message(self, bot, chat_id):
message = await bot.send_message(chat_id, text="will be deleted")
await asyncio.sleep(2)
assert await bot.delete_message(chat_id=chat_id, message_id=message.message_id) is True
async def test_delete_message_old_message(self, bot, chat_id):
@ -2223,9 +2234,9 @@ class TestBotWithRequest:
# test modules. No need to duplicate here.
async def test_delete_messages(self, bot, chat_id):
msg1 = await bot.send_message(chat_id, text="will be deleted")
msg2 = await bot.send_message(chat_id, text="will be deleted")
await asyncio.sleep(2)
msg1 = bot.send_message(chat_id, text="will be deleted")
msg2 = bot.send_message(chat_id, text="will be deleted")
msg1, msg2 = await asyncio.gather(msg1, msg2)
assert await bot.delete_messages(chat_id=chat_id, message_ids=(msg1.id, msg2.id)) is True
@ -2298,18 +2309,6 @@ class TestBotWithRequest:
assert message.contact.last_name == last_name
assert message.has_protected_content
async def test_send_chat_action_all_args(self, bot, chat_id, monkeypatch):
async def make_assertion(*args, **_):
kwargs = args[1]
return (
kwargs["chat_id"] == chat_id
and kwargs["action"] == "action"
and kwargs["message_thread_id"] == 1
)
monkeypatch.setattr(bot, "_post", make_assertion)
assert await bot.send_chat_action(chat_id, "action", 1)
# TODO: Add bot to group to test polls too
@pytest.mark.parametrize(
"reply_markup",
@ -2914,9 +2913,6 @@ class TestBotWithRequest:
with pytest.raises(BadRequest, match="Chat not found"):
await bot.leave_chat(-123456)
with pytest.raises(NetworkError, match="Chat not found"):
await bot.leave_chat(-123456)
async def test_get_chat(self, bot, super_group_id):
chat = await bot.get_chat(super_group_id)
assert chat.type == "supergroup"