Fix failing tests

This commit is contained in:
Hinrich Mahler 2024-12-30 15:18:49 +01:00
parent c5f3bf7e82
commit 0a1b976ac1
6 changed files with 49 additions and 20 deletions

View file

@ -126,5 +126,5 @@ class Gifts(TelegramObject):
"""See :meth:`telegram.TelegramObject.de_json`."""
data = cls._parse_data(data)
data["gifts"] = Gifts.de_list(data["gifts"], bot)
data["gifts"] = Gift.de_list(data["gifts"], bot)
return cls(**data)

View file

@ -8,13 +8,17 @@ from telegram import (
BotName,
BotShortDescription,
BusinessConnection,
Chat,
ChatAdministratorRights,
ChatBoost,
ChatBoostSource,
ChatFullInfo,
ChatInviteLink,
ChatMember,
File,
ForumTopic,
GameHighScore,
Gift,
Gifts,
MenuButton,
MessageId,
@ -22,6 +26,7 @@ from telegram import (
PollOption,
PreparedInlineMessage,
SentWebAppMessage,
StarTransaction,
StarTransactions,
Sticker,
StickerSet,
@ -38,6 +43,15 @@ _DUMMY_USER = User(
id=123456, is_bot=False, first_name="Dummy", last_name="User", username="dummy_user"
)
_DUMMY_DATE = dtm.datetime(1970, 1, 1, 0, 0, 0, 0, tzinfo=dtm.timezone.utc)
_DUMMY_STICKER = Sticker(
file_id="dummy_file_id",
file_unique_id="dummy_file_unique_id",
width=1,
height=1,
is_animated=False,
is_video=False,
type="dummy_type",
)
_PREPARED_DUMMY_OBJECTS: dict[str, object] = {
"bool": True,
@ -53,6 +67,7 @@ _PREPARED_DUMMY_OBJECTS: dict[str, object] = {
can_reply=True,
is_enabled=True,
),
"Chat": Chat(id=123456, type="dummy_type"),
"ChatAdministratorRights": ChatAdministratorRights.all_rights(),
"ChatFullInfo": ChatFullInfo(
id=123456,
@ -70,7 +85,7 @@ _PREPARED_DUMMY_OBJECTS: dict[str, object] = {
"ChatMember": ChatMember(user=_DUMMY_USER, status="dummy_status"),
"File": File(file_id="dummy_file_id", file_unique_id="dummy_file_unique_id"),
"ForumTopic": ForumTopic(message_thread_id=2, name="dummy_name", icon_color=1),
"Gifts": Gifts(gifts=[]),
"Gifts": Gifts(gifts=[Gift(id="dummy_id", sticker=_DUMMY_STICKER, star_count=1)]),
"GameHighScore": GameHighScore(position=1, user=_DUMMY_USER, score=1),
"int": 123456,
"MenuButton": MenuButton(type="dummy_type"),
@ -88,23 +103,29 @@ _PREPARED_DUMMY_OBJECTS: dict[str, object] = {
),
"PreparedInlineMessage": PreparedInlineMessage(id="dummy_id", expiration_date=_DUMMY_DATE),
"SentWebAppMessage": SentWebAppMessage(inline_message_id="dummy_inline_message_id"),
"StarTransactions": StarTransactions(transactions=[]),
"Sticker": Sticker(
file_id="dummy_file_id",
file_unique_id="dummy_file_unique_id",
width=1,
height=1,
is_animated=False,
is_video=False,
type="dummy_type",
"StarTransactions": StarTransactions(
transactions=[StarTransaction(id="dummy_id", amount=1, date=_DUMMY_DATE)]
),
"Sticker": _DUMMY_STICKER,
"StickerSet": StickerSet(
name="dummy_name", title="dummy_title", stickers=[], sticker_type="dummy_type"
name="dummy_name",
title="dummy_title",
stickers=[_DUMMY_STICKER],
sticker_type="dummy_type",
),
"str": "dummy_string",
"Update": Update(update_id=123456),
"User": _DUMMY_USER,
"UserChatBoosts": UserChatBoosts(boosts=[]),
"UserChatBoosts": UserChatBoosts(
boosts=[
ChatBoost(
boost_id="dummy_id",
add_date=_DUMMY_DATE,
expiration_date=_DUMMY_DATE,
source=ChatBoostSource(source="dummy_source"),
)
]
),
"UserProfilePhotos": UserProfilePhotos(total_count=1, photos=[[]]),
"WebhookInfo": WebhookInfo(
url="dummy_url",

View file

@ -105,6 +105,7 @@ from tests.auxil.pytest_classes import PytestBot, PytestExtBot, make_bot
from tests.auxil.slots import mro_slots
from .auxil.build_messages import make_message
from .auxil.dummy_objects import get_dummy_object
@pytest.fixture
@ -1625,7 +1626,7 @@ class TestBotWithoutRequest:
message = Message(
1,
dtm.datetime.utcnow(),
None,
get_dummy_object(Chat),
reply_markup=offline_bot.callback_data_cache.process_keyboard(reply_markup),
)
message._unfreeze()
@ -1639,7 +1640,7 @@ class TestBotWithoutRequest:
message_type: Message(
1,
dtm.datetime.utcnow(),
None,
get_dummy_object(Chat),
pinned_message=message,
reply_to_message=Message.de_json(message.to_dict(), offline_bot),
)
@ -1782,7 +1783,7 @@ class TestBotWithoutRequest:
message = Message(
1,
dtm.datetime.utcnow(),
None,
get_dummy_object(Chat),
reply_markup=reply_markup,
via_bot=bot.bot if self_sender else User(1, "first", False),
)

View file

@ -38,6 +38,7 @@ from telegram import (
from telegram._utils.datetime import UTC, to_timestamp
from telegram.constants import ChatBoostSources
from telegram.request import RequestData
from tests.auxil.dummy_objects import get_dummy_object_json_dict
from tests.auxil.slots import mro_slots
@ -532,7 +533,7 @@ class TestUserChatBoostsWithoutRequest(ChatBoostDefaults):
user_id = data["user_id"] == "2"
if not all((chat_id, user_id)):
pytest.fail("I got wrong parameters in post")
return data
return get_dummy_object_json_dict(UserChatBoosts)
monkeypatch.setattr(offline_bot.request, "post", make_assertion)

View file

@ -89,6 +89,7 @@ from tests.auxil.bot_method_checks import (
check_shortcut_signature,
)
from tests.auxil.build_messages import make_message
from tests.auxil.dummy_objects import get_dummy_object_json_dict
from tests.auxil.pytest_classes import PytestExtBot, PytestMessage
from tests.auxil.slots import mro_slots
@ -591,9 +592,9 @@ class TestMessageWithoutRequest(MessageTestBase):
def test_de_json_localization(self, offline_bot, raw_bot, tz_bot):
json_dict = {
"message_id": 12,
"from_user": None,
"from_user": get_dummy_object_json_dict("User"),
"date": int(dtm.datetime.now().timestamp()),
"chat": None,
"chat": get_dummy_object_json_dict("Chat"),
"edit_date": int(dtm.datetime.now().timestamp()),
}

View file

@ -47,6 +47,7 @@ from telegram import (
PreCheckoutQuery,
ReactionCount,
ReactionTypeEmoji,
ShippingAddress,
ShippingQuery,
Update,
User,
@ -158,7 +159,11 @@ params = [
{"edited_channel_post": channel_post},
{"inline_query": InlineQuery(1, User(1, "", False), "", "")},
{"chosen_inline_result": ChosenInlineResult("id", User(1, "", False), "")},
{"shipping_query": ShippingQuery("id", User(1, "", False), "", None)},
{
"shipping_query": ShippingQuery(
"id", User(1, "", False), "", ShippingAddress("", "", "", "", "", "")
)
},
{"pre_checkout_query": PreCheckoutQuery("id", User(1, "", False), "", 0, "")},
{"poll": Poll("id", "?", [PollOption(".", 1)], False, False, False, Poll.REGULAR, True)},
{