mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
add method for get user mention (#1049)
* add new method * Create 1049.feature.rst * update test_user * after black and isort using * after black and isort using * adding new tests * fix test * update tests * update test * using create_tg_link function instead of new func * Update user.py * Update aiogram/types/user.py Co-authored-by: Alex Root Junior <jroot.junior@gmail.com>
This commit is contained in:
parent
45705faf12
commit
b8cd06fd6f
3 changed files with 52 additions and 1 deletions
|
|
@ -18,3 +18,35 @@ class TestUser:
|
|||
def test_full_name(self, first: str, last: str, result: bool):
|
||||
user = User(id=42, is_bot=False, first_name=first, last_name=last)
|
||||
assert user.full_name == result
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"first,last,name",
|
||||
[
|
||||
["User", None, "bebra"],
|
||||
["", None, "telegram"],
|
||||
[" ", None, "queue🤬"],
|
||||
["User", "Name", "Alex"],
|
||||
["User", " ", "aslo "],
|
||||
[" ", " ", "telebot"],
|
||||
],
|
||||
)
|
||||
def test_get_mention_markdown(self, first: str, last: str, name: str):
|
||||
user = User(id=42, is_bot=False, first_name=first, last_name=last)
|
||||
assert user.mention_markdown() == f"[{user.full_name}](tg://user?id=42)"
|
||||
assert user.mention_markdown(name=name) == f"[{name}](tg://user?id=42)"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"first,last,name",
|
||||
[
|
||||
["User", None, "bebra"],
|
||||
["", None, "telegram"],
|
||||
[" ", None, "queue🤬"],
|
||||
["User", "Name", "Alex"],
|
||||
["User", " ", "aslo "],
|
||||
[" ", " ", "telebot"],
|
||||
],
|
||||
)
|
||||
def test_get_mention_html(self, first: str, last: str, name: str):
|
||||
user = User(id=42, is_bot=False, first_name=first, last_name=last)
|
||||
assert user.mention_html() == f'<a href="tg://user?id=42">{user.full_name}</a>'
|
||||
assert user.mention_html(name=name) == f'<a href="tg://user?id=42">{name}</a>'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue