Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`_
Expand Down
16 changes: 8 additions & 8 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def send_message(self, *args, **kwargs):
: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::
Expand All @@ -237,7 +237,7 @@ def send_photo(self, *args, **kwargs):
: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::
Expand All @@ -250,7 +250,7 @@ def send_audio(self, *args, **kwargs):
: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::
Expand All @@ -263,7 +263,7 @@ def send_document(self, *args, **kwargs):
: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::
Expand All @@ -276,7 +276,7 @@ def send_sticker(self, *args, **kwargs):
: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::
Expand All @@ -289,7 +289,7 @@ def send_video(self, *args, **kwargs):
: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::
Expand All @@ -302,7 +302,7 @@ def send_video_note(self, *args, **kwargs):
: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::
Expand All @@ -315,4 +315,4 @@ def send_voice(self, *args, **kwargs):
: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)
16 changes: 8 additions & 8 deletions telegram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def send_message(self, *args, **kwargs):
: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::
Expand All @@ -171,7 +171,7 @@ def send_photo(self, *args, **kwargs):
: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::
Expand All @@ -184,7 +184,7 @@ def send_audio(self, *args, **kwargs):
: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::
Expand All @@ -197,7 +197,7 @@ def send_document(self, *args, **kwargs):
: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::
Expand All @@ -210,7 +210,7 @@ def send_sticker(self, *args, **kwargs):
: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::
Expand All @@ -223,7 +223,7 @@ def send_video(self, *args, **kwargs):
: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::
Expand All @@ -236,7 +236,7 @@ def send_video_note(self, *args, **kwargs):
: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::
Expand All @@ -249,4 +249,4 @@ def send_voice(self, *args, **kwargs):
: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)
33 changes: 20 additions & 13 deletions tests/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,52 +126,59 @@ def test(*args, **kwargs):

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)
Expand Down
33 changes: 20 additions & 13 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,52 +105,59 @@ def test(_, *args, **kwargs):

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)
Expand Down
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