mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-10 20:12:52 +01:00
Merge pull request #261 from python-telegram-bot/unittest-bot2.0
Unittest for Bot 2.0 features
This commit is contained in:
commit
d093506ef2
65 changed files with 2646 additions and 289 deletions
|
@ -21,8 +21,8 @@
|
|||
"""This module contains a object that represents a Telegram Bot."""
|
||||
|
||||
import logging
|
||||
|
||||
import functools
|
||||
|
||||
from telegram import User, Message, Update, UserProfilePhotos, File, \
|
||||
ReplyMarkup, TelegramObject, NullHandler
|
||||
from telegram.utils import request
|
||||
|
@ -1164,6 +1164,7 @@ class Bot(TelegramObject):
|
|||
return result
|
||||
|
||||
@log
|
||||
@message
|
||||
def editMessageText(self,
|
||||
text,
|
||||
chat_id=None,
|
||||
|
@ -1171,7 +1172,6 @@ class Bot(TelegramObject):
|
|||
inline_message_id=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
"""Use this method to edit text messages sent by the bot or via the bot
|
||||
(for inline bots).
|
||||
|
@ -1194,10 +1194,10 @@ class Bot(TelegramObject):
|
|||
italic, fixed-width text or inline URLs in your bot's message.
|
||||
disable_web_page_preview:
|
||||
Disables link previews for links in this message.
|
||||
reply_markup:
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
|
||||
Keyword Args:
|
||||
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
|
@ -1229,17 +1229,8 @@ class Bot(TelegramObject):
|
|||
data['parse_mode'] = parse_mode
|
||||
if disable_web_page_preview:
|
||||
data['disable_web_page_preview'] = disable_web_page_preview
|
||||
if reply_markup:
|
||||
if isinstance(reply_markup, ReplyMarkup):
|
||||
data['reply_markup'] = reply_markup.to_json()
|
||||
else:
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
|
||||
return Message.de_json(result)
|
||||
return url, data
|
||||
|
||||
@log
|
||||
@message
|
||||
|
|
|
@ -41,6 +41,8 @@ class InlineKeyboardMarkup(ReplyMarkup):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineKeyboardMarkup, InlineKeyboardMarkup).de_json(data)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
|
|
|
@ -25,6 +25,35 @@ from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
|||
|
||||
|
||||
class InlineQueryResultCachedAudio(InlineQueryResult):
|
||||
"""Represents a link to an mp3 audio file stored on the Telegram
|
||||
servers. By default, this audio file will be sent by the user.
|
||||
Alternatively, you can use input_message_content to send a message with
|
||||
the specified content instead of the audio.
|
||||
|
||||
Attributes:
|
||||
id (str):
|
||||
audio_file_id (str):
|
||||
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
|
||||
input_message_content (Optional[
|
||||
:class:`telegram.input_message_content`]):
|
||||
|
||||
Deprecated: 4.0
|
||||
message_text (str): Use :class:`InputTextMessageContent` instead.
|
||||
|
||||
parse_mode (str): Use :class:`InputTextMessageContent` instead.
|
||||
|
||||
disable_web_page_preview (bool): Use :class:`InputTextMessageContent`
|
||||
instead.
|
||||
|
||||
Args:
|
||||
audio_file_id (str):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
|
||||
input_message_content (Optional[
|
||||
:class:`telegram.input_message_content`]):
|
||||
"""
|
||||
def __init__(self,
|
||||
id,
|
||||
audio_file_id,
|
||||
|
|
|
@ -24,4 +24,18 @@ from telegram import InputMessageContent
|
|||
|
||||
|
||||
class InputContactMessageContent(InputMessageContent):
|
||||
pass
|
||||
"""Base class for Telegram InputContactMessageContent Objects"""
|
||||
|
||||
def __init__(self,
|
||||
phone_number,
|
||||
first_name,
|
||||
last_name=None):
|
||||
# Required
|
||||
self.phone_number = phone_number
|
||||
self.first_name = first_name
|
||||
# Optionals
|
||||
self.last_name = last_name
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
return InputContactMessageContent(**data)
|
||||
|
|
|
@ -20,6 +20,11 @@
|
|||
|
||||
"""This module contains a object that represents a Telegram InputFile."""
|
||||
|
||||
import mimetypes
|
||||
import os
|
||||
import sys
|
||||
import imghdr
|
||||
|
||||
try:
|
||||
from email.generator import _make_boundary as choose_boundary
|
||||
from urllib.request import urlopen
|
||||
|
@ -27,11 +32,6 @@ except ImportError:
|
|||
from mimetools import choose_boundary
|
||||
from urllib2 import urlopen
|
||||
|
||||
import mimetypes
|
||||
import os
|
||||
import sys
|
||||
import imghdr
|
||||
|
||||
from telegram import TelegramError
|
||||
|
||||
DEFAULT_MIME_TYPE = 'application/octet-stream'
|
||||
|
|
|
@ -35,7 +35,4 @@ class InputLocationMessageContent(InputMessageContent):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InputLocationMessageContent,
|
||||
InputLocationMessageContent).de_json(data)
|
||||
|
||||
return InputLocationMessageContent(**data)
|
||||
|
|
|
@ -28,4 +28,33 @@ class InputMessageContent(TelegramObject):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
pass
|
||||
data = super(InputMessageContent, InputMessageContent).de_json(data)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
try:
|
||||
from telegram import InputTextMessageContent
|
||||
return InputTextMessageContent.de_json(data)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputLocationMessageContent
|
||||
return InputLocationMessageContent.de_json(data)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputVenueMessageContent
|
||||
return InputVenueMessageContent.de_json(data)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
from telegram import InputContactMessageContent
|
||||
return InputContactMessageContent.de_json(data)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
|
|
@ -38,7 +38,4 @@ class InputTextMessageContent(InputMessageContent):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InputTextMessageContent,
|
||||
InputTextMessageContent).de_json(data)
|
||||
|
||||
return InputTextMessageContent(**data)
|
||||
|
|
|
@ -42,7 +42,4 @@ class InputVenueMessageContent(InputMessageContent):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InputVenueMessageContent,
|
||||
InputVenueMessageContent).de_json(data)
|
||||
|
||||
return InputVenueMessageContent(**data)
|
||||
|
|
|
@ -27,4 +27,9 @@ class ReplyMarkup(TelegramObject):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
pass
|
||||
data = super(ReplyMarkup, ReplyMarkup).de_json(data)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return data
|
||||
|
|
|
@ -47,11 +47,11 @@ class Venue(TelegramObject):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(Venue, Venue).de_json(data)
|
||||
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(Venue, Venue).de_json(data)
|
||||
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
|
||||
return Venue(**data)
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Base class for tests"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
import traceback
|
||||
import sys
|
||||
|
||||
import os
|
||||
from nose.tools import make_decorator
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -38,7 +36,8 @@ class BaseTest(object):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super(BaseTest, self).__init__(*args, **kwargs)
|
||||
|
||||
bot = telegram.Bot(os.environ.get('TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
|
||||
bot = telegram.Bot(os.environ.get(
|
||||
'TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
|
||||
chat_id = os.environ.get('CHAT_ID', '12173560')
|
||||
|
||||
self._bot = bot
|
||||
|
@ -62,7 +61,6 @@ class BaseTest(object):
|
|||
|
||||
|
||||
class TestTimedOut(AssertionError):
|
||||
|
||||
def __init__(self, time_limit, frame):
|
||||
super(TestTimedOut, self).__init__('time_limit={0}'.format(time_limit))
|
||||
self.time_limit = time_limit
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Audio"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -55,8 +55,7 @@ class AudioTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_audio_required_args_only(self):
|
||||
message = self._bot.sendAudio(self._chat_id,
|
||||
self.audio_file)
|
||||
message = self._bot.sendAudio(self._chat_id, self.audio_file)
|
||||
|
||||
audio = message.audio
|
||||
|
||||
|
@ -195,7 +194,7 @@ class AudioTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_audio_empty_file(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['audio'] = open(os.devnull, 'rb')
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -207,7 +206,7 @@ class AudioTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_audio_empty_file_id(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['audio'] = ''
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -219,12 +218,13 @@ class AudioTest(BaseTest, unittest.TestCase):
|
|||
def test_error_audio_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del(json_dict['duration'])
|
||||
del (json_dict['file_id'])
|
||||
del (json_dict['duration'])
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.sendAudio(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -17,13 +17,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Bot"""
|
||||
|
||||
import io
|
||||
import os
|
||||
from datetime import datetime
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import io
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
|
@ -55,22 +54,26 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendMessage(self):
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей')
|
||||
message = self._bot.sendMessage(
|
||||
chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertTrue(isinstance(message.date, datetime))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSilentSendMessage(self):
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей',
|
||||
disable_notification=True)
|
||||
message = self._bot.sendMessage(
|
||||
chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей',
|
||||
disable_notification=True)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertTrue(isinstance(message.date, datetime))
|
||||
|
||||
@flaky(3, 1)
|
||||
|
@ -97,9 +100,10 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendPhoto(self):
|
||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(
|
||||
photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 1451)
|
||||
|
@ -108,10 +112,11 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSilentSendPhoto(self):
|
||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id,
|
||||
disable_notification=True)
|
||||
message = self._bot.sendPhoto(
|
||||
photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id,
|
||||
disable_notification=True)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 1451)
|
||||
|
@ -120,17 +125,21 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testResendPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(
|
||||
photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_id, 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
||||
self.assertEqual(
|
||||
message.photo[0].file_id,
|
||||
'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendJPGURLPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 822)
|
||||
|
@ -138,8 +147,9 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendPNGURLPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 684)
|
||||
|
@ -147,8 +157,9 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendGIFURLPhoto(self):
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 684)
|
||||
|
@ -158,8 +169,7 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
def testSendBufferedReaderPhoto(self):
|
||||
photo = open('tests/data/telegram.png', 'rb')
|
||||
br_photo = io.BufferedReader(io.BytesIO(photo.read()))
|
||||
message = self._bot.sendPhoto(photo=br_photo,
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo=br_photo, chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 1451)
|
||||
|
@ -179,7 +189,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(upf.photos[0][0].file_size, 12421)
|
||||
|
||||
def _test_invalid_token(self, token):
|
||||
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token', telegram.Bot, token)
|
||||
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token',
|
||||
telegram.Bot, token)
|
||||
|
||||
def testInvalidToken1(self):
|
||||
self._test_invalid_token('123')
|
||||
|
@ -191,12 +202,14 @@ class BotTest(BaseTest, unittest.TestCase):
|
|||
self._test_invalid_token('12:')
|
||||
|
||||
def testUnauthToken(self):
|
||||
with self.assertRaisesRegexp(telegram.error.Unauthorized, 'Unauthorized'):
|
||||
with self.assertRaisesRegexp(telegram.error.Unauthorized,
|
||||
'Unauthorized'):
|
||||
bot = telegram.Bot('1234:abcd1234')
|
||||
bot.getMe()
|
||||
|
||||
def testInvalidSrvResp(self):
|
||||
with self.assertRaisesRegexp(telegram.TelegramError, 'Invalid server response'):
|
||||
with self.assertRaisesRegexp(telegram.TelegramError,
|
||||
'Invalid server response'):
|
||||
# bypass the valid token check
|
||||
bot = telegram.Bot.__new__(telegram.Bot)
|
||||
bot.base_url = 'https://api.telegram.org/bot{0}'.format('12')
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""This module contains a object that represents Tests for Botan analytics integration"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -56,5 +56,6 @@ class BotanTest(BaseTest, unittest.TestCase):
|
|||
result = botan.track(message, 'named event')
|
||||
self.assertFalse(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# !/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
|
@ -16,12 +16,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Chat"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -67,5 +66,6 @@ class ChatTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(group_chat['title'], self.title)
|
||||
self.assertEqual(group_chat['type'], self.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
ChosenInlineResult"""
|
||||
|
||||
|
@ -37,7 +36,6 @@ class ChosenInlineResultTest(BaseTest, unittest.TestCase):
|
|||
"""This object represents Tests for Telegram ChosenInlineResult."""
|
||||
|
||||
def setUp(self):
|
||||
|
||||
user = telegram.User(1, 'First name')
|
||||
|
||||
self.result_id = 'result id'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# !/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
|
@ -16,12 +16,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Contact"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -66,5 +65,6 @@ class ContactTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(contact['last_name'], self.last_name)
|
||||
self.assertEqual(contact['user_id'], self.user_id)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Document"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -56,8 +56,7 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_document_png_file(self):
|
||||
message = self._bot.sendDocument(self._chat_id,
|
||||
self.document_file)
|
||||
message = self._bot.sendDocument(self._chat_id, self.document_file)
|
||||
|
||||
document = message.document
|
||||
|
||||
|
@ -87,8 +86,7 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_document_url_gif_file(self):
|
||||
message = self._bot.sendDocument(self._chat_id,
|
||||
self.document_file_url)
|
||||
message = self._bot.sendDocument(self._chat_id, self.document_file_url)
|
||||
|
||||
document = message.document
|
||||
|
||||
|
@ -141,7 +139,7 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_document_empty_file(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['document'] = open(os.devnull, 'rb')
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -153,7 +151,7 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_document_empty_file_id(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['document'] = ''
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -165,11 +163,12 @@ class DocumentTest(BaseTest, unittest.TestCase):
|
|||
def test_error_document_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.sendDocument(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Emoji"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from telegram.emoji import Emoji
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram File"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -38,10 +38,10 @@ class FileTest(BaseTest, unittest.TestCase):
|
|||
self.video_file_id = 'BAADAQADXwADHyP1BwJFTcmY2RYCAg'
|
||||
self.voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg'
|
||||
|
||||
|
||||
self.json_dict = {
|
||||
'file_id': self.audio_file_id,
|
||||
'file_path': 'https://api.telegram.org/file/bot133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0/document/file_3',
|
||||
'file_path':
|
||||
'https://api.telegram.org/file/bot133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0/document/file_3',
|
||||
'file_size': 28232
|
||||
}
|
||||
|
||||
|
@ -123,8 +123,8 @@ class FileTest(BaseTest, unittest.TestCase):
|
|||
def test_error_get_empty_file_id(self):
|
||||
json_dict = self.json_dict
|
||||
json_dict['file_id'] = ''
|
||||
del(json_dict['file_path'])
|
||||
del(json_dict['file_size'])
|
||||
del (json_dict['file_path'])
|
||||
del (json_dict['file_size'])
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
lambda: self._bot.getFile(**json_dict))
|
||||
|
@ -132,12 +132,12 @@ class FileTest(BaseTest, unittest.TestCase):
|
|||
def test_error_file_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del(json_dict['file_path'])
|
||||
del(json_dict['file_size'])
|
||||
del (json_dict['file_id'])
|
||||
del (json_dict['file_path'])
|
||||
del (json_dict['file_size'])
|
||||
|
||||
self.assertRaises(TypeError, lambda: self._bot.getFile(**json_dict))
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.getFile(**json_dict))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
157
tests/test_filters.py
Normal file
157
tests/test_filters.py
Normal file
|
@ -0,0 +1,157 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""
|
||||
This module contains a object that represents Tests for MessageHandler.Filters
|
||||
"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
from telegram import Update, Message, User, Chat
|
||||
from telegram.ext import Filters
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class FiltersTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for MessageHandler.Filters"""
|
||||
|
||||
def setUp(self):
|
||||
self.message = Message(0, User(0, "Testuser"), datetime.now(),
|
||||
Chat(0, 'private'))
|
||||
self.update = Update(0, message=self.message)
|
||||
|
||||
def test_filters_text(self):
|
||||
self.message.text = 'test'
|
||||
self.assertTrue(Filters.text(self.update))
|
||||
self.message.text = '/test'
|
||||
self.assertFalse(Filters.text(self.update))
|
||||
|
||||
def test_filters_command(self):
|
||||
self.message.text = 'test'
|
||||
self.assertFalse(Filters.command(self.update))
|
||||
self.message.text = '/test'
|
||||
self.assertTrue(Filters.command(self.update))
|
||||
|
||||
def test_filters_audio(self):
|
||||
self.message.audio = 'test'
|
||||
self.assertTrue(Filters.audio(self.update))
|
||||
self.message.audio = None
|
||||
self.assertFalse(Filters.audio(self.update))
|
||||
|
||||
def test_filters_document(self):
|
||||
self.message.document = 'test'
|
||||
self.assertTrue(Filters.document(self.update))
|
||||
self.message.document = None
|
||||
self.assertFalse(Filters.document(self.update))
|
||||
|
||||
def test_filters_photo(self):
|
||||
self.message.photo = 'test'
|
||||
self.assertTrue(Filters.photo(self.update))
|
||||
self.message.photo = None
|
||||
self.assertFalse(Filters.photo(self.update))
|
||||
|
||||
def test_filters_sticker(self):
|
||||
self.message.sticker = 'test'
|
||||
self.assertTrue(Filters.sticker(self.update))
|
||||
self.message.sticker = None
|
||||
self.assertFalse(Filters.sticker(self.update))
|
||||
|
||||
def test_filters_video(self):
|
||||
self.message.video = 'test'
|
||||
self.assertTrue(Filters.video(self.update))
|
||||
self.message.video = None
|
||||
self.assertFalse(Filters.video(self.update))
|
||||
|
||||
def test_filters_voice(self):
|
||||
self.message.voice = 'test'
|
||||
self.assertTrue(Filters.voice(self.update))
|
||||
self.message.voice = None
|
||||
self.assertFalse(Filters.voice(self.update))
|
||||
|
||||
def test_filters_contact(self):
|
||||
self.message.contact = 'test'
|
||||
self.assertTrue(Filters.contact(self.update))
|
||||
self.message.contact = None
|
||||
self.assertFalse(Filters.contact(self.update))
|
||||
|
||||
def test_filters_location(self):
|
||||
self.message.location = 'test'
|
||||
self.assertTrue(Filters.location(self.update))
|
||||
self.message.location = None
|
||||
self.assertFalse(Filters.location(self.update))
|
||||
|
||||
def test_filters_venue(self):
|
||||
self.message.venue = 'test'
|
||||
self.assertTrue(Filters.venue(self.update))
|
||||
self.message.venue = None
|
||||
self.assertFalse(Filters.venue(self.update))
|
||||
|
||||
def test_filters_status_update(self):
|
||||
self.assertFalse(Filters.status_update(self.update))
|
||||
|
||||
self.message.new_chat_member = 'test'
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.new_chat_member = None
|
||||
|
||||
self.message.left_chat_member = 'test'
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.left_chat_member = None
|
||||
|
||||
self.message.new_chat_title = 'test'
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.new_chat_title = ''
|
||||
|
||||
self.message.new_chat_photo = 'test'
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.new_chat_photo = None
|
||||
|
||||
self.message.delete_chat_photo = True
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.delete_chat_photo = False
|
||||
|
||||
self.message.group_chat_created = True
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.group_chat_created = False
|
||||
|
||||
self.message.supergroup_chat_created = True
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.supergroup_chat_created = False
|
||||
|
||||
self.message.migrate_to_chat_id = 100
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.migrate_to_chat_id = 0
|
||||
|
||||
self.message.migrate_from_chat_id = 100
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.migrate_from_chat_id = 0
|
||||
|
||||
self.message.channel_chat_created = True
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.channel_chat_created = False
|
||||
|
||||
self.message.pinned_message = 'test'
|
||||
self.assertTrue(Filters.status_update(self.update))
|
||||
self.message.pinned_message = None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -17,11 +17,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram ForceReply"""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -39,31 +39,34 @@ class ForceReplyTest(BaseTest, unittest.TestCase):
|
|||
'force_reply': self.force_reply,
|
||||
'selective': self.selective,
|
||||
}
|
||||
|
||||
|
||||
def test_send_message_with_force_reply(self):
|
||||
message = self._bot.sendMessage(self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ForceReply.de_json(self.json_dict))
|
||||
|
||||
message = self._bot.sendMessage(
|
||||
self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ForceReply.de_json(self.json_dict))
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_force_reply_de_json(self):
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(force_reply.force_reply, self.force_reply)
|
||||
self.assertEqual(force_reply.selective, self.selective)
|
||||
|
||||
|
||||
def test_force_reply_to_json(self):
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(force_reply.to_json()))
|
||||
|
||||
|
||||
def test_force_reply_to_dict(self):
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(force_reply['force_reply'], self.force_reply)
|
||||
self.assertEqual(force_reply['selective'], self.selective)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
77
tests/test_inlinekeyboardbutton.py
Normal file
77
tests/test_inlinekeyboardbutton.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram InlineKeyboardButton"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineKeyboardButtonTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram KeyboardButton."""
|
||||
|
||||
def setUp(self):
|
||||
self.text = 'text'
|
||||
self.url = 'url'
|
||||
self.callback_data = 'callback data'
|
||||
self.switch_inline_query = ''
|
||||
|
||||
self.json_dict = {
|
||||
'text': self.text,
|
||||
'url': self.url,
|
||||
'callback_data': self.callback_data,
|
||||
'switch_inline_query': self.switch_inline_query
|
||||
}
|
||||
|
||||
def test_inline_keyboard_button_de_json(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertEqual(inline_keyboard_button.text, self.text)
|
||||
self.assertEqual(inline_keyboard_button.url, self.url)
|
||||
self.assertEqual(inline_keyboard_button.callback_data,
|
||||
self.callback_data)
|
||||
self.assertEqual(inline_keyboard_button.switch_inline_query,
|
||||
self.switch_inline_query)
|
||||
|
||||
def test_inline_keyboard_button_to_json(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(inline_keyboard_button.to_json()))
|
||||
|
||||
def test_inline_keyboard_button_to_dict(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(inline_keyboard_button))
|
||||
self.assertDictEqual(self.json_dict, inline_keyboard_button)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
80
tests/test_inlinekeyboardmarkup.py
Normal file
80
tests/test_inlinekeyboardmarkup.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram InlineKeyboardMarkup"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram KeyboardButton."""
|
||||
|
||||
def setUp(self):
|
||||
self.inline_keyboard = [[telegram.InlineKeyboardButton(
|
||||
text='button1',
|
||||
callback_data='data1'), telegram.InlineKeyboardButton(
|
||||
text='button2', callback_data='data2')]]
|
||||
|
||||
self.json_dict = {
|
||||
'inline_keyboard': [[self.inline_keyboard[0][0].to_dict(),
|
||||
self.inline_keyboard[0][1].to_dict()]],
|
||||
}
|
||||
|
||||
def test_send_message_with_inline_keyboard_markup(self):
|
||||
message = self._bot.sendMessage(
|
||||
self._chat_id,
|
||||
'Testing InlineKeyboardMarkup',
|
||||
reply_markup=telegram.InlineKeyboardMarkup(self.inline_keyboard))
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, 'Testing InlineKeyboardMarkup')
|
||||
|
||||
def test_inline_keyboard_markup_de_json(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard,
|
||||
list))
|
||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard[0][
|
||||
0], telegram.InlineKeyboardButton))
|
||||
|
||||
def test_inline_keyboard_markup_to_json(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(inline_keyboard_markup.to_json()))
|
||||
|
||||
def test_inline_keyboard_markup_to_dict(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard,
|
||||
list))
|
||||
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard[0][
|
||||
0], telegram.InlineKeyboardButton))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQuery"""
|
||||
|
||||
|
@ -37,7 +36,6 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
|||
"""This object represents Tests for Telegram InlineQuery."""
|
||||
|
||||
def setUp(self):
|
||||
|
||||
user = telegram.User(1, 'First name')
|
||||
|
||||
self.id = 'id'
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultArticle"""
|
||||
|
||||
|
@ -40,6 +39,11 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
self.id = 'id'
|
||||
self.type = 'article'
|
||||
self.title = 'title'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
self.url = 'url'
|
||||
self.hide_url = True
|
||||
self.description = 'description'
|
||||
|
@ -51,6 +55,8 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
'type': self.type,
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
'url': self.url,
|
||||
'hide_url': self.hide_url,
|
||||
'description': self.description,
|
||||
|
@ -65,6 +71,10 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(article.type, self.type)
|
||||
self.assertEqual(article.id, self.id)
|
||||
self.assertEqual(article.title, self.title)
|
||||
self.assertDictEqual(article.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(article.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
self.assertEqual(article.url, self.url)
|
||||
self.assertEqual(article.hide_url, self.hide_url)
|
||||
self.assertEqual(article.description, self.description)
|
||||
|
@ -78,8 +88,8 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
self.assertTrue(self.is_json(article.to_json()))
|
||||
|
||||
def test_article_to_dict(self):
|
||||
article = \
|
||||
telegram.InlineQueryResultArticle.de_json(self.json_dict).to_dict()
|
||||
article = telegram.InlineQueryResultArticle.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(article))
|
||||
self.assertDictEqual(self.json_dict, article)
|
||||
|
|
90
tests/test_inlinequeryresultaudio.py
Normal file
90
tests/test_inlinequeryresultaudio.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultAudio"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InlineQueryResultAudio."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'audio'
|
||||
self.audio_url = 'audio url'
|
||||
self.title = 'title'
|
||||
self.performer = 'performer'
|
||||
self.audio_duration = 'audio_duration'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'audio_url': self.audio_url,
|
||||
'title': self.title,
|
||||
'performer': self.performer,
|
||||
'audio_duration': self.audio_duration,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_audio_de_json(self):
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(audio.type, self.type)
|
||||
self.assertEqual(audio.id, self.id)
|
||||
self.assertEqual(audio.audio_url, self.audio_url)
|
||||
self.assertEqual(audio.title, self.title)
|
||||
self.assertEqual(audio.performer, self.performer)
|
||||
self.assertEqual(audio.audio_duration, self.audio_duration)
|
||||
self.assertDictEqual(audio.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(audio.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_audio_to_json(self):
|
||||
audio = telegram.InlineQueryResultAudio.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(audio.to_json()))
|
||||
|
||||
def test_audio_to_dict(self):
|
||||
audio = telegram.InlineQueryResultAudio.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(audio))
|
||||
self.assertDictEqual(self.json_dict, audio)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
82
tests/test_inlinequeryresultcachedaudio.py
Normal file
82
tests/test_inlinequeryresultcachedaudio.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedAudio"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram
|
||||
InlineQueryResultCachedAudio."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'audio'
|
||||
self.audio_file_id = 'audio file id'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'audio_file_id': self.audio_file_id,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_audio_de_json(self):
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(audio.type, self.type)
|
||||
self.assertEqual(audio.id, self.id)
|
||||
self.assertEqual(audio.audio_file_id, self.audio_file_id)
|
||||
self.assertDictEqual(audio.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(audio.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_audio_to_json(self):
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(audio.to_json()))
|
||||
|
||||
def test_audio_to_dict(self):
|
||||
audio = telegram.InlineQueryResultCachedAudio.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(audio))
|
||||
self.assertDictEqual(self.json_dict, audio)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
92
tests/test_inlinequeryresultcacheddocument.py
Normal file
92
tests/test_inlinequeryresultcacheddocument.py
Normal file
|
@ -0,0 +1,92 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedDocument"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram
|
||||
InlineQueryResultCachedDocument."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'document'
|
||||
self.document_file_id = 'document file id'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.description = 'description'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'type': self.type,
|
||||
'document_file_id': self.document_file_id,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'description': self.description,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_document_de_json(self):
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertEqual(document.id, self.id)
|
||||
self.assertEqual(document.type, self.type)
|
||||
self.assertEqual(document.document_file_id, self.document_file_id)
|
||||
self.assertEqual(document.title, self.title)
|
||||
self.assertEqual(document.caption, self.caption)
|
||||
self.assertEqual(document.description, self.description)
|
||||
self.assertDictEqual(document.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(document.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_document_to_json(self):
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(document.to_json()))
|
||||
|
||||
def test_document_to_dict(self):
|
||||
document = telegram.InlineQueryResultCachedDocument.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(document))
|
||||
self.assertDictEqual(self.json_dict, document)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
87
tests/test_inlinequeryresultcachedgif.py
Normal file
87
tests/test_inlinequeryresultcachedgif.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedGif"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedGifTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InlineQueryResultCachedGif."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'gif'
|
||||
self.gif_file_id = 'gif file id'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'gif_file_id': self.gif_file_id,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_gif_de_json(self):
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(gif.type, self.type)
|
||||
self.assertEqual(gif.id, self.id)
|
||||
self.assertEqual(gif.gif_file_id, self.gif_file_id)
|
||||
self.assertEqual(gif.title, self.title)
|
||||
self.assertEqual(gif.caption, self.caption)
|
||||
self.assertDictEqual(gif.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(gif.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_gif_to_json(self):
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(gif.to_json()))
|
||||
|
||||
def test_gif_to_dict(self):
|
||||
gif = telegram.InlineQueryResultCachedGif.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(gif))
|
||||
self.assertDictEqual(self.json_dict, gif)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
90
tests/test_inlinequeryresultcachedmpeg4gif.py
Normal file
90
tests/test_inlinequeryresultcachedmpeg4gif.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedMpeg4Gif"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedMpeg4GifTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram
|
||||
InlineQueryResultCachedMpeg4Gif."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'mpeg4_gif'
|
||||
self.mpeg4_file_id = 'mpeg4 file id'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'mpeg4_file_id': self.mpeg4_file_id,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_mpeg4_de_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertEqual(mpeg4.type, self.type)
|
||||
self.assertEqual(mpeg4.id, self.id)
|
||||
self.assertEqual(mpeg4.mpeg4_file_id, self.mpeg4_file_id)
|
||||
self.assertEqual(mpeg4.title, self.title)
|
||||
self.assertEqual(mpeg4.caption, self.caption)
|
||||
self.assertDictEqual(mpeg4.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(mpeg4.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_mpeg4_to_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(mpeg4.to_json()))
|
||||
|
||||
def test_mpeg4_to_dict(self):
|
||||
mpeg4 = telegram.InlineQueryResultCachedMpeg4Gif.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(mpeg4))
|
||||
self.assertDictEqual(self.json_dict, mpeg4)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
91
tests/test_inlinequeryresultcachedphoto.py
Normal file
91
tests/test_inlinequeryresultcachedphoto.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedPhoto"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedPhotoTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram
|
||||
InlineQueryResultCachedPhoto."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'photo'
|
||||
self.photo_file_id = 'photo file id'
|
||||
self.title = 'title'
|
||||
self.description = 'description'
|
||||
self.caption = 'caption'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'photo_file_id': self.photo_file_id,
|
||||
'title': self.title,
|
||||
'description': self.description,
|
||||
'caption': self.caption,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_photo_de_json(self):
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(photo.type, self.type)
|
||||
self.assertEqual(photo.id, self.id)
|
||||
self.assertEqual(photo.photo_file_id, self.photo_file_id)
|
||||
self.assertEqual(photo.title, self.title)
|
||||
self.assertEqual(photo.description, self.description)
|
||||
self.assertEqual(photo.caption, self.caption)
|
||||
self.assertDictEqual(photo.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(photo.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_photo_to_json(self):
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(photo.to_json()))
|
||||
|
||||
def test_photo_to_dict(self):
|
||||
photo = telegram.InlineQueryResultCachedPhoto.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(photo))
|
||||
self.assertDictEqual(self.json_dict, photo)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
84
tests/test_inlinequeryresultcachedsticker.py
Normal file
84
tests/test_inlinequeryresultcachedsticker.py
Normal file
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedSticker"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedStickerTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram
|
||||
InlineQueryResultCachedSticker."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'sticker'
|
||||
self.sticker_file_id = 'sticker file id'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'sticker_file_id': self.sticker_file_id,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_sticker_de_json(self):
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertEqual(sticker.type, self.type)
|
||||
self.assertEqual(sticker.id, self.id)
|
||||
self.assertEqual(sticker.sticker_file_id, self.sticker_file_id)
|
||||
self.assertDictEqual(sticker.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(sticker.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_sticker_to_json(self):
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(sticker.to_json()))
|
||||
|
||||
def test_sticker_to_dict(self):
|
||||
sticker = telegram.InlineQueryResultCachedSticker.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(sticker))
|
||||
self.assertDictEqual(self.json_dict, sticker)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
91
tests/test_inlinequeryresultcachedvideo.py
Normal file
91
tests/test_inlinequeryresultcachedvideo.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedVideo"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedVideoTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram
|
||||
InlineQueryResultCachedVideo."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'video'
|
||||
self.video_file_id = 'video file id'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.description = 'description'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'video_file_id': self.video_file_id,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'description': self.description,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_video_de_json(self):
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(video.type, self.type)
|
||||
self.assertEqual(video.id, self.id)
|
||||
self.assertEqual(video.video_file_id, self.video_file_id)
|
||||
self.assertEqual(video.title, self.title)
|
||||
self.assertEqual(video.description, self.description)
|
||||
self.assertEqual(video.caption, self.caption)
|
||||
self.assertDictEqual(video.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(video.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_video_to_json(self):
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(video.to_json()))
|
||||
|
||||
def test_video_to_dict(self):
|
||||
video = telegram.InlineQueryResultCachedVideo.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(video))
|
||||
self.assertDictEqual(self.json_dict, video)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
88
tests/test_inlinequeryresultcachedvoice.py
Normal file
88
tests/test_inlinequeryresultcachedvoice.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultCachedVoice"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram
|
||||
InlineQueryResultCachedVoice."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'voice'
|
||||
self.voice_file_id = 'voice file id'
|
||||
self.title = 'title'
|
||||
self.description = 'description'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'voice_file_id': self.voice_file_id,
|
||||
'title': self.title,
|
||||
'description': self.description,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_voice_de_json(self):
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(voice.type, self.type)
|
||||
self.assertEqual(voice.id, self.id)
|
||||
self.assertEqual(voice.voice_file_id, self.voice_file_id)
|
||||
self.assertEqual(voice.title, self.title)
|
||||
self.assertEqual(voice.description, self.description)
|
||||
self.assertDictEqual(voice.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(voice.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_voice_to_json(self):
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(voice.to_json()))
|
||||
|
||||
def test_voice_to_dict(self):
|
||||
voice = telegram.InlineQueryResultCachedVoice.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(voice))
|
||||
self.assertDictEqual(self.json_dict, voice)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
95
tests/test_inlinequeryresultcontact.py
Normal file
95
tests/test_inlinequeryresultcontact.py
Normal file
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultContact"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultContactTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InlineQueryResultContact."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'contact'
|
||||
self.phone_number = 'phone_number'
|
||||
self.first_name = 'first_name'
|
||||
self.last_name = 'last_name'
|
||||
self.thumb_url = 'thumb url'
|
||||
self.thumb_width = 10
|
||||
self.thumb_height = 15
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'type': self.type,
|
||||
'phone_number': self.phone_number,
|
||||
'first_name': self.first_name,
|
||||
'last_name': self.last_name,
|
||||
'thumb_url': self.thumb_url,
|
||||
'thumb_width': self.thumb_width,
|
||||
'thumb_height': self.thumb_height,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_contact_de_json(self):
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(contact.id, self.id)
|
||||
self.assertEqual(contact.type, self.type)
|
||||
self.assertEqual(contact.phone_number, self.phone_number)
|
||||
self.assertEqual(contact.first_name, self.first_name)
|
||||
self.assertEqual(contact.last_name, self.last_name)
|
||||
self.assertEqual(contact.thumb_url, self.thumb_url)
|
||||
self.assertEqual(contact.thumb_width, self.thumb_width)
|
||||
self.assertEqual(contact.thumb_height, self.thumb_height)
|
||||
self.assertDictEqual(contact.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(contact.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_contact_to_json(self):
|
||||
contact = telegram.InlineQueryResultContact.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(contact.to_json()))
|
||||
|
||||
def test_contact_to_dict(self):
|
||||
contact = telegram.InlineQueryResultContact.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(contact))
|
||||
self.assertDictEqual(self.json_dict, contact)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
101
tests/test_inlinequeryresultdocument.py
Normal file
101
tests/test_inlinequeryresultdocument.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultDocument"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InlineQueryResultDocument."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'document'
|
||||
self.document_url = 'document url'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.mime_type = 'mime type'
|
||||
self.description = 'description'
|
||||
self.thumb_url = 'thumb url'
|
||||
self.thumb_width = 10
|
||||
self.thumb_height = 15
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'type': self.type,
|
||||
'document_url': self.document_url,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'mime_type': self.mime_type,
|
||||
'description': self.description,
|
||||
'thumb_url': self.thumb_url,
|
||||
'thumb_width': self.thumb_width,
|
||||
'thumb_height': self.thumb_height,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_document_de_json(self):
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(document.id, self.id)
|
||||
self.assertEqual(document.type, self.type)
|
||||
self.assertEqual(document.document_url, self.document_url)
|
||||
self.assertEqual(document.title, self.title)
|
||||
self.assertEqual(document.caption, self.caption)
|
||||
self.assertEqual(document.mime_type, self.mime_type)
|
||||
self.assertEqual(document.description, self.description)
|
||||
self.assertEqual(document.thumb_url, self.thumb_url)
|
||||
self.assertEqual(document.thumb_width, self.thumb_width)
|
||||
self.assertEqual(document.thumb_height, self.thumb_height)
|
||||
self.assertDictEqual(document.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(document.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_document_to_json(self):
|
||||
document = telegram.InlineQueryResultDocument.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(document.to_json()))
|
||||
|
||||
def test_document_to_dict(self):
|
||||
document = telegram.InlineQueryResultDocument.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(document))
|
||||
self.assertDictEqual(self.json_dict, document)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultGif"""
|
||||
|
||||
|
@ -45,6 +44,11 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
self.thumb_url = 'thumb url'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
|
@ -55,6 +59,8 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
'thumb_url': self.thumb_url,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_gif_de_json(self):
|
||||
|
@ -68,6 +74,10 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(gif.thumb_url, self.thumb_url)
|
||||
self.assertEqual(gif.title, self.title)
|
||||
self.assertEqual(gif.caption, self.caption)
|
||||
self.assertDictEqual(gif.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(gif.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_gif_to_json(self):
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict)
|
||||
|
|
95
tests/test_inlinequeryresultlocation.py
Normal file
95
tests/test_inlinequeryresultlocation.py
Normal file
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultLocation"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultLocationTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InlineQueryResultLocation."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'location'
|
||||
self.latitude = 'latitude'
|
||||
self.longitude = 'longitude'
|
||||
self.title = 'title'
|
||||
self.thumb_url = 'thumb url'
|
||||
self.thumb_width = 10
|
||||
self.thumb_height = 15
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'type': self.type,
|
||||
'latitude': self.latitude,
|
||||
'longitude': self.longitude,
|
||||
'title': self.title,
|
||||
'thumb_url': self.thumb_url,
|
||||
'thumb_width': self.thumb_width,
|
||||
'thumb_height': self.thumb_height,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_location_de_json(self):
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(location.id, self.id)
|
||||
self.assertEqual(location.type, self.type)
|
||||
self.assertEqual(location.latitude, self.latitude)
|
||||
self.assertEqual(location.longitude, self.longitude)
|
||||
self.assertEqual(location.title, self.title)
|
||||
self.assertEqual(location.thumb_url, self.thumb_url)
|
||||
self.assertEqual(location.thumb_width, self.thumb_width)
|
||||
self.assertEqual(location.thumb_height, self.thumb_height)
|
||||
self.assertDictEqual(location.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(location.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_location_to_json(self):
|
||||
location = telegram.InlineQueryResultLocation.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(location.to_json()))
|
||||
|
||||
def test_location_to_dict(self):
|
||||
location = telegram.InlineQueryResultLocation.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(location))
|
||||
self.assertDictEqual(self.json_dict, location)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultMpeg4Gif"""
|
||||
|
||||
|
@ -45,6 +44,11 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
self.thumb_url = 'thumb url'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
|
@ -55,6 +59,8 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
'thumb_url': self.thumb_url,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_mpeg4_de_json(self):
|
||||
|
@ -68,6 +74,10 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(mpeg4.thumb_url, self.thumb_url)
|
||||
self.assertEqual(mpeg4.title, self.title)
|
||||
self.assertEqual(mpeg4.caption, self.caption)
|
||||
self.assertDictEqual(mpeg4.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(mpeg4.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_mpeg4_to_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict)
|
||||
|
@ -75,8 +85,8 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
self.assertTrue(self.is_json(mpeg4.to_json()))
|
||||
|
||||
def test_mpeg4_to_dict(self):
|
||||
mpeg4 = \
|
||||
telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict).to_dict()
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(mpeg4))
|
||||
self.assertDictEqual(self.json_dict, mpeg4)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultPhoto"""
|
||||
|
||||
|
@ -44,7 +43,13 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
self.photo_height = 15
|
||||
self.thumb_url = 'thumb url'
|
||||
self.title = 'title'
|
||||
self.description = 'description'
|
||||
self.caption = 'caption'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
|
@ -54,7 +59,10 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
'photo_height': self.photo_height,
|
||||
'thumb_url': self.thumb_url,
|
||||
'title': self.title,
|
||||
'description': self.description,
|
||||
'caption': self.caption,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_photo_de_json(self):
|
||||
|
@ -67,7 +75,12 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(photo.photo_height, self.photo_height)
|
||||
self.assertEqual(photo.thumb_url, self.thumb_url)
|
||||
self.assertEqual(photo.title, self.title)
|
||||
self.assertEqual(photo.description, self.description)
|
||||
self.assertEqual(photo.caption, self.caption)
|
||||
self.assertDictEqual(photo.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(photo.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_photo_to_json(self):
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict)
|
||||
|
@ -75,8 +88,8 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
self.assertTrue(self.is_json(photo.to_json()))
|
||||
|
||||
def test_photo_to_dict(self):
|
||||
photo = \
|
||||
telegram.InlineQueryResultPhoto.de_json(self.json_dict).to_dict()
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(photo))
|
||||
self.assertDictEqual(self.json_dict, photo)
|
||||
|
|
101
tests/test_inlinequeryresultvenue.py
Normal file
101
tests/test_inlinequeryresultvenue.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultVenue"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultVenueTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InlineQueryResultVenue."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'venue'
|
||||
self.latitude = 'latitude'
|
||||
self.longitude = 'longitude'
|
||||
self.title = 'title'
|
||||
self._address = 'address' # nose binds self.address for testing
|
||||
self.foursquare_id = 'foursquare id'
|
||||
self.thumb_url = 'thumb url'
|
||||
self.thumb_width = 10
|
||||
self.thumb_height = 15
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'type': self.type,
|
||||
'latitude': self.latitude,
|
||||
'longitude': self.longitude,
|
||||
'title': self.title,
|
||||
'address': self._address,
|
||||
'foursquare_id': self.foursquare_id,
|
||||
'thumb_url': self.thumb_url,
|
||||
'thumb_width': self.thumb_width,
|
||||
'thumb_height': self.thumb_height,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_venue_de_json(self):
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(venue.id, self.id)
|
||||
self.assertEqual(venue.type, self.type)
|
||||
self.assertEqual(venue.latitude, self.latitude)
|
||||
self.assertEqual(venue.longitude, self.longitude)
|
||||
self.assertEqual(venue.title, self.title)
|
||||
self.assertEqual(venue.address, self._address)
|
||||
self.assertEqual(venue.foursquare_id, self.foursquare_id)
|
||||
self.assertEqual(venue.thumb_url, self.thumb_url)
|
||||
self.assertEqual(venue.thumb_width, self.thumb_width)
|
||||
self.assertEqual(venue.thumb_height, self.thumb_height)
|
||||
self.assertDictEqual(venue.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(venue.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_venue_to_json(self):
|
||||
venue = telegram.InlineQueryResultVenue.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(venue.to_json()))
|
||||
|
||||
def test_venue_to_dict(self):
|
||||
venue = telegram.InlineQueryResultVenue.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(venue))
|
||||
self.assertDictEqual(self.json_dict, venue)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultVideo"""
|
||||
|
||||
|
@ -48,6 +47,11 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.description = 'description'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
|
@ -61,6 +65,8 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'description': self.description,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_video_de_json(self):
|
||||
|
@ -77,6 +83,10 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(video.title, self.title)
|
||||
self.assertEqual(video.description, self.description)
|
||||
self.assertEqual(video.caption, self.caption)
|
||||
self.assertDictEqual(video.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(video.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_video_to_json(self):
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict)
|
||||
|
@ -84,8 +94,8 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
self.assertTrue(self.is_json(video.to_json()))
|
||||
|
||||
def test_video_to_dict(self):
|
||||
video = \
|
||||
telegram.InlineQueryResultVideo.de_json(self.json_dict).to_dict()
|
||||
video = telegram.InlineQueryResultVideo.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(video))
|
||||
self.assertDictEqual(self.json_dict, video)
|
||||
|
|
87
tests/test_inlinequeryresultvoice.py
Normal file
87
tests/test_inlinequeryresultvoice.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InlineQueryResultVoice"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InlineQueryResultVoiceTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InlineQueryResultVoice."""
|
||||
|
||||
def setUp(self):
|
||||
self.id = 'id'
|
||||
self.type = 'voice'
|
||||
self.voice_url = 'voice url'
|
||||
self.title = 'title'
|
||||
self.voice_duration = 'voice_duration'
|
||||
self.input_message_content = telegram.InputTextMessageContent(
|
||||
'input_message_content')
|
||||
self.reply_markup = telegram.InlineKeyboardMarkup([[
|
||||
telegram.InlineKeyboardButton('reply_markup')
|
||||
]])
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'voice_url': self.voice_url,
|
||||
'title': self.title,
|
||||
'voice_duration': self.voice_duration,
|
||||
'input_message_content': self.input_message_content.to_dict(),
|
||||
'reply_markup': self.reply_markup.to_dict(),
|
||||
}
|
||||
|
||||
def test_voice_de_json(self):
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(voice.type, self.type)
|
||||
self.assertEqual(voice.id, self.id)
|
||||
self.assertEqual(voice.voice_url, self.voice_url)
|
||||
self.assertEqual(voice.title, self.title)
|
||||
self.assertEqual(voice.voice_duration, self.voice_duration)
|
||||
self.assertDictEqual(voice.input_message_content.to_dict(),
|
||||
self.input_message_content.to_dict())
|
||||
self.assertDictEqual(voice.reply_markup.to_dict(),
|
||||
self.reply_markup.to_dict())
|
||||
|
||||
def test_voice_to_json(self):
|
||||
voice = telegram.InlineQueryResultVoice.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(voice.to_json()))
|
||||
|
||||
def test_voice_to_dict(self):
|
||||
voice = telegram.InlineQueryResultVoice.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(voice))
|
||||
self.assertDictEqual(self.json_dict, voice)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
85
tests/test_inputcontactmessagecontent.py
Normal file
85
tests/test_inputcontactmessagecontent.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InputContactMessageContent"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InputContactMessageContentTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InputContactMessageContent."""
|
||||
|
||||
def setUp(self):
|
||||
self.phone_number = 'phone number'
|
||||
self.first_name = 'first name'
|
||||
self.last_name = 'last name'
|
||||
|
||||
self.json_dict = {
|
||||
'first_name': self.first_name,
|
||||
'phone_number': self.phone_number,
|
||||
'last_name': self.last_name,
|
||||
}
|
||||
|
||||
def test_icmc_de_json(self):
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(icmc.first_name, self.first_name)
|
||||
self.assertEqual(icmc.phone_number, self.phone_number)
|
||||
self.assertEqual(icmc.last_name, self.last_name)
|
||||
|
||||
def test_icmc_de_json_factory(self):
|
||||
icmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(icmc, telegram.InputContactMessageContent))
|
||||
|
||||
def test_icmc_de_json_factory_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del (json_dict['phone_number'])
|
||||
del (json_dict['first_name'])
|
||||
|
||||
icmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
|
||||
self.assertFalse(icmc)
|
||||
|
||||
def test_icmc_to_json(self):
|
||||
icmc = telegram.InputContactMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(icmc.to_json()))
|
||||
|
||||
def test_icmc_to_dict(self):
|
||||
icmc = telegram.InputContactMessageContent.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(icmc))
|
||||
self.assertDictEqual(self.json_dict, icmc)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
83
tests/test_inputlocationmessagecontent.py
Normal file
83
tests/test_inputlocationmessagecontent.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InputLocationMessageContent"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InputLocationMessageContentTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InputLocationMessageContent."""
|
||||
|
||||
def setUp(self):
|
||||
self.latitude = 1.
|
||||
self.longitude = 2.
|
||||
|
||||
self.json_dict = {
|
||||
'longitude': self.longitude,
|
||||
'latitude': self.latitude,
|
||||
}
|
||||
|
||||
def test_ilmc_de_json(self):
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(ilmc.longitude, self.longitude)
|
||||
self.assertEqual(ilmc.latitude, self.latitude)
|
||||
|
||||
def test_ilmc_de_json_factory(self):
|
||||
ilmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(ilmc, telegram.InputLocationMessageContent))
|
||||
|
||||
def test_ilmc_de_json_factory_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del (json_dict['longitude'])
|
||||
# If none args are sent it will fall in a different condition
|
||||
# del (json_dict['latitude'])
|
||||
|
||||
ilmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
|
||||
self.assertFalse(ilmc)
|
||||
|
||||
def test_ilmc_to_json(self):
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(ilmc.to_json()))
|
||||
|
||||
def test_ilmc_to_dict(self):
|
||||
ilmc = telegram.InputLocationMessageContent.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(ilmc))
|
||||
self.assertDictEqual(self.json_dict, ilmc)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
45
tests/test_inputmessagecontent.py
Normal file
45
tests/test_inputmessagecontent.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InputMessageContent"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InputMessageContentTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InputMessageContent."""
|
||||
|
||||
def test_imc_de_json(self):
|
||||
imc = telegram.InputMessageContent.de_json(None)
|
||||
|
||||
self.assertFalse(imc)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
85
tests/test_inputtextmessagecontent.py
Normal file
85
tests/test_inputtextmessagecontent.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InputTextMessageContent"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InputTextMessageContentTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InputTextMessageContent."""
|
||||
|
||||
def setUp(self):
|
||||
self.message_text = '*message text*'
|
||||
self.parse_mode = telegram.ParseMode.MARKDOWN
|
||||
self.disable_web_page_preview = True
|
||||
|
||||
self.json_dict = {
|
||||
'parse_mode': self.parse_mode,
|
||||
'message_text': self.message_text,
|
||||
'disable_web_page_preview': self.disable_web_page_preview,
|
||||
}
|
||||
|
||||
def test_itmc_de_json(self):
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(itmc.parse_mode, self.parse_mode)
|
||||
self.assertEqual(itmc.message_text, self.message_text)
|
||||
self.assertEqual(itmc.disable_web_page_preview,
|
||||
self.disable_web_page_preview)
|
||||
|
||||
def test_itmc_de_json_factory(self):
|
||||
itmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(itmc, telegram.InputTextMessageContent))
|
||||
|
||||
def test_itmc_de_json_factory_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del (json_dict['message_text'])
|
||||
|
||||
itmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
|
||||
self.assertFalse(itmc)
|
||||
|
||||
def test_itmc_to_json(self):
|
||||
itmc = telegram.InputTextMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(itmc.to_json()))
|
||||
|
||||
def test_itmc_to_dict(self):
|
||||
itmc = telegram.InputTextMessageContent.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(itmc))
|
||||
self.assertDictEqual(self.json_dict, itmc)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
93
tests/test_inputvenuemessagecontent.py
Normal file
93
tests/test_inputvenuemessagecontent.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
InputVenueMessageContent"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class InputVenueMessageContentTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram InputVenueMessageContent."""
|
||||
|
||||
def setUp(self):
|
||||
self.latitude = 1.
|
||||
self.longitude = 2.
|
||||
self.title = 'title'
|
||||
self._address = 'address' # nose binds self.address for testing
|
||||
self.foursquare_id = 'foursquare id'
|
||||
|
||||
self.json_dict = {
|
||||
'longitude': self.longitude,
|
||||
'latitude': self.latitude,
|
||||
'title': self.title,
|
||||
'address': self._address,
|
||||
'foursquare_id': self.foursquare_id,
|
||||
}
|
||||
|
||||
def test_ivmc_de_json(self):
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(ivmc.longitude, self.longitude)
|
||||
self.assertEqual(ivmc.latitude, self.latitude)
|
||||
self.assertEqual(ivmc.title, self.title)
|
||||
self.assertEqual(ivmc.address, self._address)
|
||||
self.assertEqual(ivmc.foursquare_id, self.foursquare_id)
|
||||
|
||||
def test_ivmc_de_json_factory(self):
|
||||
ivmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(ivmc, telegram.InputVenueMessageContent))
|
||||
|
||||
def test_ivmc_de_json_factory_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del (json_dict['longitude'])
|
||||
del (json_dict['latitude'])
|
||||
del (json_dict['title'])
|
||||
del (json_dict['address'])
|
||||
|
||||
ivmc = telegram.InputMessageContent.de_json(json_dict)
|
||||
|
||||
self.assertFalse(ivmc)
|
||||
|
||||
def test_ivmc_to_json(self):
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(ivmc.to_json()))
|
||||
|
||||
def test_ivmc_to_dict(self):
|
||||
ivmc = telegram.InputVenueMessageContent.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(ivmc))
|
||||
self.assertDictEqual(self.json_dict, ivmc)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -17,7 +17,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""
|
||||
This module contains a object that represents Tests for JobQueue
|
||||
"""
|
||||
|
@ -46,7 +45,8 @@ root.setLevel(logging.INFO)
|
|||
|
||||
ch = logging.StreamHandler(sys.stdout)
|
||||
ch.setLevel(logging.WARN)
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
formatter = logging.Formatter(
|
||||
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
ch.setFormatter(formatter)
|
||||
root.addHandler(ch)
|
||||
|
||||
|
@ -111,5 +111,6 @@ class JobQueueTest(BaseTest, unittest.TestCase):
|
|||
sleep(2)
|
||||
self.assertEqual(1, self.result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
72
tests/test_keyboardbutton.py
Normal file
72
tests/test_keyboardbutton.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
KeyboardButton"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class KeyboardButtonTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram KeyboardButton."""
|
||||
|
||||
def setUp(self):
|
||||
self.text = 'text'
|
||||
self.request_location = True
|
||||
self.request_contact = True
|
||||
|
||||
self.json_dict = {
|
||||
'text': self.text,
|
||||
'request_location': self.request_location,
|
||||
'request_contact': self.request_contact,
|
||||
}
|
||||
|
||||
def test_keyboard_button_de_json(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(keyboard_button.text, self.text)
|
||||
self.assertEqual(keyboard_button.request_location,
|
||||
self.request_location)
|
||||
self.assertEqual(keyboard_button.request_contact, self.request_contact)
|
||||
|
||||
def test_keyboard_button_to_json(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(keyboard_button.to_json()))
|
||||
|
||||
def test_keyboard_button_to_dict(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(
|
||||
self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(keyboard_button))
|
||||
self.assertDictEqual(self.json_dict, keyboard_button)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -16,12 +16,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Location"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -41,8 +40,7 @@ class LocationTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_send_location_implicit_args(self):
|
||||
message = self._bot.sendLocation(self._chat_id,
|
||||
self.latitude,
|
||||
message = self._bot.sendLocation(self._chat_id, self.latitude,
|
||||
self.longitude)
|
||||
|
||||
location = message.location
|
||||
|
@ -90,12 +88,13 @@ class LocationTest(BaseTest, unittest.TestCase):
|
|||
def test_error_location_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['latitude'])
|
||||
del(json_dict['longitude'])
|
||||
del (json_dict['latitude'])
|
||||
del (json_dict['longitude'])
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.sendLocation(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
72
tests/test_messageentity.py
Normal file
72
tests/test_messageentity.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
MessageEntity"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class MessageEntityTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram MessageEntity."""
|
||||
|
||||
def setUp(self):
|
||||
self.type = 'type'
|
||||
self.offset = 1
|
||||
self.length = 2
|
||||
self.url = 'url'
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'offset': self.offset,
|
||||
'length': self.length,
|
||||
'url': self.url
|
||||
}
|
||||
|
||||
def test_sticker_de_json(self):
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(sticker.type, self.type)
|
||||
self.assertEqual(sticker.offset, self.offset)
|
||||
self.assertEqual(sticker.length, self.length)
|
||||
self.assertEqual(sticker.url, self.url)
|
||||
|
||||
def test_sticker_to_json(self):
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(sticker.to_json()))
|
||||
|
||||
def test_sticker_to_dict(self):
|
||||
sticker = telegram.MessageEntity.de_json(self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(sticker))
|
||||
self.assertDictEqual(self.json_dict, sticker)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -17,16 +17,17 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram ParseMode"""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class ParseMode(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram ParseMode."""
|
||||
|
||||
|
@ -34,22 +35,23 @@ class ParseMode(BaseTest, unittest.TestCase):
|
|||
self.markdown_text = "*bold* _italic_ [link](http://google.com)."
|
||||
self.html_text = '<b>bold</b> <i>italic</i> <a href="http://google.com">link</a>.'
|
||||
self.formatted_text_formatted = u'bold italic link.'
|
||||
|
||||
|
||||
def test_send_message_with_parse_mode_markdown(self):
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
text=self.markdown_text,
|
||||
parse_mode=telegram.ParseMode.MARKDOWN)
|
||||
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, self.formatted_text_formatted)
|
||||
|
||||
|
||||
def test_send_message_with_parse_mode_html(self):
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
text=self.html_text,
|
||||
parse_mode=telegram.ParseMode.HTML)
|
||||
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, self.formatted_text_formatted)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Photo"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -39,10 +39,13 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
self.photo_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.jpg'
|
||||
self.width = 300
|
||||
self.height = 300
|
||||
self.thumb = {'width': 90,
|
||||
'height': 90,
|
||||
'file_id': 'AgADAQADvb8xGx8j9QcpZDKxYoFK3bfX1i8ABBxRLXFhLnhIQ-gAAgI',
|
||||
'file_size': 1478}
|
||||
self.thumb = {
|
||||
'width': 90,
|
||||
'height': 90,
|
||||
'file_id':
|
||||
'AgADAQADvb8xGx8j9QcpZDKxYoFK3bfX1i8ABBxRLXFhLnhIQ-gAAgI',
|
||||
'file_size': 1478
|
||||
}
|
||||
self.file_size = 10209
|
||||
|
||||
# caption is part of sendPhoto method but not Photo object
|
||||
|
@ -83,8 +86,7 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_photo_jpg_file(self):
|
||||
message = self._bot.sendPhoto(self._chat_id,
|
||||
self.photo_file)
|
||||
message = self._bot.sendPhoto(self._chat_id, self.photo_file)
|
||||
|
||||
thumb, photo = message.photo
|
||||
|
||||
|
@ -105,8 +107,7 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_photo_url_jpg_file(self):
|
||||
message = self._bot.sendPhoto(self._chat_id,
|
||||
self.photo_file_url)
|
||||
message = self._bot.sendPhoto(self._chat_id, self.photo_file_url)
|
||||
|
||||
thumb, photo = message.photo
|
||||
|
||||
|
@ -171,7 +172,7 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_photo_empty_file(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['photo'] = open(os.devnull, 'rb')
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -183,7 +184,7 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_photo_empty_file_id(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['photo'] = ''
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -195,13 +196,14 @@ class PhotoTest(BaseTest, unittest.TestCase):
|
|||
def test_error_photo_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del(json_dict['width'])
|
||||
del(json_dict['height'])
|
||||
del (json_dict['file_id'])
|
||||
del (json_dict['width'])
|
||||
del (json_dict['height'])
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.sendPhoto(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram ReplyKeyboardHide"""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -39,31 +39,38 @@ class ReplyKeyboardHideTest(BaseTest, unittest.TestCase):
|
|||
'hide_keyboard': self.hide_keyboard,
|
||||
'selective': self.selective,
|
||||
}
|
||||
|
||||
|
||||
def test_send_message_with_reply_keyboard_hide(self):
|
||||
message = self._bot.sendMessage(self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ReplyKeyboardHide.de_json(self.json_dict))
|
||||
|
||||
message = self._bot.sendMessage(
|
||||
self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ReplyKeyboardHide.de_json(self.json_dict))
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_reply_keyboard_hide_de_json(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict)
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertEqual(reply_keyboard_hide.hide_keyboard, self.hide_keyboard)
|
||||
self.assertEqual(reply_keyboard_hide.selective, self.selective)
|
||||
|
||||
|
||||
def test_reply_keyboard_hide_to_json(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict)
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(reply_keyboard_hide.to_json()))
|
||||
|
||||
def test_reply_keyboard_hide_to_dict(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(reply_keyboard_hide['hide_keyboard'], self.hide_keyboard)
|
||||
def test_reply_keyboard_hide_to_dict(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertEqual(reply_keyboard_hide['hide_keyboard'],
|
||||
self.hide_keyboard)
|
||||
self.assertEqual(reply_keyboard_hide['selective'], self.selective)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram ReplyKeyboardMarkup"""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -47,37 +47,47 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
}
|
||||
|
||||
def test_send_message_with_reply_keyboard_markup(self):
|
||||
message = self._bot.sendMessage(self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ReplyKeyboardMarkup.de_json(self.json_dict))
|
||||
message = self._bot.sendMessage(
|
||||
self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ReplyKeyboardMarkup.de_json(self.json_dict))
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_reply_keyboard_markup_de_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list))
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0],
|
||||
telegram.KeyboardButton))
|
||||
self.assertEqual(reply_keyboard_markup.resize_keyboard, self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup.one_time_keyboard, self.one_time_keyboard)
|
||||
telegram.KeyboardButton))
|
||||
self.assertEqual(reply_keyboard_markup.resize_keyboard,
|
||||
self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup.one_time_keyboard,
|
||||
self.one_time_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup.selective, self.selective)
|
||||
|
||||
def test_reply_keyboard_markup_to_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(reply_keyboard_markup.to_json()))
|
||||
|
||||
def test_reply_keyboard_markup_to_dict(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list))
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0],
|
||||
telegram.KeyboardButton))
|
||||
self.assertEqual(reply_keyboard_markup['resize_keyboard'], self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup['one_time_keyboard'], self.one_time_keyboard)
|
||||
telegram.KeyboardButton))
|
||||
self.assertEqual(reply_keyboard_markup['resize_keyboard'],
|
||||
self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup['one_time_keyboard'],
|
||||
self.one_time_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup['selective'], self.selective)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Sticker"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -60,7 +60,7 @@ class StickerTest(BaseTest, unittest.TestCase):
|
|||
@timeout(10)
|
||||
def test_send_sticker_resend(self):
|
||||
message = self._bot.sendSticker(chat_id=self._chat_id,
|
||||
sticker=self.sticker_file_id)
|
||||
sticker=self.sticker_file_id)
|
||||
|
||||
sticker = message.sticker
|
||||
|
||||
|
@ -98,7 +98,7 @@ class StickerTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_sticker_empty_file(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['sticker'] = open(os.devnull, 'rb')
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -110,23 +110,24 @@ class StickerTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_sticker_empty_file_id(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['sticker'] = ''
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
lambda: self._bot.sendSticker(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
**json_dict))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_error_sticker_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.sendSticker(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
**json_dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# !/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
|
@ -16,12 +16,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Update"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -46,10 +45,7 @@ class UpdateTest(BaseTest, unittest.TestCase):
|
|||
'date': 1441644592,
|
||||
'text': "Update Test"}
|
||||
|
||||
self.json_dict = {
|
||||
'update_id': self.update_id,
|
||||
'message': self.message
|
||||
}
|
||||
self.json_dict = {'update_id': self.update_id, 'message': self.message}
|
||||
|
||||
def test_update_de_json(self):
|
||||
update = telegram.Update.de_json(self.json_dict)
|
||||
|
@ -69,5 +65,6 @@ class UpdateTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(update['update_id'], self.update_id)
|
||||
self.assertTrue(isinstance(update['message'], telegram.Message))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -17,19 +17,19 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""
|
||||
This module contains a object that represents Tests for Updater, Dispatcher,
|
||||
WebhookServer and WebhookHandler
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
import re
|
||||
import os
|
||||
import signal
|
||||
from random import randrange
|
||||
from time import sleep
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
from datetime import datetime
|
||||
from time import sleep
|
||||
from random import randrange
|
||||
|
||||
from future.builtins import bytes
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
|
@ -161,8 +161,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
|
||||
def test_addTelegramMessageHandlerMultipleMessages(self):
|
||||
self._setup_updater('Multiple', 100)
|
||||
self.updater.dispatcher.addHandler(
|
||||
MessageHandler([], self.telegramHandlerTest))
|
||||
self.updater.dispatcher.addHandler(MessageHandler(
|
||||
[], self.telegramHandlerTest))
|
||||
self.updater.start_polling(0.0)
|
||||
sleep(2)
|
||||
self.assertEqual(self.received_message, 'Multiple')
|
||||
|
@ -365,8 +365,10 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
|
||||
def test_additionalArgs(self):
|
||||
self._setup_updater('', messages=0)
|
||||
handler = StringCommandHandler('test5', self.additionalArgsTest,
|
||||
pass_update_queue=True, pass_args=True)
|
||||
handler = StringCommandHandler('test5',
|
||||
self.additionalArgsTest,
|
||||
pass_update_queue=True,
|
||||
pass_args=True)
|
||||
self.updater.dispatcher.addHandler(handler)
|
||||
|
||||
queue = self.updater.start_polling(0.01)
|
||||
|
@ -380,7 +382,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
d = self.updater.dispatcher
|
||||
handler = StringRegexHandler('^(This).*?(?P<testgroup>regex group).*',
|
||||
self.regexGroupHandlerTest,
|
||||
pass_groupdict=True, pass_groups=True)
|
||||
pass_groupdict=True,
|
||||
pass_groups=True)
|
||||
d.addHandler(handler)
|
||||
queue = self.updater.start_polling(0.01)
|
||||
queue.put('This is a test message for regex group matching.')
|
||||
|
@ -391,7 +394,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
def test_runAsyncWithAdditionalArgs(self):
|
||||
self._setup_updater('Test6', messages=2)
|
||||
d = self.updater.dispatcher
|
||||
handler = MessageHandler([], self.asyncAdditionalHandlerTest,
|
||||
handler = MessageHandler([],
|
||||
self.asyncAdditionalHandlerTest,
|
||||
pass_update_queue=True)
|
||||
d.addHandler(handler)
|
||||
self.updater.start_polling(0.01)
|
||||
|
@ -407,7 +411,8 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
|
||||
ip = '127.0.0.1'
|
||||
port = randrange(1024, 49152) # Select random port for travis
|
||||
self.updater.start_webhook(ip, port,
|
||||
self.updater.start_webhook(ip,
|
||||
port,
|
||||
url_path='TOKEN',
|
||||
cert='./tests/test_updater.py',
|
||||
key='./tests/test_updater.py',
|
||||
|
@ -417,7 +422,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
Thread(target=self.updater.httpd.serve_forever).start()
|
||||
|
||||
# Now, we send an update to the server via urlopen
|
||||
message = Message(1, User(1, "Tester"), datetime.now(),
|
||||
message = Message(1,
|
||||
User(1, "Tester"),
|
||||
datetime.now(),
|
||||
Chat(1, "group", title="Test Group"))
|
||||
|
||||
message.text = "Webhook Test"
|
||||
|
@ -434,8 +441,10 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(b'', response.read())
|
||||
self.assertEqual(200, response.code)
|
||||
|
||||
response = self._send_webhook_msg(ip, port, None, 'webookhandler.py',
|
||||
get_method=lambda: 'HEAD')
|
||||
response = self._send_webhook_msg(
|
||||
ip, port,
|
||||
None, 'webookhandler.py',
|
||||
get_method=lambda: 'HEAD')
|
||||
|
||||
self.assertEqual(b'', response.read())
|
||||
self.assertEqual(200, response.code)
|
||||
|
@ -457,7 +466,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
sleep(0.5)
|
||||
|
||||
# Now, we send an update to the server via urlopen
|
||||
message = Message(1, User(1, "Tester 2"), datetime.now(),
|
||||
message = Message(1,
|
||||
User(1, "Tester 2"),
|
||||
datetime.now(),
|
||||
Chat(1, 'group', title="Test Group 2"))
|
||||
|
||||
message.text = "Webhook Test 2"
|
||||
|
@ -483,7 +494,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
|
||||
def test_bootstrap_retries_unauth(self):
|
||||
retries = 3
|
||||
self._setup_updater('', messages=0, bootstrap_retries=retries,
|
||||
self._setup_updater('',
|
||||
messages=0,
|
||||
bootstrap_retries=retries,
|
||||
bootstrap_err=Unauthorized())
|
||||
|
||||
self.assertRaises(Unauthorized, self.updater._set_webhook, 'path',
|
||||
|
@ -492,7 +505,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
|
||||
def test_bootstrap_retries_invalid_token(self):
|
||||
retries = 3
|
||||
self._setup_updater('', messages=0, bootstrap_retries=retries,
|
||||
self._setup_updater('',
|
||||
messages=0,
|
||||
bootstrap_retries=retries,
|
||||
bootstrap_err=InvalidToken())
|
||||
|
||||
self.assertRaises(InvalidToken, self.updater._set_webhook, 'path',
|
||||
|
@ -521,14 +536,16 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
|
||||
try:
|
||||
with self.assertRaises(HTTPError) as ctx:
|
||||
self._send_webhook_msg(ip, port,
|
||||
self._send_webhook_msg(ip,
|
||||
port,
|
||||
'<root><bla>data</bla></root>',
|
||||
content_type='application/xml')
|
||||
self.assertEqual(ctx.exception.code, 403)
|
||||
|
||||
with self.assertRaises(HTTPError) as ctx:
|
||||
self._send_webhook_msg(ip, port, 'dummy-payload',
|
||||
content_len=-2)
|
||||
self._send_webhook_msg(
|
||||
ip, port, 'dummy-payload',
|
||||
content_len=-2)
|
||||
self.assertEqual(ctx.exception.code, 403)
|
||||
|
||||
# TODO: prevent urllib or the underlying from adding content-length
|
||||
|
@ -538,7 +555,9 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
# self.assertEqual(ctx.exception.code, 411)
|
||||
|
||||
with self.assertRaises(HTTPError) as ctx:
|
||||
self._send_webhook_msg(ip, port, 'dummy-payload',
|
||||
self._send_webhook_msg(ip,
|
||||
port,
|
||||
'dummy-payload',
|
||||
content_len='not-a-number')
|
||||
self.assertEqual(ctx.exception.code, 403)
|
||||
|
||||
|
@ -546,12 +565,15 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
self.updater._stop_httpd()
|
||||
thr.join()
|
||||
|
||||
def _send_webhook_msg(self, ip, port, payload_str, url_path='',
|
||||
content_len=-1, content_type='application/json',
|
||||
def _send_webhook_msg(self,
|
||||
ip,
|
||||
port,
|
||||
payload_str,
|
||||
url_path='',
|
||||
content_len=-1,
|
||||
content_type='application/json',
|
||||
get_method=None):
|
||||
headers = {
|
||||
'content-type': content_type,
|
||||
}
|
||||
headers = {'content-type': content_type, }
|
||||
|
||||
if not payload_str:
|
||||
content_len = None
|
||||
|
@ -565,12 +587,11 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
if content_len is not None:
|
||||
headers['content-length'] = str(content_len)
|
||||
|
||||
url = 'http://{ip}:{port}/{path}'.format(ip=ip, port=port,
|
||||
path=url_path)
|
||||
url = 'http://{ip}:{port}/{path}'.format(
|
||||
ip=ip, port=port, path=url_path)
|
||||
|
||||
req = Request(url, data=payload, headers=headers)
|
||||
|
||||
|
||||
if get_method is not None:
|
||||
req.get_method = get_method
|
||||
|
||||
|
@ -602,9 +623,12 @@ class UpdaterTest(BaseTest, unittest.TestCase):
|
|||
|
||||
|
||||
class MockBot(object):
|
||||
|
||||
def __init__(self, text, messages=1, raise_error=False,
|
||||
bootstrap_retries=None, bootstrap_err=TelegramError('test')):
|
||||
def __init__(self,
|
||||
text,
|
||||
messages=1,
|
||||
raise_error=False,
|
||||
bootstrap_retries=None,
|
||||
bootstrap_err=TelegramError('test')):
|
||||
self.text = text
|
||||
self.send_messages = messages
|
||||
self.raise_error = raise_error
|
||||
|
@ -629,11 +653,7 @@ class MockBot(object):
|
|||
self.bootstrap_attempts += 1
|
||||
raise self.bootstrap_err
|
||||
|
||||
def getUpdates(self,
|
||||
offset=None,
|
||||
limit=100,
|
||||
timeout=0,
|
||||
network_delay=2.):
|
||||
def getUpdates(self, offset=None, limit=100, timeout=0, network_delay=2.):
|
||||
|
||||
if self.raise_error:
|
||||
raise TelegramError('Test Error 2')
|
||||
|
@ -646,5 +666,6 @@ class MockBot(object):
|
|||
else:
|
||||
return []
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# !/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
|
@ -16,12 +16,11 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram User"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
|
@ -60,7 +59,7 @@ class UserTest(BaseTest, unittest.TestCase):
|
|||
def test_user_de_json_without_username(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['username'])
|
||||
del (json_dict['username'])
|
||||
|
||||
user = telegram.User.de_json(self.json_dict)
|
||||
|
||||
|
@ -69,14 +68,14 @@ class UserTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(user.last_name, self.last_name)
|
||||
self.assertEqual(user.type, self.type)
|
||||
|
||||
self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name))
|
||||
|
||||
self.assertEqual(user.name,
|
||||
'%s %s' % (self.first_name, self.last_name))
|
||||
|
||||
def test_user_de_json_without_username_and_lastname(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['username'])
|
||||
del(json_dict['last_name'])
|
||||
del (json_dict['username'])
|
||||
del (json_dict['last_name'])
|
||||
|
||||
user = telegram.User.de_json(self.json_dict)
|
||||
|
||||
|
@ -100,5 +99,6 @@ class UserTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(user['username'], self.username)
|
||||
self.assertEqual(user['type'], self.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
71
tests/test_venue.py
Normal file
71
tests/test_venue.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram Venue"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class VenueTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram Venue."""
|
||||
|
||||
def setUp(self):
|
||||
self.location = telegram.Location(longitude=1., latitude=0.)
|
||||
self.title = 'title'
|
||||
self._address = '_address'
|
||||
self.foursquare_id = 'foursquare id'
|
||||
|
||||
self.json_dict = {
|
||||
'location': self.location.to_dict(),
|
||||
'title': self.title,
|
||||
'address': self._address,
|
||||
'foursquare_id': self.foursquare_id
|
||||
}
|
||||
|
||||
def test_sticker_de_json(self):
|
||||
sticker = telegram.Venue.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(isinstance(sticker.location, telegram.Location))
|
||||
self.assertEqual(sticker.title, self.title)
|
||||
self.assertEqual(sticker.address, self._address)
|
||||
self.assertEqual(sticker.foursquare_id, self.foursquare_id)
|
||||
|
||||
def test_sticker_to_json(self):
|
||||
sticker = telegram.Venue.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(sticker.to_json()))
|
||||
|
||||
def test_sticker_to_dict(self):
|
||||
sticker = telegram.Venue.de_json(self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(sticker))
|
||||
self.assertDictEqual(self.json_dict, sticker)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -16,12 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Video"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -217,7 +217,7 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_video_empty_file(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['video'] = open(os.devnull, 'rb')
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -230,7 +230,7 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_video_empty_file_id(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['video'] = ''
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -243,13 +243,14 @@ class VideoTest(BaseTest, unittest.TestCase):
|
|||
def test_error_video_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del(json_dict['duration'])
|
||||
del (json_dict['file_id'])
|
||||
del (json_dict['duration'])
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.sendVideo(chat_id=self._chat_id,
|
||||
timeout=10,
|
||||
**json_dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Voice"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import sys
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
sys.path.append('.')
|
||||
|
@ -51,8 +51,7 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def test_send_voice_required_args_only(self):
|
||||
message = self._bot.sendVoice(self._chat_id,
|
||||
self.voice_file)
|
||||
message = self._bot.sendVoice(self._chat_id, self.voice_file)
|
||||
|
||||
voice = message.voice
|
||||
|
||||
|
@ -165,7 +164,7 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_voice_empty_file(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['voice'] = open(os.devnull, 'rb')
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -177,7 +176,7 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
def test_error_send_voice_empty_file_id(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del (json_dict['file_id'])
|
||||
json_dict['voice'] = ''
|
||||
|
||||
self.assertRaises(telegram.TelegramError,
|
||||
|
@ -189,12 +188,13 @@ class VoiceTest(BaseTest, unittest.TestCase):
|
|||
def test_error_voice_without_required_args(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del(json_dict['file_id'])
|
||||
del(json_dict['duration'])
|
||||
del (json_dict['file_id'])
|
||||
del (json_dict['duration'])
|
||||
|
||||
self.assertRaises(TypeError,
|
||||
lambda: self._bot.sendVoice(chat_id=self._chat_id,
|
||||
**json_dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in a new issue