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:
sheldy 2022-11-02 22:40:19 +02:00 committed by GitHub
parent 45705faf12
commit b8cd06fd6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 1 deletions

View file

@ -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>'