From a42b68933c3628b9b98c83927661eddb61d1571a Mon Sep 17 00:00:00 2001 From: Bibo-Joshi Date: Wed, 27 May 2020 21:59:49 +0200 Subject: [PATCH] Add User.send_poll (#1968) --- telegram/user.py | 13 +++++++++++++ tests/test_user.py | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/telegram/user.py b/telegram/user.py index 084fd65a0..69afb57de 100644 --- a/telegram/user.py +++ b/telegram/user.py @@ -296,3 +296,16 @@ class User(TelegramObject): """ return self.bot.send_voice(self.id, *args, **kwargs) + + def send_poll(self, *args, **kwargs): + """Shortcut for:: + + bot.send_poll(User.id, *args, **kwargs) + + Where User is the current instance. + + Returns: + :class:`telegram.Message`: On success, instance representing the message posted. + + """ + return self.bot.send_poll(self.id, *args, **kwargs) diff --git a/tests/test_user.py b/tests/test_user.py index bab96aa66..9328c55fe 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -190,6 +190,13 @@ class TestUser(object): monkeypatch.setattr(user.bot, 'send_animation', test) assert user.send_animation('test_animation') + def test_instance_method_send_poll(self, monkeypatch, user): + def test(*args, **kwargs): + return args[0] == user.id and args[1] == 'test_poll' + + monkeypatch.setattr(user.bot, 'send_poll', test) + assert user.send_poll('test_poll') + def test_mention_html(self, user): expected = u'{}'