Adding sendPhoto method

This commit is contained in:
Leandro Toledo 2015-07-07 18:46:32 -03:00
parent 8fb2bf58fc
commit f7a15306a8
5 changed files with 32 additions and 11 deletions

1
.gitignore vendored
View file

@ -22,6 +22,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.env
# PyInstaller
# Usually these files are written by a python script from a template

View file

@ -81,6 +81,7 @@ class Bot(object):
data = {'chat_id': chat_id,
'photo': photo}
if caption:
data['caption'] = caption
if reply_to_message_id:
@ -143,6 +144,18 @@ class Bot(object):
data=None):
if method == 'POST':
if data.has_key('photo'):
try:
photo = data.pop('photo')
return requests.post(
url,
data=data,
files={'photo': photo}
)
except requests.RequestException as e:
pass
else:
try:
return requests.post(
url,

View file

@ -0,0 +1,5 @@
#!/usr/bin/env python
class InputFile(object):
pass

BIN
tests/telegram.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -44,7 +44,9 @@ class BotTest(unittest.TestCase):
self.assertEqual(u'Oi', message.text)
self.assertEqual(u'leandrotoledo', message.forward_from.username)
# def testSendPhoto(self):
# '''Test the telegram.Bot sendPhoto method'''
# print 'Testing sendPhoto'
# message = self._bot.sendPhoto()
def testSendPhoto(self):
'''Test the telegram.Bot sendPhoto method'''
print 'Testing sendPhoto'
message = self._bot.sendPhoto(photo=open('tests/telegram.png', 'rb'),
chat_id=12173560)
#self.assertEqual(u'')