mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 06:25:12 +01:00
parent
87afd98e02
commit
42daf96d20
3 changed files with 32 additions and 5 deletions
|
@ -94,7 +94,7 @@ def mention_html(user_id, name):
|
|||
:obj:`str`: The inline mention for the user as html.
|
||||
"""
|
||||
if isinstance(user_id, int):
|
||||
return '<a href="tg://user?id={}">{}</a>'.format(user_id, escape(name))
|
||||
return u'<a href="tg://user?id={}">{}</a>'.format(user_id, escape(name))
|
||||
|
||||
|
||||
def mention_markdown(user_id, name):
|
||||
|
@ -107,7 +107,7 @@ def mention_markdown(user_id, name):
|
|||
:obj:`str`: The inline mention for the user as markdown.
|
||||
"""
|
||||
if isinstance(user_id, int):
|
||||
return '[{}](tg://user?id={})'.format(escape_markdown(name), user_id)
|
||||
return u'[{}](tg://user?id={})'.format(escape_markdown(name), user_id)
|
||||
|
||||
|
||||
def effective_message_type(entity):
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
from telegram import Update
|
||||
|
||||
from telegram import Sticker
|
||||
from telegram import Update
|
||||
from telegram import User
|
||||
from telegram.message import Message
|
||||
from telegram.utils import helpers
|
||||
|
@ -55,3 +55,13 @@ class TestHelpers(object):
|
|||
|
||||
empty_update = Update(2)
|
||||
assert helpers.effective_message_type(empty_update) is None
|
||||
|
||||
def test_mention_html(self):
|
||||
expected = '<a href="tg://user?id=1">the name</a>'
|
||||
|
||||
assert expected == helpers.mention_html(1, 'the name')
|
||||
|
||||
def test_mention_markdown(self):
|
||||
expected = '[the name](tg://user?id=1)'
|
||||
|
||||
assert expected == helpers.mention_markdown(1, 'the name')
|
||||
|
|
|
@ -35,8 +35,9 @@ def json_dict():
|
|||
|
||||
@pytest.fixture(scope='function')
|
||||
def user(bot):
|
||||
return User(TestUser.id, TestUser.first_name, TestUser.is_bot, last_name=TestUser.last_name,
|
||||
username=TestUser.username, language_code=TestUser.language_code, bot=bot)
|
||||
return User(id=TestUser.id, first_name=TestUser.first_name, is_bot=TestUser.is_bot,
|
||||
last_name=TestUser.last_name, username=TestUser.username,
|
||||
language_code=TestUser.language_code, bot=bot)
|
||||
|
||||
|
||||
class TestUser(object):
|
||||
|
@ -164,6 +165,22 @@ class TestUser(object):
|
|||
monkeypatch.setattr('telegram.Bot.send_voice', test)
|
||||
assert user.send_voice('test_voice')
|
||||
|
||||
def test_mention_html(self, user):
|
||||
expected = u'<a href="tg://user?id={}">{}</a>'
|
||||
|
||||
assert user.mention_html() == expected.format(user.id, user.full_name)
|
||||
assert user.mention_html('the<b>name\u2022') == expected.format(user.id,
|
||||
'the<b>name\u2022')
|
||||
assert user.mention_html(user.username) == expected.format(user.id, user.username)
|
||||
|
||||
def test_mention_markdown(self, user):
|
||||
expected = u'[{}](tg://user?id={})'
|
||||
|
||||
assert user.mention_markdown() == expected.format(user.full_name, user.id)
|
||||
assert user.mention_markdown('the_name*\u2022') == expected.format('the\_name\*\u2022',
|
||||
user.id)
|
||||
assert user.mention_markdown(user.username) == expected.format(user.username, user.id)
|
||||
|
||||
def test_equality(self):
|
||||
a = User(self.id, self.first_name, self.is_bot, self.last_name)
|
||||
b = User(self.id, self.first_name, self.is_bot, self.last_name)
|
||||
|
|
Loading…
Reference in a new issue