From fb9a48251bcc15f23f6f663e4c993a8cc7771f09 Mon Sep 17 00:00:00 2001 From: m-xim <170838360+m-xim@users.noreply.github.com> Date: Sat, 31 Jan 2026 13:56:22 +0300 Subject: [PATCH] Add full_name property to Contact and corresponding tests --- aiogram/types/contact.py | 6 ++++++ tests/test_api/test_types/test_contact.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/test_api/test_types/test_contact.py 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