From 59d55df99ed5025e2f79920a845fb1f1415857ac Mon Sep 17 00:00:00 2001 From: Leandro Toledo Date: Sat, 11 Jul 2015 10:01:07 -0300 Subject: [PATCH] Fixes crash when username is not defined on chat --- telegram/message.py | 2 +- tests/test_bot.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/telegram/message.py b/telegram/message.py index 8f4cec552..a0cd36452 100644 --- a/telegram/message.py +++ b/telegram/message.py @@ -62,7 +62,7 @@ class Message(object): from_user = None if 'chat' in data: - if 'username' in data['chat'] or 'id' in data['chat']: + if 'first_name' in data['chat']: from telegram import User chat = User.de_json(data['chat']) if 'title' in data['chat']: diff --git a/tests/test_bot.py b/tests/test_bot.py index 794e98ac4..5f3849aa1 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -49,14 +49,14 @@ class BotTest(unittest.TestCase): print 'Testing sendPhoto - File' message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'), chat_id=12173560) - self.assertEqual(12948, message.photo[2].file_size) + self.assertEqual(1451, message.photo[0].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'), + message = self._bot.sendPhoto(photo=str('AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI'), chat_id=12173560) - self.assertEqual(u'AgAD_v___6-nMRs1PC0HuqtHTCQ9qx0AFAI', message.photo[2].file_id) + self.assertEqual(u'AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI', message.photo[0].file_id) def testSendAudio(self): '''Test the telegram.Bot sendAudio method'''