User.full_name convinience property (#949)

Fixes #943
This commit is contained in:
graynk 2017-12-30 18:13:06 +05:00 committed by Noam Meltzer
parent 5c8470e552
commit d347c0d45e
2 changed files with 16 additions and 0 deletions

View file

@ -83,6 +83,17 @@ class User(TelegramObject):
return '%s %s' % (self.first_name, self.last_name)
return self.first_name
@property
def full_name(self):
"""
:obj:`str`: The users :attr:`first_name` and if present :attr:`last_name`.
"""
if self.last_name:
return '%s %s' % (self.first_name, self.last_name)
return self.first_name
@classmethod
def de_json(cls, data, bot):
if not data:

View file

@ -90,6 +90,11 @@ class TestUser(object):
assert user.name == 'first_name'
user.username = self.username
assert user.name == '@username'
def test_full_name(self, user):
assert user.full_name == 'first_name last_name'
user.last_name = None
assert user.full_name == 'first_name'
def test_get_profile_photos(self, monkeypatch, user):
def test(_, *args, **kwargs):