diff --git a/telegram/bot.py b/telegram/bot.py index a75771a87e1..11794a7ad88 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -1512,7 +1512,10 @@ def answer_inline_query(self, 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): diff --git a/tests/test_bot.py b/tests/test_bot.py index 1bf5756ed21..a35f773a183 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -28,7 +28,8 @@ 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 @@ def test(_, url, data, *args, **kwargs): 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):
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: