Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
64 changes: 63 additions & 1 deletion tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy