Skip to content

Commit cf5d184

Browse files
committed
Add type to User and GroupChat classes
1 parent 5738dc5 commit cf5d184

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

telegram/groupchat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ class GroupChat(TelegramObject):
2828
Attributes:
2929
id (int):
3030
title (str):
31+
type (str):
3132
3233
Args:
3334
id (int):
3435
title (str):
36+
type (str):
3537
"""
3638

3739
def __init__(self,
3840
id,
39-
title):
41+
title,
42+
type):
4043
# Required
4144
self.id = int(id)
4245
self.title = title
46+
self.type = type
4347

4448
@staticmethod
4549
def de_json(data):

telegram/user.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ class User(TelegramObject):
3030
first_name (str):
3131
last_name (str):
3232
username (str):
33+
type (str):
3334
3435
Args:
3536
id (int):
3637
first_name (str):
3738
**kwargs: Arbitrary keyword arguments.
3839
3940
Keyword Args:
41+
type (Optional[str]):
4042
last_name (Optional[str]):
4143
username (Optional[str]):
4244
"""
@@ -49,6 +51,7 @@ def __init__(self,
4951
self.id = int(id)
5052
self.first_name = first_name
5153
# Optionals
54+
self.type = kwargs.get('type', '')
5255
self.last_name = kwargs.get('last_name', '')
5356
self.username = kwargs.get('username', '')
5457

tests/test_groupchat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ class GroupChatTest(BaseTest, unittest.TestCase):
3333
def setUp(self):
3434
self.id = -28767330
3535
self.title = 'ToledosPalaceBot - Group'
36+
self.type = 'group'
3637

3738
self.json_dict = {
3839
'id': self.id,
39-
'title': self.title
40+
'title': self.title,
41+
'type': self.type
4042
}
4143

4244
def test_group_chat_de_json_empty_json(self):
@@ -55,6 +57,7 @@ def test_group_chat_de_json(self):
5557

5658
self.assertEqual(group_chat.id, self.id)
5759
self.assertEqual(group_chat.title, self.title)
60+
self.assertEqual(group_chat.type, self.type)
5861

5962
def test_group_chat_to_json(self):
6063
"""Test GroupChat.to_json() method"""
@@ -73,6 +76,7 @@ def test_group_chat_to_dict(self):
7376
self.assertTrue(self.is_dict(group_chat.to_dict()))
7477
self.assertEqual(group_chat['id'], self.id)
7578
self.assertEqual(group_chat['title'], self.title)
79+
self.assertEqual(group_chat['type'], self.type)
7680

7781
if __name__ == '__main__':
7882
unittest.main()

tests/test_user.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ def setUp(self):
3535
self.first_name = "Leandro"
3636
self.last_name = "S."
3737
self.username = "leandrotoledo"
38+
self.type = "private"
3839

3940
self.json_dict = {
4041
'id': self.id,
4142
'first_name': self.first_name,
4243
'last_name': self.last_name,
43-
'username': self.username
44+
'username': self.username,
45+
'type': self.type
4446
}
4547

4648
def test_user_de_json(self):
@@ -53,6 +55,7 @@ def test_user_de_json(self):
5355
self.assertEqual(user.first_name, self.first_name)
5456
self.assertEqual(user.last_name, self.last_name)
5557
self.assertEqual(user.username, self.username)
58+
self.assertEqual(user.type, self.type)
5659

5760
self.assertEqual(user.name, '@leandrotoledo')
5861

@@ -69,6 +72,7 @@ def test_user_de_json_without_username(self):
6972
self.assertEqual(user.id, self.id)
7073
self.assertEqual(user.first_name, self.first_name)
7174
self.assertEqual(user.last_name, self.last_name)
75+
self.assertEqual(user.type, self.type)
7276

7377
self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name))
7478

@@ -108,6 +112,7 @@ def test_user_to_dict(self):
108112
self.assertEqual(user['first_name'], self.first_name)
109113
self.assertEqual(user['last_name'], self.last_name)
110114
self.assertEqual(user['username'], self.username)
115+
self.assertEqual(user['type'], self.type)
111116

112117
if __name__ == '__main__':
113118
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy