Skip to content

Commit 3ccf40e

Browse files
Emilio Molinarijh0ker
authored andcommitted
Make chat_id a positional argument inside shortcut methods of Chat and User classes python-telegram-bot#1048 (python-telegram-bot#1050)
* Make chat_id a positional argument python-telegram-bot#1048 * Fixed tests
1 parent 38e3b91 commit 3ccf40e

File tree

5 files changed

+57
-42
lines changed

5 files changed

+57
-42
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The following wonderful people contributed directly or indirectly to this projec
2424
- `daimajia <https://github.com/daimajia>`_
2525
- `Daniel Reed <https://github.com/nmlorg>`_
2626
- `Eli Gao <https://github.com/eligao>`_
27+
- `Emilio Molinari <https://github.com/xates>`_
2728
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
2829
- `Eugene Lisitsky <https://github.com/lisitsky>`_
2930
- `Eugenio Panadero <https://github.com/azogue>`_

telegram/chat.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def send_message(self, *args, **kwargs):
224224
:class:`telegram.Message`: On success, instance representing the message posted.
225225
226226
"""
227-
return self.bot.send_message(chat_id=self.id, *args, **kwargs)
227+
return self.bot.send_message(self.id, *args, **kwargs)
228228

229229
def send_photo(self, *args, **kwargs):
230230
"""Shortcut for::
@@ -237,7 +237,7 @@ def send_photo(self, *args, **kwargs):
237237
:class:`telegram.Message`: On success, instance representing the message posted.
238238
239239
"""
240-
return self.bot.send_photo(chat_id=self.id, *args, **kwargs)
240+
return self.bot.send_photo(self.id, *args, **kwargs)
241241

242242
def send_audio(self, *args, **kwargs):
243243
"""Shortcut for::
@@ -250,7 +250,7 @@ def send_audio(self, *args, **kwargs):
250250
:class:`telegram.Message`: On success, instance representing the message posted.
251251
252252
"""
253-
return self.bot.send_audio(chat_id=self.id, *args, **kwargs)
253+
return self.bot.send_audio(self.id, *args, **kwargs)
254254

255255
def send_document(self, *args, **kwargs):
256256
"""Shortcut for::
@@ -263,7 +263,7 @@ def send_document(self, *args, **kwargs):
263263
:class:`telegram.Message`: On success, instance representing the message posted.
264264
265265
"""
266-
return self.bot.send_document(chat_id=self.id, *args, **kwargs)
266+
return self.bot.send_document(self.id, *args, **kwargs)
267267

268268
def send_sticker(self, *args, **kwargs):
269269
"""Shortcut for::
@@ -276,7 +276,7 @@ def send_sticker(self, *args, **kwargs):
276276
:class:`telegram.Message`: On success, instance representing the message posted.
277277
278278
"""
279-
return self.bot.send_sticker(chat_id=self.id, *args, **kwargs)
279+
return self.bot.send_sticker(self.id, *args, **kwargs)
280280

281281
def send_video(self, *args, **kwargs):
282282
"""Shortcut for::
@@ -289,7 +289,7 @@ def send_video(self, *args, **kwargs):
289289
:class:`telegram.Message`: On success, instance representing the message posted.
290290
291291
"""
292-
return self.bot.send_video(chat_id=self.id, *args, **kwargs)
292+
return self.bot.send_video(self.id, *args, **kwargs)
293293

294294
def send_video_note(self, *args, **kwargs):
295295
"""Shortcut for::
@@ -302,7 +302,7 @@ def send_video_note(self, *args, **kwargs):
302302
:class:`telegram.Message`: On success, instance representing the message posted.
303303
304304
"""
305-
return self.bot.send_video_note(chat_id=self.id, *args, **kwargs)
305+
return self.bot.send_video_note(self.id, *args, **kwargs)
306306

307307
def send_voice(self, *args, **kwargs):
308308
"""Shortcut for::
@@ -315,4 +315,4 @@ def send_voice(self, *args, **kwargs):
315315
:class:`telegram.Message`: On success, instance representing the message posted.
316316
317317
"""
318-
return self.bot.send_voice(chat_id=self.id, *args, **kwargs)
318+
return self.bot.send_voice(self.id, *args, **kwargs)

telegram/user.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def send_message(self, *args, **kwargs):
158158
:class:`telegram.Message`: On success, instance representing the message posted.
159159
160160
"""
161-
return self.bot.send_message(chat_id=self.id, *args, **kwargs)
161+
return self.bot.send_message(self.id, *args, **kwargs)
162162

163163
def send_photo(self, *args, **kwargs):
164164
"""Shortcut for::
@@ -171,7 +171,7 @@ def send_photo(self, *args, **kwargs):
171171
:class:`telegram.Message`: On success, instance representing the message posted.
172172
173173
"""
174-
return self.bot.send_photo(chat_id=self.id, *args, **kwargs)
174+
return self.bot.send_photo(self.id, *args, **kwargs)
175175

176176
def send_audio(self, *args, **kwargs):
177177
"""Shortcut for::
@@ -184,7 +184,7 @@ def send_audio(self, *args, **kwargs):
184184
:class:`telegram.Message`: On success, instance representing the message posted.
185185
186186
"""
187-
return self.bot.send_audio(chat_id=self.id, *args, **kwargs)
187+
return self.bot.send_audio(self.id, *args, **kwargs)
188188

189189
def send_document(self, *args, **kwargs):
190190
"""Shortcut for::
@@ -197,7 +197,7 @@ def send_document(self, *args, **kwargs):
197197
:class:`telegram.Message`: On success, instance representing the message posted.
198198
199199
"""
200-
return self.bot.send_document(chat_id=self.id, *args, **kwargs)
200+
return self.bot.send_document(self.id, *args, **kwargs)
201201

202202
def send_sticker(self, *args, **kwargs):
203203
"""Shortcut for::
@@ -210,7 +210,7 @@ def send_sticker(self, *args, **kwargs):
210210
:class:`telegram.Message`: On success, instance representing the message posted.
211211
212212
"""
213-
return self.bot.send_sticker(chat_id=self.id, *args, **kwargs)
213+
return self.bot.send_sticker(self.id, *args, **kwargs)
214214

215215
def send_video(self, *args, **kwargs):
216216
"""Shortcut for::
@@ -223,7 +223,7 @@ def send_video(self, *args, **kwargs):
223223
:class:`telegram.Message`: On success, instance representing the message posted.
224224
225225
"""
226-
return self.bot.send_video(chat_id=self.id, *args, **kwargs)
226+
return self.bot.send_video(self.id, *args, **kwargs)
227227

228228
def send_video_note(self, *args, **kwargs):
229229
"""Shortcut for::
@@ -236,7 +236,7 @@ def send_video_note(self, *args, **kwargs):
236236
:class:`telegram.Message`: On success, instance representing the message posted.
237237
238238
"""
239-
return self.bot.send_video_note(chat_id=self.id, *args, **kwargs)
239+
return self.bot.send_video_note(self.id, *args, **kwargs)
240240

241241
def send_voice(self, *args, **kwargs):
242242
"""Shortcut for::
@@ -249,4 +249,4 @@ def send_voice(self, *args, **kwargs):
249249
:class:`telegram.Message`: On success, instance representing the message posted.
250250
251251
"""
252-
return self.bot.send_voice(chat_id=self.id, *args, **kwargs)
252+
return self.bot.send_voice(self.id, *args, **kwargs)

tests/test_chat.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,52 +126,59 @@ def test(*args, **kwargs):
126126

127127
def test_instance_method_send_message(self, monkeypatch, chat):
128128
def test(*args, **kwargs):
129-
return kwargs['chat_id'] == chat.id and args[1] == 'test'
129+
return args[1] == chat.id and args[2] == 'test'
130130

131131
monkeypatch.setattr('telegram.Bot.send_message', test)
132132
assert chat.send_message('test')
133133

134+
def test_instance_method_send_photo(self, monkeypatch, chat):
135+
def test(*args, **kwargs):
136+
return args[1] == chat.id and args[2] == 'test_photo'
137+
138+
monkeypatch.setattr('telegram.Bot.send_photo', test)
139+
assert chat.send_photo('test_photo')
140+
134141
def test_instance_method_send_audio(self, monkeypatch, chat):
135142
def test(*args, **kwargs):
136-
return kwargs['chat_id'] == chat.id and kwargs['audio'] == 'test_audio'
143+
return args[1] == chat.id and args[2] == 'test_audio'
137144

138145
monkeypatch.setattr('telegram.Bot.send_audio', test)
139-
assert chat.send_audio(audio='test_audio')
146+
assert chat.send_audio('test_audio')
140147

141148
def test_instance_method_send_document(self, monkeypatch, chat):
142149
def test(*args, **kwargs):
143-
return kwargs['chat_id'] == chat.id and kwargs['document'] == 'test_document'
150+
return args[1] == chat.id and args[2] == 'test_document'
144151

145152
monkeypatch.setattr('telegram.Bot.send_document', test)
146-
assert chat.send_document(document='test_document')
153+
assert chat.send_document('test_document')
147154

148155
def test_instance_method_send_sticker(self, monkeypatch, chat):
149156
def test(*args, **kwargs):
150-
return kwargs['chat_id'] == chat.id and kwargs['sticker'] == 'test_sticker'
157+
return args[1] == chat.id and args[2] == 'test_sticker'
151158

152159
monkeypatch.setattr('telegram.Bot.send_sticker', test)
153-
assert chat.send_sticker(sticker='test_sticker')
160+
assert chat.send_sticker('test_sticker')
154161

155162
def test_instance_method_send_video(self, monkeypatch, chat):
156163
def test(*args, **kwargs):
157-
return kwargs['chat_id'] == chat.id and kwargs['video'] == 'test_video'
164+
return args[1] == chat.id and args[2] == 'test_video'
158165

159166
monkeypatch.setattr('telegram.Bot.send_video', test)
160-
assert chat.send_video(video='test_video')
167+
assert chat.send_video('test_video')
161168

162169
def test_instance_method_send_video_note(self, monkeypatch, chat):
163170
def test(*args, **kwargs):
164-
return kwargs['chat_id'] == chat.id and kwargs['video_note'] == 'test_video_note'
171+
return args[1] == chat.id and args[2] == 'test_video_note'
165172

166173
monkeypatch.setattr('telegram.Bot.send_video_note', test)
167-
assert chat.send_video_note(video_note='test_video_note')
174+
assert chat.send_video_note('test_video_note')
168175

169176
def test_instance_method_send_voice(self, monkeypatch, chat):
170177
def test(*args, **kwargs):
171-
return kwargs['chat_id'] == chat.id and kwargs['voice'] == 'test_voice'
178+
return args[1] == chat.id and args[2] == 'test_voice'
172179

173180
monkeypatch.setattr('telegram.Bot.send_voice', test)
174-
assert chat.send_voice(voice='test_voice')
181+
assert chat.send_voice('test_voice')
175182

176183
def test_equality(self):
177184
a = Chat(self.id, self.title, self.type)

tests/test_user.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,52 +105,59 @@ def test(_, *args, **kwargs):
105105

106106
def test_instance_method_send_message(self, monkeypatch, user):
107107
def test(*args, **kwargs):
108-
return kwargs['chat_id'] == user.id and args[1] == 'test'
108+
return args[1] == user.id and args[2] == 'test'
109109

110110
monkeypatch.setattr('telegram.Bot.send_message', test)
111111
assert user.send_message('test')
112112

113+
def test_instance_method_send_photo(self, monkeypatch, user):
114+
def test(*args, **kwargs):
115+
return args[1] == user.id and args[2] == 'test_photo'
116+
117+
monkeypatch.setattr('telegram.Bot.send_photo', test)
118+
assert user.send_photo('test_photo')
119+
113120
def test_instance_method_send_audio(self, monkeypatch, user):
114121
def test(*args, **kwargs):
115-
return kwargs['chat_id'] == user.id and kwargs['audio'] == 'test_audio'
122+
return args[1] == user.id and args[2] == 'test_audio'
116123

117124
monkeypatch.setattr('telegram.Bot.send_audio', test)
118-
assert user.send_audio(audio='test_audio')
125+
assert user.send_audio('test_audio')
119126

120127
def test_instance_method_send_document(self, monkeypatch, user):
121128
def test(*args, **kwargs):
122-
return kwargs['chat_id'] == user.id and kwargs['document'] == 'test_document'
129+
return args[1] == user.id and args[2] == 'test_document'
123130

124131
monkeypatch.setattr('telegram.Bot.send_document', test)
125-
assert user.send_document(document='test_document')
132+
assert user.send_document('test_document')
126133

127134
def test_instance_method_send_sticker(self, monkeypatch, user):
128135
def test(*args, **kwargs):
129-
return kwargs['chat_id'] == user.id and kwargs['sticker'] == 'test_sticker'
136+
return args[1] == user.id and args[2] == 'test_sticker'
130137

131138
monkeypatch.setattr('telegram.Bot.send_sticker', test)
132-
assert user.send_sticker(sticker='test_sticker')
139+
assert user.send_sticker('test_sticker')
133140

134141
def test_instance_method_send_video(self, monkeypatch, user):
135142
def test(*args, **kwargs):
136-
return kwargs['chat_id'] == user.id and kwargs['video'] == 'test_video'
143+
return args[1] == user.id and args[2] == 'test_video'
137144

138145
monkeypatch.setattr('telegram.Bot.send_video', test)
139-
assert user.send_video(video='test_video')
146+
assert user.send_video('test_video')
140147

141148
def test_instance_method_send_video_note(self, monkeypatch, user):
142149
def test(*args, **kwargs):
143-
return kwargs['chat_id'] == user.id and kwargs['video_note'] == 'test_video_note'
150+
return args[1] == user.id and args[2] == 'test_video_note'
144151

145152
monkeypatch.setattr('telegram.Bot.send_video_note', test)
146-
assert user.send_video_note(video_note='test_video_note')
153+
assert user.send_video_note('test_video_note')
147154

148155
def test_instance_method_send_voice(self, monkeypatch, user):
149156
def test(*args, **kwargs):
150-
return kwargs['chat_id'] == user.id and kwargs['voice'] == 'test_voice'
157+
return args[1] == user.id and args[2] == 'test_voice'
151158

152159
monkeypatch.setattr('telegram.Bot.send_voice', test)
153-
assert user.send_voice(voice='test_voice')
160+
assert user.send_voice('test_voice')
154161

155162
def test_equality(self):
156163
a = User(self.id, self.first_name, self.is_bot, self.last_name)

0 commit comments

Comments
 (0)