From 79c59ca1fd5df45c228457eefc971cbc0f30f72e Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sat, 26 Jul 2025 16:25:45 +0200 Subject: [PATCH 1/2] Test `send_paid_media` Without Request --- .../4879.kABAi45KpR2H6jqJu6NtDS.toml | 5 ++ tests/_files/test_inputmedia.py | 52 ++++++++++++------- 2 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml diff --git a/changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml b/changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml new file mode 100644 index 00000000000..66ad9fb7d77 --- /dev/null +++ b/changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml @@ -0,0 +1,5 @@ +internal = "Address Failing Unit Test for ``send_paid_media`` by Skipping Request to Bot API" + +[[pull_requests]] +uid = "4879" +author_uid = "Bibo-Joshi" diff --git a/tests/_files/test_inputmedia.py b/tests/_files/test_inputmedia.py index 08bdf3428a3..2238efabaa3 100644 --- a/tests/_files/test_inputmedia.py +++ b/tests/_files/test_inputmedia.py @@ -38,7 +38,7 @@ MessageEntity, ReplyParameters, ) -from telegram.constants import InputMediaType, ParseMode +from telegram.constants import InputMediaType, InputPaidMediaType, ParseMode from telegram.error import BadRequest from telegram.request import RequestData from telegram.warnings import PTBDeprecationWarning @@ -859,6 +859,39 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs): chat_id, media_group, reply_parameters=ReplyParameters(**kwargs) ) + async def test_send_paid_media(self, bot, channel_id, photo_file, video_file, monkeypatch): + # Actually making the request started returning BadRequest at some point with an unclear + # error message, so we just check that we pass the correct parameters to the request now + async def make_assertion(url, request_data: RequestData, *args, **kwargs): + assert request_data.parameters["star_count"] == 20 + assert len(request_data.multipart_data) == 2 + assert request_data.parameters["caption"] == "bye onlyfans" + assert request_data.parameters["show_caption_above_media"] is True + + media = request_data.parameters["media"] + mpd = request_data.multipart_data + assert media[0]["type"] == InputPaidMediaType.PHOTO + attach_photo = media[0]["media"].replace("attach://", "") + assert mpd.pop(attach_photo)[0] == "telegram.jpg" + assert media[1]["type"] == InputPaidMediaType.VIDEO + attach_video = media[1]["media"].replace("attach://", "") + assert mpd.pop(attach_video)[0] == "telegram.mp4" + assert mpd == {} + + return make_message("dummy reply").to_dict() + + monkeypatch.setattr(bot.request, "post", make_assertion) + await bot.send_paid_media( + chat_id=channel_id, + star_count=20, + media=[ + InputPaidMediaPhoto(media=photo_file), + InputPaidMediaVideo(media=video_file), + ], + caption="bye onlyfans", + show_caption_above_media=True, + ) + class CustomSequence(Sequence): def __init__(self, items): @@ -1239,20 +1272,3 @@ def build_media(parse_mode, med_type): assert message.caption_entities == () # make sure that the media was not modified assert media.parse_mode == copied_media.parse_mode - - async def test_send_paid_media(self, bot, channel_id, photo_file, video_file): - msg = await bot.send_paid_media( - chat_id=channel_id, - star_count=20, - media=[ - InputPaidMediaPhoto(media=photo_file), - InputPaidMediaVideo(media=video_file), - ], - caption="bye onlyfans", - show_caption_above_media=True, - ) - - assert isinstance(msg, Message) - assert msg.caption == "bye onlyfans" - assert msg.show_caption_above_media - assert msg.paid_media.star_count == 20 From 1354c7eecdc8ec411a6c0ff5ce48c784163d02f8 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sat, 26 Jul 2025 17:09:29 +0200 Subject: [PATCH 2/2] Revert & just change the chatid --- .../4879.kABAi45KpR2H6jqJu6NtDS.toml | 2 +- tests/_files/test_inputmedia.py | 52 +++++++------------ 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml b/changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml index 66ad9fb7d77..f1fcabc5453 100644 --- a/changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml +++ b/changes/unreleased/4879.kABAi45KpR2H6jqJu6NtDS.toml @@ -1,4 +1,4 @@ -internal = "Address Failing Unit Test for ``send_paid_media`` by Skipping Request to Bot API" +internal = "Address Failing Unit Test for ``send_paid_media``" [[pull_requests]] uid = "4879" diff --git a/tests/_files/test_inputmedia.py b/tests/_files/test_inputmedia.py index 2238efabaa3..57bf8609f19 100644 --- a/tests/_files/test_inputmedia.py +++ b/tests/_files/test_inputmedia.py @@ -38,7 +38,7 @@ MessageEntity, ReplyParameters, ) -from telegram.constants import InputMediaType, InputPaidMediaType, ParseMode +from telegram.constants import InputMediaType, ParseMode from telegram.error import BadRequest from telegram.request import RequestData from telegram.warnings import PTBDeprecationWarning @@ -859,39 +859,6 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs): chat_id, media_group, reply_parameters=ReplyParameters(**kwargs) ) - async def test_send_paid_media(self, bot, channel_id, photo_file, video_file, monkeypatch): - # Actually making the request started returning BadRequest at some point with an unclear - # error message, so we just check that we pass the correct parameters to the request now - async def make_assertion(url, request_data: RequestData, *args, **kwargs): - assert request_data.parameters["star_count"] == 20 - assert len(request_data.multipart_data) == 2 - assert request_data.parameters["caption"] == "bye onlyfans" - assert request_data.parameters["show_caption_above_media"] is True - - media = request_data.parameters["media"] - mpd = request_data.multipart_data - assert media[0]["type"] == InputPaidMediaType.PHOTO - attach_photo = media[0]["media"].replace("attach://", "") - assert mpd.pop(attach_photo)[0] == "telegram.jpg" - assert media[1]["type"] == InputPaidMediaType.VIDEO - attach_video = media[1]["media"].replace("attach://", "") - assert mpd.pop(attach_video)[0] == "telegram.mp4" - assert mpd == {} - - return make_message("dummy reply").to_dict() - - monkeypatch.setattr(bot.request, "post", make_assertion) - await bot.send_paid_media( - chat_id=channel_id, - star_count=20, - media=[ - InputPaidMediaPhoto(media=photo_file), - InputPaidMediaVideo(media=video_file), - ], - caption="bye onlyfans", - show_caption_above_media=True, - ) - class CustomSequence(Sequence): def __init__(self, items): @@ -1272,3 +1239,20 @@ def build_media(parse_mode, med_type): assert message.caption_entities == () # make sure that the media was not modified assert media.parse_mode == copied_media.parse_mode + + async def test_send_paid_media(self, bot, chat_id, photo_file, video_file): + msg = await bot.send_paid_media( + chat_id=chat_id, + star_count=20, + media=[ + InputPaidMediaPhoto(media=photo_file), + InputPaidMediaVideo(media=video_file), + ], + caption="bye onlyfans", + show_caption_above_media=True, + ) + + assert isinstance(msg, Message) + assert msg.caption == "bye onlyfans" + assert msg.show_caption_above_media + assert msg.paid_media.star_count == 20
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: