Make chat_id a positional argument inside shortcut methods of Chat and User classes #1048 (#1050)

* Make chat_id a positional argument #1048

* Fixed tests
This commit is contained in:
Emilio Molinari 2018-03-17 00:10:11 +01:00 committed by Jannes Höke
parent 38e3b91a87
commit 3ccf40e8cc
5 changed files with 57 additions and 42 deletions

View file

@ -24,6 +24,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `daimajia <https://github.com/daimajia>`_
- `Daniel Reed <https://github.com/nmlorg>`_
- `Eli Gao <https://github.com/eligao>`_
- `Emilio Molinari <https://github.com/xates>`_
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
- `Eugene Lisitsky <https://github.com/lisitsky>`_
- `Eugenio Panadero <https://github.com/azogue>`_

View file

@ -224,7 +224,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_message(chat_id=self.id, *args, **kwargs)
return self.bot.send_message(self.id, *args, **kwargs)
def send_photo(self, *args, **kwargs):
"""Shortcut for::
@ -237,7 +237,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_photo(chat_id=self.id, *args, **kwargs)
return self.bot.send_photo(self.id, *args, **kwargs)
def send_audio(self, *args, **kwargs):
"""Shortcut for::
@ -250,7 +250,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_audio(chat_id=self.id, *args, **kwargs)
return self.bot.send_audio(self.id, *args, **kwargs)
def send_document(self, *args, **kwargs):
"""Shortcut for::
@ -263,7 +263,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_document(chat_id=self.id, *args, **kwargs)
return self.bot.send_document(self.id, *args, **kwargs)
def send_sticker(self, *args, **kwargs):
"""Shortcut for::
@ -276,7 +276,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_sticker(chat_id=self.id, *args, **kwargs)
return self.bot.send_sticker(self.id, *args, **kwargs)
def send_video(self, *args, **kwargs):
"""Shortcut for::
@ -289,7 +289,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video(chat_id=self.id, *args, **kwargs)
return self.bot.send_video(self.id, *args, **kwargs)
def send_video_note(self, *args, **kwargs):
"""Shortcut for::
@ -302,7 +302,7 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video_note(chat_id=self.id, *args, **kwargs)
return self.bot.send_video_note(self.id, *args, **kwargs)
def send_voice(self, *args, **kwargs):
"""Shortcut for::
@ -315,4 +315,4 @@ class Chat(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_voice(chat_id=self.id, *args, **kwargs)
return self.bot.send_voice(self.id, *args, **kwargs)

View file

@ -158,7 +158,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_message(chat_id=self.id, *args, **kwargs)
return self.bot.send_message(self.id, *args, **kwargs)
def send_photo(self, *args, **kwargs):
"""Shortcut for::
@ -171,7 +171,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_photo(chat_id=self.id, *args, **kwargs)
return self.bot.send_photo(self.id, *args, **kwargs)
def send_audio(self, *args, **kwargs):
"""Shortcut for::
@ -184,7 +184,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_audio(chat_id=self.id, *args, **kwargs)
return self.bot.send_audio(self.id, *args, **kwargs)
def send_document(self, *args, **kwargs):
"""Shortcut for::
@ -197,7 +197,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_document(chat_id=self.id, *args, **kwargs)
return self.bot.send_document(self.id, *args, **kwargs)
def send_sticker(self, *args, **kwargs):
"""Shortcut for::
@ -210,7 +210,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_sticker(chat_id=self.id, *args, **kwargs)
return self.bot.send_sticker(self.id, *args, **kwargs)
def send_video(self, *args, **kwargs):
"""Shortcut for::
@ -223,7 +223,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video(chat_id=self.id, *args, **kwargs)
return self.bot.send_video(self.id, *args, **kwargs)
def send_video_note(self, *args, **kwargs):
"""Shortcut for::
@ -236,7 +236,7 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_video_note(chat_id=self.id, *args, **kwargs)
return self.bot.send_video_note(self.id, *args, **kwargs)
def send_voice(self, *args, **kwargs):
"""Shortcut for::
@ -249,4 +249,4 @@ class User(TelegramObject):
:class:`telegram.Message`: On success, instance representing the message posted.
"""
return self.bot.send_voice(chat_id=self.id, *args, **kwargs)
return self.bot.send_voice(self.id, *args, **kwargs)

View file

@ -126,52 +126,59 @@ class TestChat(object):
def test_instance_method_send_message(self, monkeypatch, chat):
def test(*args, **kwargs):
return kwargs['chat_id'] == chat.id and args[1] == 'test'
return args[1] == chat.id and args[2] == 'test'
monkeypatch.setattr('telegram.Bot.send_message', test)
assert chat.send_message('test')
def test_instance_method_send_photo(self, monkeypatch, chat):
def test(*args, **kwargs):
return args[1] == chat.id and args[2] == 'test_photo'
monkeypatch.setattr('telegram.Bot.send_photo', test)
assert chat.send_photo('test_photo')
def test_instance_method_send_audio(self, monkeypatch, chat):
def test(*args, **kwargs):
return kwargs['chat_id'] == chat.id and kwargs['audio'] == 'test_audio'
return args[1] == chat.id and args[2] == 'test_audio'
monkeypatch.setattr('telegram.Bot.send_audio', test)
assert chat.send_audio(audio='test_audio')
assert chat.send_audio('test_audio')
def test_instance_method_send_document(self, monkeypatch, chat):
def test(*args, **kwargs):
return kwargs['chat_id'] == chat.id and kwargs['document'] == 'test_document'
return args[1] == chat.id and args[2] == 'test_document'
monkeypatch.setattr('telegram.Bot.send_document', test)
assert chat.send_document(document='test_document')
assert chat.send_document('test_document')
def test_instance_method_send_sticker(self, monkeypatch, chat):
def test(*args, **kwargs):
return kwargs['chat_id'] == chat.id and kwargs['sticker'] == 'test_sticker'
return args[1] == chat.id and args[2] == 'test_sticker'
monkeypatch.setattr('telegram.Bot.send_sticker', test)
assert chat.send_sticker(sticker='test_sticker')
assert chat.send_sticker('test_sticker')
def test_instance_method_send_video(self, monkeypatch, chat):
def test(*args, **kwargs):
return kwargs['chat_id'] == chat.id and kwargs['video'] == 'test_video'
return args[1] == chat.id and args[2] == 'test_video'
monkeypatch.setattr('telegram.Bot.send_video', test)
assert chat.send_video(video='test_video')
assert chat.send_video('test_video')
def test_instance_method_send_video_note(self, monkeypatch, chat):
def test(*args, **kwargs):
return kwargs['chat_id'] == chat.id and kwargs['video_note'] == 'test_video_note'
return args[1] == chat.id and args[2] == 'test_video_note'
monkeypatch.setattr('telegram.Bot.send_video_note', test)
assert chat.send_video_note(video_note='test_video_note')
assert chat.send_video_note('test_video_note')
def test_instance_method_send_voice(self, monkeypatch, chat):
def test(*args, **kwargs):
return kwargs['chat_id'] == chat.id and kwargs['voice'] == 'test_voice'
return args[1] == chat.id and args[2] == 'test_voice'
monkeypatch.setattr('telegram.Bot.send_voice', test)
assert chat.send_voice(voice='test_voice')
assert chat.send_voice('test_voice')
def test_equality(self):
a = Chat(self.id, self.title, self.type)

View file

@ -105,52 +105,59 @@ class TestUser(object):
def test_instance_method_send_message(self, monkeypatch, user):
def test(*args, **kwargs):
return kwargs['chat_id'] == user.id and args[1] == 'test'
return args[1] == user.id and args[2] == 'test'
monkeypatch.setattr('telegram.Bot.send_message', test)
assert user.send_message('test')
def test_instance_method_send_photo(self, monkeypatch, user):
def test(*args, **kwargs):
return args[1] == user.id and args[2] == 'test_photo'
monkeypatch.setattr('telegram.Bot.send_photo', test)
assert user.send_photo('test_photo')
def test_instance_method_send_audio(self, monkeypatch, user):
def test(*args, **kwargs):
return kwargs['chat_id'] == user.id and kwargs['audio'] == 'test_audio'
return args[1] == user.id and args[2] == 'test_audio'
monkeypatch.setattr('telegram.Bot.send_audio', test)
assert user.send_audio(audio='test_audio')
assert user.send_audio('test_audio')
def test_instance_method_send_document(self, monkeypatch, user):
def test(*args, **kwargs):
return kwargs['chat_id'] == user.id and kwargs['document'] == 'test_document'
return args[1] == user.id and args[2] == 'test_document'
monkeypatch.setattr('telegram.Bot.send_document', test)
assert user.send_document(document='test_document')
assert user.send_document('test_document')
def test_instance_method_send_sticker(self, monkeypatch, user):
def test(*args, **kwargs):
return kwargs['chat_id'] == user.id and kwargs['sticker'] == 'test_sticker'
return args[1] == user.id and args[2] == 'test_sticker'
monkeypatch.setattr('telegram.Bot.send_sticker', test)
assert user.send_sticker(sticker='test_sticker')
assert user.send_sticker('test_sticker')
def test_instance_method_send_video(self, monkeypatch, user):
def test(*args, **kwargs):
return kwargs['chat_id'] == user.id and kwargs['video'] == 'test_video'
return args[1] == user.id and args[2] == 'test_video'
monkeypatch.setattr('telegram.Bot.send_video', test)
assert user.send_video(video='test_video')
assert user.send_video('test_video')
def test_instance_method_send_video_note(self, monkeypatch, user):
def test(*args, **kwargs):
return kwargs['chat_id'] == user.id and kwargs['video_note'] == 'test_video_note'
return args[1] == user.id and args[2] == 'test_video_note'
monkeypatch.setattr('telegram.Bot.send_video_note', test)
assert user.send_video_note(video_note='test_video_note')
assert user.send_video_note('test_video_note')
def test_instance_method_send_voice(self, monkeypatch, user):
def test(*args, **kwargs):
return kwargs['chat_id'] == user.id and kwargs['voice'] == 'test_voice'
return args[1] == user.id and args[2] == 'test_voice'
monkeypatch.setattr('telegram.Bot.send_voice', test)
assert user.send_voice(voice='test_voice')
assert user.send_voice('test_voice')
def test_equality(self):
a = User(self.id, self.first_name, self.is_bot, self.last_name)