mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
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:
parent
f2459fbcf2
commit
1708980ceb
3 changed files with 27 additions and 0 deletions
1
CHANGES/1758.feature.rst
Normal file
1
CHANGES/1758.feature.rst
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Add full_name property to Contact and corresponding tests
|
||||||
|
|
@ -49,3 +49,9 @@ class Contact(TelegramObject):
|
||||||
vcard=vcard,
|
vcard=vcard,
|
||||||
**__pydantic_kwargs,
|
**__pydantic_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def full_name(self) -> str:
|
||||||
|
if self.last_name:
|
||||||
|
return f"{self.first_name} {self.last_name}"
|
||||||
|
return self.first_name
|
||||||
|
|
|
||||||
20
tests/test_api/test_types/test_contact.py
Normal file
20
tests/test_api/test_types/test_contact.py
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue