From cf5d1847667311c5a2ca8b5c3b6f133cc8397c2c Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Thu, 8 Oct 2015 10:19:05 -0300 Subject: [PATCH] Add type to User and GroupChat classes --- telegram/groupchat.py | 6 +++++- telegram/user.py | 3 +++ tests/test_groupchat.py | 6 +++++- tests/test_user.py | 7 ++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/telegram/groupchat.py b/telegram/groupchat.py index 1b3fac8df..1f41af0f6 100644 --- a/telegram/groupchat.py +++ b/telegram/groupchat.py @@ -28,18 +28,22 @@ class GroupChat(TelegramObject): Attributes: id (int): title (str): + type (str): Args: id (int): title (str): + type (str): """ def __init__(self, id, - title): + title, + type): # Required self.id = int(id) self.title = title + self.type = type @staticmethod def de_json(data): diff --git a/telegram/user.py b/telegram/user.py index 4cff942b5..4fa88295a 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -30,6 +30,7 @@ class User(TelegramObject): first_name (str): last_name (str): username (str): + type (str): Args: id (int): @@ -37,6 +38,7 @@ class User(TelegramObject): **kwargs: Arbitrary keyword arguments. Keyword Args: + type (Optional[str]): last_name (Optional[str]): username (Optional[str]): """ @@ -49,6 +51,7 @@ class User(TelegramObject): self.id = int(id) self.first_name = first_name # Optionals + self.type = kwargs.get('type', '') self.last_name = kwargs.get('last_name', '') self.username = kwargs.get('username', '') diff --git a/tests/test_groupchat.py b/tests/test_groupchat.py index 6fb4d74d7..2bde9700a 100644 --- a/tests/test_groupchat.py +++ b/tests/test_groupchat.py @@ -33,10 +33,12 @@ class GroupChatTest(BaseTest, unittest.TestCase): def setUp(self): self.id = -28767330 self.title = 'ToledosPalaceBot - Group' + self.type = 'group' self.json_dict = { 'id': self.id, - 'title': self.title + 'title': self.title, + 'type': self.type } 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.title, self.title) + self.assertEqual(group_chat.type, self.type) def test_group_chat_to_json(self): """Test GroupChat.to_json() method""" @@ -73,6 +76,7 @@ class GroupChatTest(BaseTest, unittest.TestCase): self.assertTrue(self.is_dict(group_chat.to_dict())) self.assertEqual(group_chat['id'], self.id) self.assertEqual(group_chat['title'], self.title) + self.assertEqual(group_chat['type'], self.type) if __name__ == '__main__': unittest.main() diff --git a/tests/test_user.py b/tests/test_user.py index e13e52320..019c461fb 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -35,12 +35,14 @@ class UserTest(BaseTest, unittest.TestCase): self.first_name = "Leandro" self.last_name = "S." self.username = "leandrotoledo" + self.type = "private" self.json_dict = { 'id': self.id, 'first_name': self.first_name, 'last_name': self.last_name, - 'username': self.username + 'username': self.username, + 'type': self.type } 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.last_name, self.last_name) self.assertEqual(user.username, self.username) + self.assertEqual(user.type, self.type) self.assertEqual(user.name, '@leandrotoledo') @@ -69,6 +72,7 @@ class UserTest(BaseTest, unittest.TestCase): self.assertEqual(user.id, self.id) self.assertEqual(user.first_name, self.first_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)) @@ -108,6 +112,7 @@ class UserTest(BaseTest, unittest.TestCase): self.assertEqual(user['first_name'], self.first_name) self.assertEqual(user['last_name'], self.last_name) self.assertEqual(user['username'], self.username) + self.assertEqual(user['type'], self.type) if __name__ == '__main__': unittest.main()