Fixes crash when username is not defined on chat

This commit is contained in:
Leandro Toledo 2015-07-11 10:01:07 -03:00
parent 1bc58ad746
commit 59d55df99e
2 changed files with 4 additions and 4 deletions

View file

@ -62,7 +62,7 @@ class Message(object):
from_user = None from_user = None
if 'chat' in data: if 'chat' in data:
if 'username' in data['chat'] or 'id' in data['chat']: if 'first_name' in data['chat']:
from telegram import User from telegram import User
chat = User.de_json(data['chat']) chat = User.de_json(data['chat'])
if 'title' in data['chat']: if 'title' in data['chat']:

View file

@ -49,14 +49,14 @@ class BotTest(unittest.TestCase):
print 'Testing sendPhoto - File' print 'Testing sendPhoto - File'
message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'), message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'),
chat_id=12173560) chat_id=12173560)
self.assertEqual(12948, message.photo[2].file_size) self.assertEqual(1451, message.photo[0].file_size)
def testResendPhoto(self): def testResendPhoto(self):
'''Test the telegram.Bot sendPhoto method''' '''Test the telegram.Bot sendPhoto method'''
print 'Testing sendPhoto - Resend' print 'Testing sendPhoto - Resend'
message = self._bot.sendPhoto(photo=str('AgAD_v___6-nMRs1PC0HuqtHTCQ9qx0AFAI'), message = self._bot.sendPhoto(photo=str('AgADAQADr6cxGzU8LQe6q0dMJD2rHYkP2ykABFymiQqJgjxRGGMAAgI'),
chat_id=12173560) 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): def testSendAudio(self):
'''Test the telegram.Bot sendAudio method''' '''Test the telegram.Bot sendAudio method'''