From 1708980cebc5ed61376eabf7600a831b9837713f Mon Sep 17 00:00:00 2001 From: m-xim <170838360+m-xim@users.noreply.github.com> Date: Mon, 2 Feb 2026 04:22:15 +0900 Subject: [PATCH] Add full_name property to Contact and corresponding tests (#1758) * Add full_name property to Contact and corresponding tests * Add brief description of changes --- CHANGES/1758.feature.rst | 1 + aiogram/types/contact.py | 6 ++++++ tests/test_api/test_types/test_contact.py | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 CHANGES/1758.feature.rst create mode 100644 tests/test_api/test_types/test_contact.py diff --git a/CHANGES/1758.feature.rst b/CHANGES/1758.feature.rst new file mode 100644 index 00000000..d00c4e05 --- /dev/null +++ b/CHANGES/1758.feature.rst @@ -0,0 +1 @@ +Add full_name property to Contact and corresponding tests diff --git a/aiogram/types/contact.py b/aiogram/types/contact.py index acc53765..9e7677a4 100644 --- a/aiogram/types/contact.py +++ b/aiogram/types/contact.py @@ -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 diff --git a/tests/test_api/test_types/test_contact.py b/tests/test_api/test_types/test_contact.py new file mode 100644 index 00000000..bc555809 --- /dev/null +++ b/tests/test_api/test_types/test_contact.py @@ -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