From 05b7fda4a1a47801bf3aea0554a3bdb968c62196 Mon Sep 17 00:00:00 2001 From: leandrotoledo Date: Fri, 4 Sep 2015 17:53:39 -0300 Subject: [PATCH] Add certificate arg to setWebhook function --- telegram/bot.py | 15 +++++--- telegram/inputfile.py | 3 ++ testscommand_handlertest.py | 73 ------------------------------------- 3 files changed, 13 insertions(+), 78 deletions(-) delete mode 100644 testscommand_handlertest.py diff --git a/telegram/bot.py b/telegram/bot.py index b09907c91a6..c6ec61731ce 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -72,12 +72,12 @@ def __init__(self, def info(func): """ - bla + Returns: """ @functools.wraps(func) def decorator(self, *args, **kwargs): """ - bla + decorator """ if not self.bot: self.getMe() @@ -660,7 +660,8 @@ def getUpdates(self, @log def setWebhook(self, - webhook_url): + webhook_url=None, + certificate=None): """Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a @@ -677,12 +678,16 @@ def setWebhook(self, """ url = '%s/setWebhook' % self.base_url - data = {'url': webhook_url} + data = {} + if webhook_url: + data['url'] = webhook_url + if certificate: + data['certificate'] = certificate json_data = self._requestUrl(url, 'POST', data=data) data = self._parseAndCheckTelegram(json_data) - return True + return data @staticmethod def _requestUrl(url, diff --git a/telegram/inputfile.py b/telegram/inputfile.py index aec76e8b804..e0f234f6205 100644 --- a/telegram/inputfile.py +++ b/telegram/inputfile.py @@ -61,6 +61,9 @@ def __init__(self, if 'voice' in data: self.input_name = 'voice' self.input_file = data.pop('voice') + if 'certificate' in data: + self.input_name = 'certificate' + self.input_file = data.pop('certificate') if isinstance(self.input_file, file): self.input_file_content = self.input_file.read() diff --git a/testscommand_handlertest.py b/testscommand_handlertest.py deleted file mode 100644 index 4916a8d1597..00000000000 --- a/testscommand_handlertest.py +++ /dev/null @@ -1,73 +0,0 @@ -import telegram -import unittest -import unittest.mock -from telegram import CommandHandler, CommandHandlerWithHelp - - -class CommandHandlerTmp(CommandHandler): - def __init__(self, *args, **kwargs): - super(CommandHandlerTmp, self).__init__(*args, **kwargs) - self.output = None - - def command_test(self, update): - self.output = 1 - - -class CommandHandlerTmp2(CommandHandlerWithHelp): - def __init__(self, *args, **kwargs): - super(CommandHandlerTmp2, self).__init__(*args, **kwargs) - self.output_test = None - - def command_test(self, update): - self.output_test = 1 - - -def fake_getUpdates(*args, **kwargs): - from_user = telegram.User(id=42, first_name='hello') - message = telegram.Message(message_id=42, from_user=from_user, date=None, chat=from_user, text='/test') - update = telegram.Update(update_id=42, message=message) - return [update] - -output_fsm = None - - -def fake_sendMessage(chat_id, message, *args, **kwargs): - global output_fsm - output_fsm = (chat_id, message) - return telegram.Message(43, 123, 000000, telegram.User(chat_id, 'test'), text=message) - - -class CommandHandlerTest(unittest.TestCase): - def setUp(self): - self.bot = unittest.mock.MagicMock() - self.bot.getUpdates = fake_getUpdates - self.bot.sendMessage = fake_sendMessage - - def test_get_command_func(self): - CH = CommandHandlerTmp(self.bot) - self.assertEqual(CH.command_test, CH._get_command_func('test')) - self.assertEqual(CH.command_test, CH._get_command_func('/test')) - self.assertEqual(None, CH._get_command_func('this function does not exsist')) - - def test_run_once(self): - CH = CommandHandlerTmp(self.bot) - self.assertEqual(CH.output, None) - threads, last_update = CH.run_once(make_thread=True) - for t in threads: - t.start() - for t in threads: - t.join() - self.assertEqual(CH.output, 1) - - def test_run(self): - pass # TODO implement test - - def test__command_not_found(self): - CH = CommandHandlerTmp(self.bot) - CH._command_not_found(self.bot.getUpdates()[0]) - self.assertEqual(output_fsm, (42, "Sorry, I didn't understand the command: /test.")) - - -if __name__ == '__main__': - import sys - unittest.main(sys.argv)