Repository: python-telegram-bot/python-telegram-bot

Issue:
Tests missing for `User.mention_markdown` and `User.mention_html`
And while we're at it. Maybe `helpers.mention_markdown/html` too.



Discussion:

Resolving patch:
diff --git a/telegram/utils/helpers.py b/telegram/utils/helpers.py
--- a/telegram/utils/helpers.py
+++ b/telegram/utils/helpers.py
@@ -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):


Test patch:
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -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 @@ def test_effective_message_type(self):
 
         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')
diff --git a/tests/test_user.py b/tests/test_user.py
--- a/tests/test_user.py
+++ b/tests/test_user.py
@@ -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 @@ def test(*args, **kwargs):
         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&lt;b&gt;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)