Add type to User and GroupChat classes

This commit is contained in:
Leandro Toledo 2015-10-08 10:19:05 -03:00
parent 5738dc553f
commit cf5d184766
4 changed files with 19 additions and 3 deletions

View file

@ -28,18 +28,22 @@ class GroupChat(TelegramObject):
Attributes: Attributes:
id (int): id (int):
title (str): title (str):
type (str):
Args: Args:
id (int): id (int):
title (str): title (str):
type (str):
""" """
def __init__(self, def __init__(self,
id, id,
title): title,
type):
# Required # Required
self.id = int(id) self.id = int(id)
self.title = title self.title = title
self.type = type
@staticmethod @staticmethod
def de_json(data): def de_json(data):

View file

@ -30,6 +30,7 @@ class User(TelegramObject):
first_name (str): first_name (str):
last_name (str): last_name (str):
username (str): username (str):
type (str):
Args: Args:
id (int): id (int):
@ -37,6 +38,7 @@ class User(TelegramObject):
**kwargs: Arbitrary keyword arguments. **kwargs: Arbitrary keyword arguments.
Keyword Args: Keyword Args:
type (Optional[str]):
last_name (Optional[str]): last_name (Optional[str]):
username (Optional[str]): username (Optional[str]):
""" """
@ -49,6 +51,7 @@ class User(TelegramObject):
self.id = int(id) self.id = int(id)
self.first_name = first_name self.first_name = first_name
# Optionals # Optionals
self.type = kwargs.get('type', '')
self.last_name = kwargs.get('last_name', '') self.last_name = kwargs.get('last_name', '')
self.username = kwargs.get('username', '') self.username = kwargs.get('username', '')

View file

@ -33,10 +33,12 @@ class GroupChatTest(BaseTest, unittest.TestCase):
def setUp(self): def setUp(self):
self.id = -28767330 self.id = -28767330
self.title = 'ToledosPalaceBot - Group' self.title = 'ToledosPalaceBot - Group'
self.type = 'group'
self.json_dict = { self.json_dict = {
'id': self.id, 'id': self.id,
'title': self.title 'title': self.title,
'type': self.type
} }
def test_group_chat_de_json_empty_json(self): def test_group_chat_de_json_empty_json(self):
@ -55,6 +57,7 @@ class GroupChatTest(BaseTest, unittest.TestCase):
self.assertEqual(group_chat.id, self.id) self.assertEqual(group_chat.id, self.id)
self.assertEqual(group_chat.title, self.title) self.assertEqual(group_chat.title, self.title)
self.assertEqual(group_chat.type, self.type)
def test_group_chat_to_json(self): def test_group_chat_to_json(self):
"""Test GroupChat.to_json() method""" """Test GroupChat.to_json() method"""
@ -73,6 +76,7 @@ class GroupChatTest(BaseTest, unittest.TestCase):
self.assertTrue(self.is_dict(group_chat.to_dict())) self.assertTrue(self.is_dict(group_chat.to_dict()))
self.assertEqual(group_chat['id'], self.id) self.assertEqual(group_chat['id'], self.id)
self.assertEqual(group_chat['title'], self.title) self.assertEqual(group_chat['title'], self.title)
self.assertEqual(group_chat['type'], self.type)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View file

@ -35,12 +35,14 @@ class UserTest(BaseTest, unittest.TestCase):
self.first_name = "Leandro" self.first_name = "Leandro"
self.last_name = "S." self.last_name = "S."
self.username = "leandrotoledo" self.username = "leandrotoledo"
self.type = "private"
self.json_dict = { self.json_dict = {
'id': self.id, 'id': self.id,
'first_name': self.first_name, 'first_name': self.first_name,
'last_name': self.last_name, 'last_name': self.last_name,
'username': self.username 'username': self.username,
'type': self.type
} }
def test_user_de_json(self): def test_user_de_json(self):
@ -53,6 +55,7 @@ class UserTest(BaseTest, unittest.TestCase):
self.assertEqual(user.first_name, self.first_name) self.assertEqual(user.first_name, self.first_name)
self.assertEqual(user.last_name, self.last_name) self.assertEqual(user.last_name, self.last_name)
self.assertEqual(user.username, self.username) self.assertEqual(user.username, self.username)
self.assertEqual(user.type, self.type)
self.assertEqual(user.name, '@leandrotoledo') self.assertEqual(user.name, '@leandrotoledo')
@ -69,6 +72,7 @@ class UserTest(BaseTest, unittest.TestCase):
self.assertEqual(user.id, self.id) self.assertEqual(user.id, self.id)
self.assertEqual(user.first_name, self.first_name) self.assertEqual(user.first_name, self.first_name)
self.assertEqual(user.last_name, self.last_name) self.assertEqual(user.last_name, self.last_name)
self.assertEqual(user.type, self.type)
self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name)) self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name))
@ -108,6 +112,7 @@ class UserTest(BaseTest, unittest.TestCase):
self.assertEqual(user['first_name'], self.first_name) self.assertEqual(user['first_name'], self.first_name)
self.assertEqual(user['last_name'], self.last_name) self.assertEqual(user['last_name'], self.last_name)
self.assertEqual(user['username'], self.username) self.assertEqual(user['username'], self.username)
self.assertEqual(user['type'], self.type)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()