Add full_name property to Contact and corresponding tests (#1758)

* Add full_name property to Contact and corresponding tests

* Add brief description of changes
This commit is contained in:
m-xim 2026-02-02 04:22:15 +09:00 committed by GitHub
parent f2459fbcf2
commit 1708980ceb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 0 deletions

1
CHANGES/1758.feature.rst Normal file
View file

@ -0,0 +1 @@
Add full_name property to Contact and corresponding tests

View file

@ -49,3 +49,9 @@ class Contact(TelegramObject):
vcard=vcard,
**__pydantic_kwargs,
)
@property
def full_name(self) -> str:
if self.last_name:
return f"{self.first_name} {self.last_name}"
return self.first_name

View file

@ -0,0 +1,20 @@
import pytest
from aiogram.types import Contact
class TestContact:
@pytest.mark.parametrize(
"first,last,result",
[
["User", None, "User"],
["", None, ""],
[" ", None, " "],
["User", "Name", "User Name"],
["User", " ", "User "],
[" ", " ", " "],
],
)
def test_full_name(self, first: str, last: str, result: bool):
contact = Contact(phone_number="911", first_name=first, last_name=last)
assert contact.full_name == result