From 5e2f60ed7d7e51207f1926d660137a45c01dcdd0 Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Tue, 7 Jul 2015 19:06:17 -0300 Subject: [PATCH] Adding sendPhoto method by file_id --- telegram/bot.py | 2 +- tests/test_bot.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/telegram/bot.py b/telegram/bot.py index 78ffb61a5..0874ac31e 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -144,7 +144,7 @@ class Bot(object): data=None): if method == 'POST': - if data.has_key('photo'): + if data.has_key('photo') and isinstance(data['photo'], file): try: photo = data.pop('photo') diff --git a/tests/test_bot.py b/tests/test_bot.py index 485f5cf74..9d93b9376 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -46,7 +46,14 @@ class BotTest(unittest.TestCase): def testSendPhoto(self): '''Test the telegram.Bot sendPhoto method''' - print 'Testing sendPhoto' + print 'Testing sendPhoto - File' message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'), chat_id=12173560) - #self.assertEqual(u'') + self.assertEqual(12948, message.photo[2].get('file_size')) + + def testReSendPhoto(self): + '''Test the telegram.Bot sendPhoto method''' + print 'Testing sendPhoto - Resend' + message = self._bot.sendPhoto(photo=str('AgAD_v___6-nMRs1PC0HuqtHTCQ9qx0AFAI'), + chat_id=12173560) + self.assertEqual(u'AgAD_v___6-nMRs1PC0HuqtHTCQ9qx0AFAI', message.photo[2].get('file_id'))