Fix setting thumbs with send_media_group (#2093)

* fix: uploading thumb in media group

* add test

Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de>
This commit is contained in:
Poolitzer 2020-09-19 16:50:34 +02:00 committed by GitHub
parent 897a20d758
commit 2989108e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -317,9 +317,13 @@ class Request:
# Attach and set val to attached name for all
media = []
for m in val:
media.append(m.to_dict())
media_dict = m.to_dict()
media.append(media_dict)
if isinstance(m.media, InputFile):
data[m.media.attach] = m.media.field_tuple
# if the file has a thumb, we also need to attach it to the data
if "thumb" in media_dict:
data[m.thumb.attach] = m.thumb.field_tuple
data[key] = json.dumps(media)
files = True

View file

@ -317,6 +317,20 @@ class TestSendMediaGroup:
assert all([isinstance(mes, Message) for mes in messages])
assert all([mes.media_group_id == messages[0].media_group_id for mes in messages])
def test_send_media_group_with_thumbs(self, bot, chat_id, video_file, photo_file, # noqa: F811
monkeypatch):
def test(*args, **kwargs):
data = kwargs['fields']
video_check = data[input_video.media.attach] == input_video.media.field_tuple
thumb_check = data[input_video.thumb.attach] == input_video.thumb.field_tuple
result = video_check and thumb_check
raise(Exception('Test was {}'.format('successful' if result else 'failing')))
monkeypatch.setattr('telegram.utils.request.Request._request_wrapper', test)
input_video = InputMediaVideo(video_file, thumb=photo_file)
with pytest.raises(Exception, match='Test was successful'):
bot.send_media_group(chat_id, [input_video, input_video])
@flaky(3, 1) # noqa: F811
@pytest.mark.timeout(10) # noqa: F811
def test_send_media_group_new_files(self, bot, chat_id, video_file, photo_file, # noqa: F811