Pass correct parse_mode to InlineResults if bot.defaults is None (#1763)

* Pass correct parse_mode to InlineResults if bot.defaults is None

* Add tests for inlinequeryresults with (default)parse_mode

* enhance tests
This commit is contained in:
Bibo-Joshi 2020-02-08 17:52:23 +01:00 committed by GitHub
parent bd1b2fb6c1
commit 6da529c46b
2 changed files with 67 additions and 2 deletions

View file

@ -1512,7 +1512,10 @@ class Bot(TelegramObject):
for res in results:
if res._has_parse_mode and res.parse_mode == DEFAULT_NONE:
res.parse_mode = self.defaults.parse_mode
if self.defaults:
res.parse_mode = self.defaults.parse_mode
else:
res.parse_mode = None
if res._has_input_message_content and res.input_message_content:
if (res.input_message_content._has_parse_mode
and res.input_message_content.parse_mode == DEFAULT_NONE):

View file

@ -28,7 +28,8 @@ from future.utils import string_types
from telegram import (Bot, Update, ChatAction, TelegramError, User, InlineKeyboardMarkup,
InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent,
ShippingOption, LabeledPrice, ChatPermissions, Poll)
ShippingOption, LabeledPrice, ChatPermissions, Poll,
InlineQueryResultDocument)
from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter
from telegram.utils.helpers import from_timestamp, escape_markdown
@ -237,6 +238,67 @@ class TestBot(object):
switch_pm_text='switch pm',
switch_pm_parameter='start_pm')
def test_answer_inline_query_no_default_parse_mode(self, monkeypatch, bot):
def test(_, url, data, *args, **kwargs):
return data == {'cache_time': 300,
'results': [{'title': 'test_result', 'id': '123', 'type': 'document',
'document_url': 'https://raw.githubusercontent.com/'
'python-telegram-bot/logos/master/logo/png/'
'ptb-logo_240.png', 'mime_type': 'image/png',
'caption': 'ptb_logo'}],
'next_offset': '42', 'switch_pm_parameter': 'start_pm',
'inline_query_id': 1234, 'is_personal': True,
'switch_pm_text': 'switch pm'}
monkeypatch.setattr('telegram.utils.request.Request.post', test)
results = [InlineQueryResultDocument(
id='123',
document_url='https://raw.githubusercontent.com/python-telegram-bot/logos/master/'
'logo/png/ptb-logo_240.png',
title='test_result',
mime_type='image/png',
caption='ptb_logo',
)]
assert bot.answer_inline_query(1234,
results=results,
cache_time=300,
is_personal=True,
next_offset='42',
switch_pm_text='switch pm',
switch_pm_parameter='start_pm')
@pytest.mark.parametrize('default_bot', [{'parse_mode': 'Markdown'}], indirect=True)
def test_answer_inline_query_default_parse_mode(self, monkeypatch, default_bot):
def test(_, url, data, *args, **kwargs):
return data == {'cache_time': 300,
'results': [{'title': 'test_result', 'id': '123', 'type': 'document',
'document_url': 'https://raw.githubusercontent.com/'
'python-telegram-bot/logos/master/logo/png/'
'ptb-logo_240.png', 'mime_type': 'image/png',
'caption': 'ptb_logo', 'parse_mode': 'Markdown'}],
'next_offset': '42', 'switch_pm_parameter': 'start_pm',
'inline_query_id': 1234, 'is_personal': True,
'switch_pm_text': 'switch pm'}
monkeypatch.setattr('telegram.utils.request.Request.post', test)
results = [InlineQueryResultDocument(
id='123',
document_url='https://raw.githubusercontent.com/python-telegram-bot/logos/master/'
'logo/png/ptb-logo_240.png',
title='test_result',
mime_type='image/png',
caption='ptb_logo',
)]
assert default_bot.answer_inline_query(1234,
results=results,
cache_time=300,
is_personal=True,
next_offset='42',
switch_pm_text='switch pm',
switch_pm_parameter='start_pm')
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_get_user_profile_photos(self, bot, chat_id):