Merge pull request #431 from python-telegram-bot/october3

Add api changes as of october 3
This commit is contained in:
Jacob Bom 2016-10-19 12:59:00 +02:00 committed by GitHub
commit 61fe438a8b
110 changed files with 1244 additions and 308 deletions

3
.gitignore vendored
View file

@ -68,3 +68,6 @@ telegram.mp4
telegram.ogg
telegram.png
telegram.webp
# original files from merges
*.orig

View file

@ -1,5 +1,5 @@
- repo: git://github.com/pre-commit/mirrors-yapf
sha: v0.11.0
- repo: git://github.com/python-telegram-bot/mirrors-yapf
sha: v0.12.2
hooks:
- id: yapf
files: ^(telegram|tests)/.*\.py$

View file

@ -6,6 +6,9 @@ python:
- "3.5"
- "pypy"
- "pypy3"
branches:
only:
- master
install:
- pip install coveralls
- pip install -r requirements.txt
@ -13,6 +16,6 @@ install:
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi
script:
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/
- if [ $TRAVIS_PYTHON_VERSION != 3.3 ] && [ $TRAVIS_PYTHON_VERSION != pypy3 ]; then pre-commit run --all-files; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then pre-commit run --all-files; fi
after_success:
coveralls

View file

@ -27,6 +27,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Noam Meltzer <https://github.com/tsnoam>`_
- `Oleg Shlyazhko <https://github.com/ollmer>`_
- `overquota <https://github.com/overquota>`_
- `Patrick Hofmann <https://github.com/PH89>`_
- `Rahiel Kasim <https://github.com/rahiel>`_
- `Shelomentsev D <https://github.com/shelomentsevd>`_
- `sooyhwang <https://github.com/sooyhwang>`_

View file

@ -84,7 +84,7 @@ make the development of bots easy and straightforward. These classes are contain
Telegram API support
====================
As of **28. May 2016**, all types and methods of the Telegram Bot API are supported.
As of **3. Oct 2016**, all types and methods of the Telegram Bot API are supported.
==========
Installing

View file

@ -46,6 +46,8 @@ from .file import File
from .emoji import Emoji
from .parsemode import ParseMode
from .messageentity import MessageEntity
from .animation import Animation
from .game import Game
from .message import Message
from .inputmessagecontent import InputMessageContent
from .callbackquery import CallbackQuery
@ -73,10 +75,13 @@ from .inlinequeryresultphoto import InlineQueryResultPhoto
from .inlinequeryresultvenue import InlineQueryResultVenue
from .inlinequeryresultvideo import InlineQueryResultVideo
from .inlinequeryresultvoice import InlineQueryResultVoice
from .inlinequeryresultgame import InlineQueryResultGame
from .inputtextmessagecontent import InputTextMessageContent
from .inputlocationmessagecontent import InputLocationMessageContent
from .inputvenuemessagecontent import InputVenueMessageContent
from .inputcontactmessagecontent import InputContactMessageContent
from .webhookinfo import WebhookInfo
from .gamehighscore import GameHighScore
from .update import Update
from .bot import Bot
from .constants import (MAX_MESSAGE_LENGTH, MAX_CAPTION_LENGTH, SUPPORTED_WEBHOOK_PORTS,
@ -87,22 +92,24 @@ from .version import __version__ # flake8: noqa
__author__ = 'devs@python-telegram-bot.org'
__all__ = ['Audio', 'Bot', 'Chat', 'ChatMember', 'ChatAction', 'ChosenInlineResult',
'CallbackQuery', 'Contact', 'Document', 'Emoji', 'File', 'ForceReply',
'InlineKeyboardButton', 'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult',
'InlineQueryResult', 'InlineQueryResultArticle', 'InlineQueryResultAudio',
'InlineQueryResultCachedAudio', 'InlineQueryResultCachedDocument',
'InlineQueryResultCachedGif', 'InlineQueryResultCachedMpeg4Gif',
'InlineQueryResultCachedPhoto', 'InlineQueryResultCachedSticker',
'InlineQueryResultCachedVideo', 'InlineQueryResultCachedVoice',
'InlineQueryResultContact', 'InlineQueryResultDocument', 'InlineQueryResultGif',
'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif', 'InlineQueryResultPhoto',
'InlineQueryResultVenue', 'InlineQueryResultVideo', 'InlineQueryResultVoice',
'InputContactMessageContent', 'InputFile', 'InputLocationMessageContent',
'InputMessageContent', 'InputTextMessageContent', 'InputVenueMessageContent',
'KeyboardButton', 'Location', 'Message', 'MessageEntity', 'ParseMode', 'PhotoSize',
'ReplyKeyboardHide', 'ReplyKeyboardMarkup', 'ReplyMarkup', 'Sticker', 'TelegramError',
'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue', 'Video', 'Voice',
'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP']
__all__ = [
'Audio', 'Bot', 'Chat', 'ChatMember', 'ChatAction', 'ChosenInlineResult', 'CallbackQuery',
'Contact', 'Document', 'Emoji', 'File', 'ForceReply', 'InlineKeyboardButton',
'InlineKeyboardMarkup', 'InlineQuery', 'InlineQueryResult', 'InlineQueryResult',
'InlineQueryResultArticle', 'InlineQueryResultAudio', 'InlineQueryResultCachedAudio',
'InlineQueryResultCachedDocument', 'InlineQueryResultCachedGif',
'InlineQueryResultCachedMpeg4Gif', 'InlineQueryResultCachedPhoto',
'InlineQueryResultCachedSticker', 'InlineQueryResultCachedVideo',
'InlineQueryResultCachedVoice', 'InlineQueryResultContact', 'InlineQueryResultDocument',
'InlineQueryResultGif', 'InlineQueryResultLocation', 'InlineQueryResultMpeg4Gif',
'InlineQueryResultPhoto', 'InlineQueryResultVenue', 'InlineQueryResultVideo',
'InlineQueryResultVoice', 'InlineQueryResultGame', 'InputContactMessageContent', 'InputFile',
'InputLocationMessageContent', 'InputMessageContent', 'InputTextMessageContent',
'InputVenueMessageContent', 'KeyboardButton', 'Location', 'Message', 'MessageEntity',
'ParseMode', 'PhotoSize', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup', 'ReplyMarkup', 'Sticker',
'TelegramError', 'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue', 'Video',
'Voice', 'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'WebhookInfo', 'Animation',
'Game', 'GameHighScore'
]

60
telegram/animation.py Normal file
View file

@ -0,0 +1,60 @@
#!/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 Lesser 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 Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Animation."""
from telegram import PhotoSize
from telegram import TelegramObject
class Animation(TelegramObject):
"""This object represents a Telegram Animation.
Attributes:
file_id (str): Unique file identifier.
Keyword Args:
thumb (Optional[:class:`telegram.PhotoSize`]): Animation thumbnail as defined by sender.
file_name (Optional[str]): Original animation filename as defined by sender.
mime_type (Optional[str]): MIME type of the file as defined by sender.
file_size (Optional[int]): File size.
"""
def __init__(self, file_id, **kwargs):
self.file_id = file_id
self.thumb = kwargs.get('thumb')
self.file_name = kwargs.get('file_name')
self.mime_type = kwargs.get('mime_type')
self.file_size = kwargs.get('file_size')
@staticmethod
def de_json(data, bot):
"""
Args:
data (dict):
bot (telegram.Bot):
Returns:
telegram.Game:
"""
if not data:
return None
data['thumb'] = PhotoSize.de_json(data.get('thumb'), bot)
return Animation(**data)

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Audio."""
"""This module contains an object that represents a Telegram Audio."""
from telegram import TelegramObject

View file

@ -17,13 +17,13 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Bot."""
"""This module contains an object that represents a Telegram Bot."""
import functools
import logging
from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File,
ReplyMarkup, TelegramObject)
ReplyMarkup, TelegramObject, WebhookInfo, GameHighScore)
from telegram.error import InvalidToken, TelegramError
from telegram.utils.request import Request
@ -51,16 +51,14 @@ class Bot(TelegramObject):
def __init__(self, token, base_url=None, base_file_url=None, request=None):
self.token = self._validate_token(token)
if not base_url:
self.base_url = 'https://api.telegram.org/bot{0}'.format(self.token)
else:
self.base_url = base_url + self.token
if base_url is None:
base_url = 'https://api.telegram.org/bot'
if not base_file_url:
self.base_file_url = 'https://api.telegram.org/file/bot{0}'.format(self.token)
else:
self.base_file_url = base_file_url + self.token
if base_file_url is None:
base_file_url = 'https://api.telegram.org/file/bot'
self.base_url = str(base_url) + str(self.token)
self.base_file_url = str(base_file_url) + str(self.token)
self.bot = None
self._request = request or Request()
self.logger = logging.getLogger(__name__)
@ -330,6 +328,7 @@ class Bot(TelegramObject):
duration=None,
performer=None,
title=None,
caption=None,
disable_notification=False,
reply_to_message_id=None,
reply_markup=None,
@ -354,6 +353,7 @@ class Bot(TelegramObject):
duration (Optional[int]): Duration of sent audio in seconds.
performer: Performer of sent audio. [Optional]
title: Title of sent audio. [Optional]
caption: Audio caption [Optional]
disable_notification (Optional[bool]): Sends the message silently. iOS users will not
receive a notification, Android users will receive a notification with no sound.
reply_to_message_id (Optional[int]): If the message is a reply, ID of the original
@ -382,6 +382,8 @@ class Bot(TelegramObject):
data['performer'] = performer
if title:
data['title'] = title
if caption:
data['caption'] = caption
return url, data
@ -534,6 +536,7 @@ class Bot(TelegramObject):
chat_id,
voice,
duration=None,
caption=None,
disable_notification=False,
reply_to_message_id=None,
reply_markup=None,
@ -551,6 +554,7 @@ class Bot(TelegramObject):
that is already on the Telegram servers, or upload a new audio file using
multipart/form-data.
duration (Optional[int]): Duration of sent audio in seconds.
caption: Voice caption [Optional]
disable_notification (Optional[bool]): Sends the message silently. iOS users will not
receive a notification, Android users will receive a notification with no sound.
reply_to_message_id (Optional[int]): If the message is a reply, ID of the original
@ -575,6 +579,8 @@ class Bot(TelegramObject):
if duration:
data['duration'] = duration
if caption:
data['caption'] = caption
return url, data
@ -664,11 +670,13 @@ class Bot(TelegramObject):
"""
url = '{0}/sendVenue'.format(self.base_url)
data = {'chat_id': chat_id,
'latitude': latitude,
'longitude': longitude,
'address': address,
'title': title}
data = {
'chat_id': chat_id,
'latitude': latitude,
'longitude': longitude,
'address': address,
'title': title
}
if foursquare_id:
data['foursquare_id'] = foursquare_id
@ -723,6 +731,41 @@ class Bot(TelegramObject):
return url, data
@log
@message
def sendGame(self, chat_id, game_short_name, **kwargs):
"""Use this method to send a game.
Args:
chat_id: Unique identifier for the target chat or username of the target channel (in
the format @channelusername).
game_short_name (str): Short name of the game, serves as the unique identifier for the
game.
Keyword Args:
disable_notification (Optional[bool]): Sends the message silently. iOS users will not
receive a notification, Android users will receive a notification with no sound.
reply_to_message_id (Optional[int]): If the message is a reply,
ID of the original message.
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options.
A JSON-serialized object for an inline keyboard, custom reply keyboard,
instructions to hide reply keyboard or to force a reply from the user.
timeout (Optional[float]): If this value is specified, use it as
the definitive timeout (in seconds) for urlopen() operations.
Returns:
:class:`telegram.Message`: On success, the sent message is returned.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/sendGame'.format(self.base_url)
data = {'chat_id': chat_id, 'game_short_name': game_short_name}
return url, data
@log
@message
def sendChatAction(self, chat_id, action, **kwargs):
@ -942,6 +985,7 @@ class Bot(TelegramObject):
callback_query_id,
text=None,
show_alert=False,
url=None,
timeout=None,
**kwargs):
"""Use this method to send answers to callback queries sent from inline keyboards. The
@ -955,7 +999,8 @@ class Bot(TelegramObject):
show_alert (Optional[bool]): If `True`, an alert will be shown by the client instead of
a notification at the top of the chat screen. Defaults to `False`.
timeout (Optional[float]): If this value is specified, use it as the definitive timeout
(in seconds) for urlopen() operations.
(in seconds) for urlopen() operations.
url (Optional[str]): URL that will be opened by the user's client.
**kwargs (dict): Arbitrary keyword arguments.
Returns:
@ -965,7 +1010,7 @@ class Bot(TelegramObject):
:class:`telegram.TelegramError`
"""
url = '{0}/answerCallbackQuery'.format(self.base_url)
url_ = '{0}/answerCallbackQuery'.format(self.base_url)
data = {'callback_query_id': callback_query_id}
@ -973,8 +1018,10 @@ class Bot(TelegramObject):
data['text'] = text
if show_alert:
data['show_alert'] = show_alert
if url:
data['url'] = url
result = self._request.post(url, data, timeout=timeout)
result = self._request.post(url_, data, timeout=timeout)
return result
@ -1362,6 +1409,85 @@ class Bot(TelegramObject):
return ChatMember.de_json(result, self)
def getWebhookInfo(self, **kwargs):
"""Use this method to get current webhook status.
If the bot is using getUpdates, will return an object with the url field empty.
Returns:
:class: `telegram.WebhookInfo`
"""
url = '{0}/getWebhookInfo'.format(self.base_url)
data = {}
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
return WebhookInfo.de_json(result, self)
def setGameScore(self,
user_id,
score,
chat_id=None,
message_id=None,
inline_message_id=None,
edit_message=None,
**kwargs):
"""Use this method to set the score of the specified user in a game.
Returns:
:class:`telegram.Message` or True: The edited message, or if the
message wasn't sent by the bot, True.
"""
url = '{0}/setGameScore'.format(self.base_url)
data = {'user_id': user_id, 'score': score}
if chat_id:
data['chat_id'] = chat_id
if message_id:
data['message_id'] = message_id
if inline_message_id:
data['inline_message_id'] = inline_message_id
if edit_message:
data['edit_message'] = edit_message
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
if result is True:
return result
else:
return Message.de_json(result, self)
def getGameHighScores(self,
user_id,
chat_id=None,
message_id=None,
inline_message_id=None,
**kwargs):
"""Use this method to get data for high score tables.
Returns:
list[:class:`telegram.GameHighScore`]: Scores of the specified user and several of his
neighbors in a game.
"""
url = '{0}/setGameScore'.format(self.base_url)
data = {'user_id': user_id}
if chat_id:
data['chat_id'] = chat_id
if message_id:
data['message_id'] = message_id
if inline_message_id:
data['inline_message_id'] = inline_message_id
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
return [GameHighScore.de_json(hs, self) for hs in result]
@staticmethod
def de_json(data, bot):
data = super(Bot, Bot).de_json(data, bot)
@ -1380,7 +1506,8 @@ class Bot(TelegramObject):
return (self.__class__, (self.token, self.base_url.replace(self.token, ''),
self.base_file_url.replace(self.token, '')))
# snake_case (PEP8) aliases
# snake_case (PEP8) aliases
get_me = getMe
send_message = sendMessage
forward_message = forwardMessage
@ -1393,6 +1520,7 @@ class Bot(TelegramObject):
send_location = sendLocation
send_venue = sendVenue
send_contact = sendContact
send_game = sendGame
send_chat_action = sendChatAction
answer_inline_query = answerInlineQuery
get_user_profile_photos = getUserProfilePhotos
@ -1410,3 +1538,6 @@ class Bot(TelegramObject):
get_chat_administrators = getChatAdministrators
get_chat_member = getChatMember
get_chat_members_count = getChatMembersCount
get_webhook_info = getWebhookInfo
set_game_score = setGameScore
get_game_high_scores = getGameHighScores

25
telegram/callbackgame.py Normal file
View file

@ -0,0 +1,25 @@
#!/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 Lesser 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 Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram CallbackGame."""
from telegram import TelegramObject
class CallbackGame(TelegramObject):
"""A placeholder, currently holds no information. Use BotFather to set up your game."""

View file

@ -16,8 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
CallbackQuery"""
"""This module contains an object that represents a Telegram CallbackQuery"""
from telegram import TelegramObject, Message, User
@ -25,15 +24,25 @@ from telegram import TelegramObject, Message, User
class CallbackQuery(TelegramObject):
"""This object represents a Telegram CallbackQuery."""
def __init__(self, id, from_user, data, message=None, inline_message_id='', bot=None,
def __init__(self,
id,
from_user,
chat_instance,
message=None,
data=None,
inline_message_id=None,
game_short_name=None,
bot=None,
**kwargs):
# Required
self.id = id
self.from_user = from_user
self.data = data
self.chat_instance = chat_instance
# Optionals
self.message = message
self.data = data
self.inline_message_id = inline_message_id
self.game_short_name = game_short_name
self.bot = bot

View file

@ -17,7 +17,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Chat."""
"""This module contains an object that represents a Telegram Chat."""
from telegram import TelegramObject
@ -32,6 +32,7 @@ class Chat(TelegramObject):
username (str): Username, for private chats and channels if available
first_name (str): First name of the other party in a private chat
last_name (str): Last name of the other party in a private chat
all_members_are_admins (bool): True if a group has 'All Members Are Admins' enabled.
Args:
id (int):
@ -56,6 +57,7 @@ class Chat(TelegramObject):
username='',
first_name='',
last_name='',
all_members_are_admins=False,
bot=None,
**kwargs):
# Required
@ -66,6 +68,7 @@ class Chat(TelegramObject):
self.username = username
self.first_name = first_name
self.last_name = last_name
self.all_members_are_admins = all_members_are_admins
self.bot = bot

View file

@ -17,7 +17,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram ChatAction."""
"""This module contains an object that represents a Telegram ChatAction."""
class ChatAction(object):

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram ChatMember."""
"""This module contains an object that represents a Telegram ChatMember."""
from telegram import User, TelegramObject

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""
This module contains a object that represents a Telegram ChosenInlineResult
This module contains an object that represents a Telegram ChosenInlineResult
"""
from telegram import TelegramObject, User, Location
@ -74,7 +74,7 @@ class ChosenInlineResult(TelegramObject):
if not data:
return None
# Required
# Required
data['from_user'] = User.de_json(data.pop('from'), bot)
# Optionals
data['location'] = Location.de_json(data.get('location'), bot)

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Contact."""
"""This module contains an object that represents a Telegram Contact."""
from telegram import TelegramObject

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Document."""
"""This module contains an object that represents a Telegram Document."""
from telegram import PhotoSize, TelegramObject

View file

@ -18,7 +18,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents an Emoji.
"""This module contains an object that represents an Emoji.
This module will be removed in the future.
"""

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Error."""
"""This module contains an object that represents a Telegram Error."""
def _lstrip_str(in_s, lstr):
@ -94,8 +94,20 @@ class ChatMigrated(TelegramError):
Args:
new_chat_id (int):
Returns:
"""
super(ChatMigrated,
self).__init__('Group migrated to supergroup. New chat id: {}'.format(new_chat_id))
self.new_chat_id = new_chat_id
class RetryAfter(TelegramError):
def __init__(self, retry_after):
"""
Args:
retry_after (int):
"""
super(ChatMigrated, self).__init__('Chat migrated')
self.new_chat_id = new_chat_id
super(RetryAfter,
self).__init__('Flood control exceeded. Retry in {} seconds'.format(retry_after))
self.retry_after = float(retry_after)

View file

@ -191,6 +191,13 @@ class Filters(object):
forwarded = _Forwarded()
class _Game(BaseFilter):
def filter(self, message):
return bool(message.game)
game = _Game()
class entity(BaseFilter):
"""Filters messages to only allow those which have a :class:`telegram.MessageEntity`
where their `type` matches `entity_type`.

View file

@ -87,8 +87,7 @@ class MessageHandler(Handler):
return self.callback(dispatcher.bot, update, **optional_args)
# old non-PEP8 Handler methods
# old non-PEP8 Handler methods
m = "telegram.MessageHandler."
checkUpdate = deprecate(check_update, m + "checkUpdate", m + "check_update")
handleUpdate = deprecate(handle_update, m + "handleUpdate", m + "handle_update")

View file

@ -30,7 +30,7 @@ from queue import Queue
from telegram import Bot, TelegramError
from telegram.ext import Dispatcher, JobQueue
from telegram.error import Unauthorized, InvalidToken
from telegram.error import Unauthorized, InvalidToken, RetryAfter
from telegram.utils.request import Request
from telegram.utils.webhookhandler import (WebhookServer, WebhookHandler)
@ -233,6 +233,9 @@ class Updater(object):
try:
updates = self.bot.getUpdates(
self.last_update_id, timeout=timeout, network_delay=network_delay)
except RetryAfter as e:
self.logger.info(str(e))
cur_interval = 0.5 + e.retry_after
except TelegramError as te:
self.logger.error("Error while getting Updates: {0}".format(te))

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram File."""
"""This module contains an object that represents a Telegram File."""
from os.path import basename

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram ForceReply."""
"""This module contains an object that represents a Telegram ForceReply."""
from telegram import ReplyMarkup

146
telegram/game.py Normal file
View file

@ -0,0 +1,146 @@
#!/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 Lesser 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 Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Game."""
import sys
from telegram import MessageEntity, TelegramObject, Animation, PhotoSize
class Game(TelegramObject):
"""This object represents a Telegram Game.
Attributes:
title (str): Title of the game.
description (str): Description of the game.
photo (list[:class:`telegram.PhotoSize`]): List of photos that will be displayed in the
game message in chats.
Keyword Args:
text (Optional[str]): Brief description of the game or high scores included in the game
message. Can be automatically edited to include current high scores for the game when
the bot calls setGameScore, or manually edited using editMessageText.
0-4096 characters.
text_entities (Optional[list[:class:`telegram.MessageEntity`]]): Special entities that
appear in text, such as usernames, URLs, bot commands, etc.
animation (Optional[:class:`telegram.Animation`]): Animation that will be displayed in the
game message in chats. Upload via BotFather.
"""
def __init__(self,
title,
description,
photo,
text='',
text_entities=None,
animation=None,
**kwargs):
self.title = title
self.description = description
self.photo = photo
self.text = text
self.text_entities = text_entities
self.animation = animation
@staticmethod
def de_json(data, bot):
"""
Args:
data (dict):
bot (telegram.Bot):
Returns:
telegram.Game:
"""
if not data:
return None
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
data['text_entities'] = MessageEntity.de_list(data.get('text_entities'), bot)
data['animation'] = Animation.de_json(data.get('animation'), bot)
return Game(**data)
def to_dict(self):
"""
Returns:
dict:
"""
data = super(Game, self).to_dict()
data['photo'] = [p.to_dict() for p in self.photo]
data['text_entities'] = [x.to_dict() for x in self.text_entities]
return data
def parse_text_entity(self, entity):
"""
Returns the text from a given :class:`telegram.MessageEntity`.
Note:
This method is present because Telegram calculates the offset and length in
UTF-16 codepoint pairs, which some versions of Python don't handle automatically.
(That is, you can't just slice ``Message.text`` with the offset and length.)
Args:
entity (MessageEntity): The entity to extract the text from. It must be an entity that
belongs to this message.
Returns:
str: The text of the given entity
"""
# Is it a narrow build, if so we don't need to convert
if sys.maxunicode == 0xffff:
return self.text[entity.offset:entity.offset + entity.length]
else:
entity_text = self.text.encode('utf-16-le')
entity_text = entity_text[entity.offset * 2:(entity.offset + entity.length) * 2]
return entity_text.decode('utf-16-le')
def parse_text_entities(self, types=None):
"""
Returns a ``dict`` that maps :class:`telegram.MessageEntity` to ``str``.
It contains entities from this message filtered by their ``type`` attribute as the key, and
the text that each entity belongs to as the value of the ``dict``.
Note:
This method should always be used instead of the ``entities`` attribute, since it
calculates the correct substring from the message text based on UTF-16 codepoints.
See ``get_entity_text`` for more info.
Args:
types (Optional[list]): List of ``MessageEntity`` types as strings. If the ``type``
attribute of an entity is contained in this list, it will be returned.
Defaults to a list of all types. All types can be found as constants in
:class:`telegram.MessageEntity`.
Returns:
dict[:class:`telegram.MessageEntity`, ``str``]: A dictionary of entities mapped to the
text that belongs to them, calculated based on UTF-16 codepoints.
"""
if types is None:
types = MessageEntity.ALL_TYPES
return {
entity: self.parse_text_entity(entity)
for entity in self.text_entities if entity.type in types
}

54
telegram/gamehighscore.py Normal file
View file

@ -0,0 +1,54 @@
#!/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 Lesser 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 Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram GameHighScore."""
from telegram import TelegramObject, User
class GameHighScore(TelegramObject):
"""This object represents a Telegram GameHighScore.
Attributes:
position (int): Position in high score table for the game.
user (:class:`telegram.User`): User object.
score (int): Score.
"""
def __init__(self, position, user, score):
self.position = position
self.user = user
self.score = score
@staticmethod
def de_json(data, bot):
"""
Args:
data (dict):
bot (telegram.Bot):
Returns:
telegram.Game:
"""
if not data:
return None
data['user'] = User.de_json(data.get('user'), bot)
return GameHighScore(**data)

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
"""This module contains an object that represents a Telegram
InlineKeyboardButton"""
from telegram import TelegramObject
@ -30,12 +30,23 @@ class InlineKeyboardButton(TelegramObject):
url (str):
callback_data (str):
switch_inline_query (str):
switch_inline_query_current_chat (str):
callback_game (:class:`telegram.CallbackGame`):
Args:
text (str):
url (Optional[str]):
callback_data (Optional[str]):
switch_inline_query (Optional[str]):
text (str): Label text on the button.
url (Optional[str]): HTTP url to be opened when button is pressed.
callback_data (Optional[str]): Data to be sent in a callback query to the bot when button
is pressed, 1-64 bytes.
switch_inline_query (Optional[str]): If set, pressing the button will prompt the user to
select one of their chats, open that chat and insert the bot's username and the
specified inline query in the input field. Can be empty, in which case just the bot's
username will be inserted.
switch_inline_query_current_chat (Optional[str]): If set, pressing the button will insert
the bot's username and the specified inline query in the current chat's input field.
Can be empty, in which case only the bot's username will be inserted.
callback_game (Optional[:class:`telegram.CallbackGame`]): Description of the game that will
be launched when the user presses the button.
**kwargs (dict): Arbitrary keyword arguments.
"""
@ -48,6 +59,8 @@ class InlineKeyboardButton(TelegramObject):
self.url = url
self.callback_data = callback_data
self.switch_inline_query = switch_inline_query
self.switch_inline_query_current_chat = kwargs.get('switch_inline_query_current_chat')
self.callback_game = kwargs.get('callback_game')
@staticmethod
def de_json(data, bot):

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
"""This module contains an object that represents a Telegram
InlineKeyboardMarkup"""
from telegram import ReplyMarkup, InlineKeyboardButton
@ -54,8 +54,10 @@ class InlineKeyboardMarkup(ReplyMarkup):
if not data:
return None
data['inline_keyboard'] = [InlineKeyboardButton.de_list(inline_keyboard, bot)
for inline_keyboard in data['inline_keyboard']]
data['inline_keyboard'] = [
InlineKeyboardButton.de_list(inline_keyboard, bot)
for inline_keyboard in data['inline_keyboard']
]
return InlineKeyboardMarkup(**data)

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram InlineQuery"""
"""This module contains an object that represents a Telegram InlineQuery"""
from telegram import TelegramObject, User, Location

View file

@ -33,6 +33,7 @@ class InlineQueryResultAudio(InlineQueryResult):
title (str):
performer (Optional[str]):
audio_duration (Optional[str]):
caption (Optional[str]):
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
input_message_content (Optional[:class:`telegram.input_message_content`]):
@ -48,6 +49,7 @@ class InlineQueryResultAudio(InlineQueryResult):
title (str):
performer (Optional[str]):
audio_duration (Optional[str]):
caption (Optional[str]):
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
input_message_content (Optional[:class:`telegram.input_message_content`]):
**kwargs (dict): Arbitrary keyword arguments.
@ -60,6 +62,7 @@ class InlineQueryResultAudio(InlineQueryResult):
title,
performer=None,
audio_duration=None,
caption=None,
reply_markup=None,
input_message_content=None,
**kwargs):
@ -74,6 +77,8 @@ class InlineQueryResultAudio(InlineQueryResult):
self.performer = performer
if audio_duration:
self.audio_duration = audio_duration
if caption:
self.caption = caption
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:

View file

@ -30,6 +30,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
Attributes:
id (str):
audio_file_id (str):
caption (Optional[str]):
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
input_message_content (Optional[:class:`telegram.input_message_content`]):
@ -42,18 +43,27 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
Args:
audio_file_id (str):
caption (Optional[str]):
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
input_message_content (Optional[:class:`telegram.input_message_content`]):
**kwargs (dict): Arbitrary keyword arguments.
"""
def __init__(self, id, audio_file_id, reply_markup=None, input_message_content=None, **kwargs):
def __init__(self,
id,
audio_file_id,
caption=None,
reply_markup=None,
input_message_content=None,
**kwargs):
# Required
super(InlineQueryResultCachedAudio, self).__init__('audio', id)
self.audio_file_id = audio_file_id
# Optionals
if caption:
self.caption = caption
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:

View file

@ -50,7 +50,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
id,
voice_file_id,
title,
description=None,
caption=None,
reply_markup=None,
input_message_content=None,
**kwargs):
@ -60,8 +60,8 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
self.title = title
# Optionals
if description:
self.description = description
if caption:
self.caption = caption
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:

View file

@ -0,0 +1,42 @@
#!/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 Lesser 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 Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram
InlineQueryResultGame"""
from telegram import InlineQueryResult, InlineKeyboardMarkup
class InlineQueryResultGame(InlineQueryResult):
def __init__(self, id, game_short_name, reply_markup=None, **kwargs):
# Required
super(InlineQueryResultGame, self).__init__('game', id)
self.id = id
self.game_short_name = game_short_name
if reply_markup:
self.reply_markup = reply_markup
@staticmethod
def de_json(data, bot):
data = super(InlineQueryResultGame, InlineQueryResultGame).de_json(data, bot)
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)
return InlineQueryResultGame(**data)

View file

@ -29,6 +29,7 @@ class InlineQueryResultVoice(InlineQueryResult):
voice_url,
title,
voice_duration=None,
caption=None,
reply_markup=None,
input_message_content=None,
**kwargs):
@ -41,6 +42,8 @@ class InlineQueryResultVoice(InlineQueryResult):
# Optional
if voice_duration:
self.voice_duration = voice_duration
if caption:
self.caption = caption
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:

View file

@ -17,7 +17,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram InputFile."""
"""This module contains an object that represents a Telegram InputFile."""
try:
# python 3
@ -31,12 +31,11 @@ import mimetypes
import os
import sys
from future.moves.urllib.request import urlopen
from telegram import TelegramError
DEFAULT_MIME_TYPE = 'application/octet-stream'
USER_AGENT = 'Python Telegram Bot (https://github.com/python-telegram-bot/python-telegram-bot)'
FILE_TYPES = ('audio', 'document', 'photo', 'sticker', 'video', 'voice', 'certificate')
class InputFile(object):
@ -49,32 +48,28 @@ class InputFile(object):
if 'audio' in data:
self.input_name = 'audio'
self.input_file = data.pop('audio')
if 'document' in data:
elif 'document' in data:
self.input_name = 'document'
self.input_file = data.pop('document')
if 'photo' in data:
elif 'photo' in data:
self.input_name = 'photo'
self.input_file = data.pop('photo')
if 'sticker' in data:
elif 'sticker' in data:
self.input_name = 'sticker'
self.input_file = data.pop('sticker')
if 'video' in data:
elif 'video' in data:
self.input_name = 'video'
self.input_file = data.pop('video')
if 'voice' in data:
elif 'voice' in data:
self.input_name = 'voice'
self.input_file = data.pop('voice')
if 'certificate' in data:
elif 'certificate' in data:
self.input_name = 'certificate'
self.input_file = data.pop('certificate')
if str(self.input_file).startswith('http'):
from_url = True
self.input_file = urlopen(self.input_file)
else:
from_url = False
raise TelegramError('Unknown inputfile type')
if hasattr(self.input_file, 'read') or from_url:
if hasattr(self.input_file, 'read'):
self.filename = None
self.input_file_content = self.input_file.read()
if 'filename' in data:
@ -83,11 +78,9 @@ class InputFile(object):
# on py2.7, pylint fails to understand this properly
# pylint: disable=E1101
self.filename = os.path.basename(self.input_file.name)
elif from_url:
self.filename = os.path.basename(self.input_file.url).split('?')[0].split('&')[0]
try:
self.mimetype = InputFile.is_image(self.input_file_content)
self.mimetype = self.is_image(self.input_file_content)
if not self.filename or '.' not in self.filename:
self.filename = self.mimetype.replace('/', '.')
except TelegramError:
@ -118,7 +111,8 @@ class InputFile(object):
form_boundary = '--' + self.boundary
# Add data fields
for name, value in self.data.items():
for name in iter(self.data):
value = self.data[name]
form.extend([
form_boundary, 'Content-Disposition: form-data; name="%s"' % name, '', str(value)
])
@ -133,7 +127,7 @@ class InputFile(object):
form.append('--' + self.boundary + '--')
form.append('')
return InputFile._parse(form)
return self._parse(form)
@staticmethod
def _parse(form):
@ -174,18 +168,17 @@ class InputFile(object):
"""Check if the request is a file request.
Args:
data (str): A dict of (str, unicode) key/value pairs
data (dict): A dict of (str, unicode) key/value pairs
Returns:
bool
"""
if data:
file_types = ['audio', 'document', 'photo', 'sticker', 'video', 'voice', 'certificate']
file_type = [i for i in list(data.keys()) if i in file_types]
file_type = [i for i in iter(data) if i in FILE_TYPES]
if file_type:
file_content = data[file_type[0]]
return hasattr(file_content, 'read') or str(file_content).startswith('http')
return hasattr(file_content, 'read')
return False

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram KeyboardButton."""
"""This module contains an object that represents a Telegram KeyboardButton."""
from telegram import TelegramObject

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Location."""
"""This module contains an object that represents a Telegram Location."""
from telegram import TelegramObject

View file

@ -17,14 +17,14 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Message."""
"""This module contains an object that represents a Telegram Message."""
import sys
from datetime import datetime
from time import mktime
from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize, Sticker, TelegramObject,
User, Video, Voice, Venue, MessageEntity)
User, Video, Voice, Venue, MessageEntity, Game)
class Message(TelegramObject):
@ -45,6 +45,7 @@ class Message(TelegramObject):
text (str):
audio (:class:`telegram.Audio`):
document (:class:`telegram.Document`):
game (:class:`telegram.Game`):
photo (List[:class:`telegram.PhotoSize`]):
sticker (:class:`telegram.Sticker`):
video (:class:`telegram.Video`):
@ -86,6 +87,7 @@ class Message(TelegramObject):
text (Optional[str]):
audio (Optional[:class:`telegram.Audio`]):
document (Optional[:class:`telegram.Document`]):
game (Optional[:class:`telegram.Game`]):
photo (Optional[List[:class:`telegram.PhotoSize`]]):
sticker (Optional[:class:`telegram.Sticker`]):
video (Optional[:class:`telegram.Video`]):
@ -155,6 +157,7 @@ class Message(TelegramObject):
self.text = text
self.entities = entities or list()
self.audio = audio
self.game = kwargs.get('game')
self.document = document
self.photo = photo
self.sticker = sticker
@ -207,6 +210,7 @@ class Message(TelegramObject):
data['edit_date'] = Message._fromtimestamp(data.get('edit_date'))
data['audio'] = Audio.de_json(data.get('audio'), bot)
data['document'] = Document.de_json(data.get('document'), bot)
data['game'] = Game.de_json(data.get('game'), bot)
data['photo'] = PhotoSize.de_list(data.get('photo'), bot)
data['sticker'] = Sticker.de_json(data.get('sticker'), bot)
data['video'] = Video.de_json(data.get('video'), bot)
@ -537,5 +541,7 @@ class Message(TelegramObject):
if types is None:
types = MessageEntity.ALL_TYPES
return {entity: self.parse_entity(entity)
for entity in self.entities if entity.type in types}
return {
entity: self.parse_entity(entity)
for entity in self.entities if entity.type in types
}

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram MessageEntity."""
"""This module contains an object that represents a Telegram MessageEntity."""
from telegram import User, TelegramObject
@ -80,5 +80,6 @@ class MessageEntity(TelegramObject):
PRE = 'pre'
TEXT_LINK = 'text_link'
TEXT_MENTION = 'text_mention'
ALL_TYPES = [MENTION, HASHTAG, BOT_COMMAND, URL, EMAIL, BOLD, ITALIC, CODE, PRE, TEXT_LINK,
TEXT_MENTION]
ALL_TYPES = [
MENTION, HASHTAG, BOT_COMMAND, URL, EMAIL, BOLD, ITALIC, CODE, PRE, TEXT_LINK, TEXT_MENTION
]

View file

@ -17,7 +17,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
"""This module contains an object that represents a Telegram
Message Parse Modes."""

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram PhotoSize."""
"""This module contains an object that represents a Telegram PhotoSize."""
from telegram import TelegramObject

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
"""This module contains an object that represents a Telegram
ReplyKeyboardHide."""
from telegram import ReplyMarkup

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
"""This module contains an object that represents a Telegram
ReplyKeyboardMarkup."""
from telegram import ReplyMarkup, KeyboardButton

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Sticker."""
"""This module contains an object that represents a Telegram Sticker."""
from telegram import PhotoSize, TelegramObject

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Update."""
"""This module contains an object that represents a Telegram Update."""
from telegram import (Message, TelegramObject, InlineQuery, ChosenInlineResult, CallbackQuery)

View file

@ -17,7 +17,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram User."""
"""This module contains an object that represents a Telegram User."""
from telegram import TelegramObject

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram
"""This module contains an object that represents a Telegram
UserProfilePhotos."""
from telegram import PhotoSize, TelegramObject

View file

@ -31,7 +31,8 @@ import urllib3
from urllib3.connection import HTTPConnection
from telegram import (InputFile, TelegramError)
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated, \
RetryAfter
logging.getLogger('urllib3').setLevel(logging.WARNING)
@ -105,6 +106,9 @@ class Request(object):
migrate_to_chat_id = parameters.get('migrate_to_chat_id')
if migrate_to_chat_id:
raise ChatMigrated(migrate_to_chat_id)
retry_after = parameters.get('retry_after')
if retry_after:
raise RetryAfter(retry_after)
if description:
return description

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Venue."""
"""This module contains an object that represents a Telegram Venue."""
from telegram import TelegramObject, Location

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Video."""
"""This module contains an object that represents a Telegram Video."""
from telegram import PhotoSize, TelegramObject

View file

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a object that represents a Telegram Voice."""
"""This module contains an object that represents a Telegram Voice."""
from telegram import TelegramObject

65
telegram/webhookinfo.py Normal file
View file

@ -0,0 +1,65 @@
#!/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 Lesser 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 Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram WebhookInfo."""
from telegram import TelegramObject
class WebhookInfo(TelegramObject):
"""This object represents a Telegram WebhookInfo.
Attributes:
url (str): Webhook URL, may be empty if webhook is not set up.
has_custom_certificate (bool):
pending_update_count (int):
last_error_date (int):
last_error_message (str):
Args:
url (str): Webhook URL, may be empty if webhook is not set up.
has_custom_certificate (bool):
pending_update_count (int):
last_error_date (Optional[int]):
last_error_message (Optional[str]):
"""
def __init__(self, url, has_custom_certificate, pending_update_count, **kwargs):
# Required
self.url = url
self.has_custom_certificate = has_custom_certificate
self.pending_update_count = pending_update_count
self.last_error_date = kwargs.get('last_error_date', '')
self.last_error_message = kwargs.get('last_error_message', '')
@staticmethod
def de_json(data, bot):
"""
Args:
data (dict):
bot (telegram.Bot):
Returns:
telegram.WebhookInfo:
"""
if not data:
return None
return WebhookInfo(**data)

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents a Base class for tests"""
import os
import sys

BIN
tests/data/game.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
tests/data/game.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram Audio"""
import sys
import unittest
@ -40,6 +40,7 @@ class AudioTest(BaseTest, unittest.TestCase):
self.duration = 4
self.performer = 'Leandro Toledo'
self.title = 'Teste'
self.caption = "Test audio"
self.mime_type = 'audio/mpeg'
self.file_size = 28232
@ -48,6 +49,7 @@ class AudioTest(BaseTest, unittest.TestCase):
'duration': self.duration,
'performer': self.performer,
'title': self.title,
'caption': self.caption,
'mime_type': self.mime_type,
'file_size': self.file_size
}
@ -57,6 +59,8 @@ class AudioTest(BaseTest, unittest.TestCase):
def test_send_audio_required_args_only(self):
message = self._bot.sendAudio(self._chat_id, self.audio_file)
self.assertEqual(message.caption, '')
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
@ -76,9 +80,12 @@ class AudioTest(BaseTest, unittest.TestCase):
duration=self.duration,
performer=self.performer,
title=self.title,
caption=self.caption,
mime_type=self.mime_type,
file_size=self.file_size)
self.assertEqual(message.caption, self.caption)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
@ -97,7 +104,10 @@ class AudioTest(BaseTest, unittest.TestCase):
audio=self.audio_file,
duration=self.duration,
performer=self.performer,
title=self.title)
title=self.title,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
audio = message.audio
@ -118,8 +128,11 @@ class AudioTest(BaseTest, unittest.TestCase):
duration=self.duration,
performer=self.performer,
title=self.title,
caption=self.caption,
filename='telegram_custom.mp3')
self.assertEqual(message.caption, self.caption)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
@ -134,19 +147,32 @@ class AudioTest(BaseTest, unittest.TestCase):
@timeout(10)
def test_send_audio_mp3_url_file(self):
message = self._bot.sendAudio(
chat_id=self._chat_id,
audio=self.audio_file_url,
duration=self.duration,
performer=self.performer,
title=self.title)
chat_id=self._chat_id, audio=self.audio_file_url, duration=self.duration)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
self.assertNotEqual(audio.file_id, '')
self.assertEqual(audio.duration, self.duration)
self.assertEqual(audio.mime_type, self.mime_type)
self.assertEqual(audio.file_size, self.file_size)
@flaky(3, 1)
@timeout(10)
def test_send_audio_mp3_url_file_with_caption(self):
message = self._bot.sendAudio(
chat_id=self._chat_id,
audio=self.audio_file_url,
duration=self.duration,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
audio = message.audio
self.assertTrue(isinstance(audio.file_id, str))
self.assertNotEqual(audio.file_id, '')
self.assertEqual(audio.duration, self.duration)
self.assertEqual(audio.performer, self.performer)
self.assertEqual(audio.title, self.title)
self.assertEqual(audio.mime_type, self.mime_type)
self.assertEqual(audio.file_size, self.file_size)
@ -158,7 +184,10 @@ class AudioTest(BaseTest, unittest.TestCase):
audio=self.audio_file_id,
duration=self.duration,
performer=self.performer,
title=self.title)
title=self.title,
caption=self.caption)
self.assertEqual(message.caption, self.caption)
audio = message.audio

View file

@ -17,11 +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"""
"""This module contains an object that represents Tests for Telegram Bot"""
import io
import re
from datetime import datetime
import time
import sys
import unittest
@ -30,6 +31,7 @@ from flaky import flaky
sys.path.append('.')
import telegram
from telegram.error import BadRequest
from tests.base import BaseTest, timeout
@ -66,6 +68,17 @@ class BotTest(BaseTest, unittest.TestCase):
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
self.assertTrue(isinstance(message.date, datetime))
@flaky(3, 1)
@timeout(10)
def test_sendMessage_no_web_page_preview(self):
message = self._bot.sendMessage(
chat_id=self._chat_id,
text='Моё судно на воздушной подушке полно угрей',
disable_web_page_preview=True)
self.assertTrue(self.is_json(message.to_json()))
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
@flaky(3, 1)
@timeout(10)
def testGetUpdates(self):
@ -158,6 +171,17 @@ class BotTest(BaseTest, unittest.TestCase):
self.assertTrue(self.is_json(message.to_json()))
self.assertEqual(message.photo[0].file_size, 1451)
@flaky(3, 1)
@timeout(10)
def testSendGame(self):
game_short_name = 'python_telegram_bot_test_game'
message = self._bot.sendGame(game_short_name=game_short_name, chat_id=self._chat_id)
self.assertTrue(self.is_json(message.to_json()))
self.assertEqual(message.game.description, 'This is a test game for python-telegram-bot.')
self.assertEqual(message.game.animation.file_id, 'BQADAQADKwIAAvjAuQABozciVqhFDO0C')
self.assertEqual(message.game.photo[0].file_size, 851)
@flaky(3, 1)
@timeout(10)
def testSendChatAction(self):
@ -171,6 +195,13 @@ class BotTest(BaseTest, unittest.TestCase):
self.assertTrue(self.is_json(upf.to_json()))
self.assertEqual(upf.photos[0][0].file_size, 12421)
@flaky(3, 1)
@timeout(10)
def test_get_one_user_profile_photo(self):
upf = self._bot.getUserProfilePhotos(user_id=self._chat_id, offset=0)
self.assertTrue(self.is_json(upf.to_json()))
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)
@ -255,6 +286,46 @@ class BotTest(BaseTest, unittest.TestCase):
self.assertEqual(chat_member.status, "administrator")
self._testUserEqualsBot(bot)
@flaky(3, 1)
@timeout(10)
def test_get_webhook_info(self):
url = 'https://python-telegram-bot.org/test/webhook'
self._bot.set_webhook(url)
info = self._bot.getWebhookInfo()
self._bot.set_webhook('')
self.assertEqual(url, info.url)
@flaky(3, 1)
@timeout(10)
def test_set_game_score(self):
# We need a game to set the score for
game_short_name = 'python_telegram_bot_test_game'
game = self._bot.sendGame(game_short_name=game_short_name, chat_id=self._chat_id)
message = self._bot.set_game_score(
user_id=self._chat_id,
score=int(time.time() - 1450000000),
chat_id=game.chat_id,
message_id=game.message_id,
edit_message=True)
self.assertTrue(self.is_json(game.to_json()))
self.assertEqual(message.game.description, game.game.description)
self.assertEqual(message.game.animation.file_id, game.game.animation.file_id)
self.assertEqual(message.game.photo[0].file_size, game.game.photo[0].file_size)
self.assertNotEqual(message.game.text, game.game.text)
@flaky(3, 1)
@timeout(10)
def test_set_game_score_too_low_score(self):
# We need a game to set the score for
game_short_name = 'python_telegram_bot_test_game'
game = self._bot.sendGame(game_short_name=game_short_name, chat_id=self._chat_id)
with self.assertRaises(BadRequest):
self._bot.set_game_score(
user_id=self._chat_id, score=100, chat_id=game.chat_id, message_id=game.message_id)
def _testUserEqualsBot(self, user):
"""Tests if user is our trusty @PythonTelegramBot."""
self.assertEqual(user.id, 133505823)
@ -263,6 +334,27 @@ class BotTest(BaseTest, unittest.TestCase):
self.assertEqual(user.username, 'PythonTelegramBot')
self.assertEqual(user.name, '@PythonTelegramBot')
@flaky(3, 1)
@timeout(10)
def test_info(self):
# tests the Bot.info decorator and associated funcs
self.assertEqual(self._bot.id, 133505823)
self.assertEqual(self._bot.first_name, 'PythonTelegramBot')
self.assertEqual(self._bot.last_name, '')
self.assertEqual(self._bot.username, 'PythonTelegramBot')
self.assertEqual(self._bot.name, '@PythonTelegramBot')
@flaky(3, 1)
@timeout(10)
def test_send_contact(self):
phone = '+3-54-5445445'
name = 'name'
last = 'last'
message = self._bot.send_contact(self._chat_id, phone, name, last)
self.assertEqual(phone.replace('-', ''), message.contact.phone_number)
self.assertEqual(name, message.contact.first_name)
self.assertEqual(last, message.contact.last_name)
if __name__ == '__main__':
unittest.main()

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram Chat"""
import unittest
import sys
@ -36,8 +36,14 @@ class ChatTest(BaseTest, unittest.TestCase):
self.id = -28767330
self.title = 'ToledosPalaceBot - Group'
self.type = 'group'
self.all_members_are_admins = False
self.json_dict = {'id': self.id, 'title': self.title, 'type': self.type}
self.json_dict = {
'id': self.id,
'title': self.title,
'type': self.type,
'all_members_are_admins': self.all_members_are_admins
}
def test_group_chat_de_json_empty_json(self):
group_chat = telegram.Chat.de_json({}, self._bot)
@ -50,6 +56,7 @@ class ChatTest(BaseTest, unittest.TestCase):
self.assertEqual(group_chat.id, self.id)
self.assertEqual(group_chat.title, self.title)
self.assertEqual(group_chat.type, self.type)
self.assertEqual(group_chat.all_members_are_admins, self.all_members_are_admins)
def test_group_chat_to_json(self):
group_chat = telegram.Chat.de_json(self.json_dict, self._bot)
@ -63,6 +70,7 @@ class ChatTest(BaseTest, unittest.TestCase):
self.assertEqual(group_chat['id'], self.id)
self.assertEqual(group_chat['title'], self.title)
self.assertEqual(group_chat['type'], self.type)
self.assertEqual(group_chat['all_members_are_admins'], self.all_members_are_admins)
@flaky(3, 1)
def test_send_action(self):

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
ChosenInlineResult"""
import sys

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram Contact"""
import unittest
import sys

View file

@ -18,7 +18,7 @@
# 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 ConversationHandler
This module contains an object that represents Tests for ConversationHandler
"""
import logging
import sys
@ -66,14 +66,17 @@ class ConversationHandlerTest(BaseTest, unittest.TestCase):
def setUp(self):
self.current_state = dict()
self.entry_points = [CommandHandler('start', self.start)]
self.states = {self.THIRSTY: [CommandHandler('brew', self.brew),
CommandHandler('wait', self.start)],
self.BREWING: [CommandHandler('pourCoffee', self.drink)],
self.DRINKING: [CommandHandler('startCoding', self.code),
CommandHandler('drinkMore', self.drink)],
self.CODING: [CommandHandler('keepCoding', self.code),
CommandHandler('gettingThirsty', self.start),
CommandHandler('drinkMore', self.drink)],}
self.states = {
self.THIRSTY: [CommandHandler('brew', self.brew), CommandHandler('wait', self.start)],
self.BREWING: [CommandHandler('pourCoffee', self.drink)],
self.DRINKING:
[CommandHandler('startCoding', self.code), CommandHandler('drinkMore', self.drink)],
self.CODING: [
CommandHandler('keepCoding', self.code),
CommandHandler('gettingThirsty', self.start),
CommandHandler('drinkMore', self.drink)
],
}
self.fallbacks = [CommandHandler('eat', self.start)]
def _setup_updater(self, *args, **kwargs):

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram Document"""
import sys
import unittest
@ -37,10 +37,12 @@ class DocumentTest(BaseTest, unittest.TestCase):
self.document_file = open('tests/data/telegram.png', 'rb')
self.document_file_id = 'BQADAQADpAADHyP1B04ipZxJTe2BAg'
self.document_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.gif'
self.thumb = {'width': 90,
'height': 90,
'file_id': 'BQADAQADoQADHyP1B0mzJMVyzcB0Ag',
'file_size': 2364}
self.thumb = {
'width': 90,
'height': 90,
'file_id': 'BQADAQADoQADHyP1B0mzJMVyzcB0Ag',
'file_size': 2364
}
self.file_name = 'telegram.png'
self.mime_type = 'image/png'
self.file_size = 12948
@ -56,7 +58,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, caption='caption text')
document = message.document

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram File"""
import sys
import unittest

View file

@ -17,7 +17,7 @@
# 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 Filters for use with MessageHandler
This module contains an object that represents Tests for Filters for use with MessageHandler.
"""
import sys
@ -105,6 +105,12 @@ class FiltersTest(BaseTest, unittest.TestCase):
self.message.venue = None
self.assertFalse(Filters.venue(self.message))
def test_filters_game(self):
self.message.game = 'test'
self.assertTrue(Filters.game(self.message))
self.message.game = None
self.assertFalse(Filters.game(self.message))
def test_filters_status_update(self):
self.assertFalse(Filters.status_update(self.message))

View file

@ -17,7 +17,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram ForceReply"""
import sys
import unittest
@ -35,8 +35,10 @@ class ForceReplyTest(BaseTest, unittest.TestCase):
self.force_reply = True
self.selective = True
self.json_dict = {'force_reply': self.force_reply,
'selective': self.selective,}
self.json_dict = {
'force_reply': self.force_reply,
'selective': self.selective,
}
def test_send_message_with_force_reply(self):
message = self._bot.sendMessage(

134
tests/test_game.py Normal file
View file

@ -0,0 +1,134 @@
#!/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 an object that represents Tests for Telegram Games"""
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class GameTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram Game."""
def setUp(self):
self.title = 'Python-telegram-bot Test Game'
self.description = 'description'
self.photo = [{'width': 640, 'height': 360, 'file_id': 'Blah', 'file_size': 0}]
self.text = 'Other description'
self.text_entities = [{'offset': 13, 'length': 17, 'type': telegram.MessageEntity.URL}]
self.animation = {'file_id': 'Blah'}
self.json_dict = {
'title': self.title,
'description': self.description,
'photo': self.photo,
'text': self.text,
'text_entities': self.text_entities,
'animation': self.animation
}
def test_game_de_json(self):
game = telegram.Game.de_json(self.json_dict, self._bot)
self.assertEqual(game.title, self.title)
self.assertEqual(game.description, self.description)
self.assertTrue(isinstance(game.photo[0], telegram.PhotoSize))
self.assertEqual(game.text, self.text)
self.assertTrue(isinstance(game.text_entities[0], telegram.MessageEntity))
self.assertTrue(isinstance(game.animation, telegram.Animation))
def test_game_to_json(self):
game = telegram.Game.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(game.to_json()))
def test_game_all_args(self):
game = telegram.Game(
title=self.title,
description=self.description,
photo=self.photo,
text=self.text,
text_entities=self.text_entities,
animation=self.animation)
self.assertEqual(game.title, self.title)
self.assertEqual(game.description, self.description)
self.assertEqual(game.photo, self.photo)
self.assertEqual(game.text, self.text)
self.assertEqual(game.text_entities, self.text_entities)
self.assertEqual(game.animation, self.animation)
def test_parse_entity(self):
text = (b'\\U0001f469\\u200d\\U0001f469\\u200d\\U0001f467'
b'\\u200d\\U0001f467\\U0001f431http://google.com').decode('unicode-escape')
entity = telegram.MessageEntity(type=telegram.MessageEntity.URL, offset=13, length=17)
game = telegram.Game(
self.title, self.description, self.photo, text=text, text_entities=[entity])
self.assertEqual(game.parse_text_entity(entity), 'http://google.com')
def test_parse_entities(self):
text = (b'\\U0001f469\\u200d\\U0001f469\\u200d\\U0001f467'
b'\\u200d\\U0001f467\\U0001f431http://google.com').decode('unicode-escape')
entity = telegram.MessageEntity(type=telegram.MessageEntity.URL, offset=13, length=17)
entity_2 = telegram.MessageEntity(type=telegram.MessageEntity.BOLD, offset=13, length=1)
game = telegram.Game(
self.title, self.description, self.photo, text=text, text_entities=[entity_2, entity])
self.assertDictEqual(
game.parse_text_entities(telegram.MessageEntity.URL), {entity: 'http://google.com'})
self.assertDictEqual(game.parse_text_entities(),
{entity: 'http://google.com',
entity_2: 'h'})
class AnimationTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram Animatiion."""
def setUp(self):
self.file_id = 'thisisafileid'
self.thumb = {'width': 640, 'height': 360, 'file_id': 'Blah', 'file_size': 0}
self.file_name = 'File name'
self.mime_type = 'something/gif'
self.file_size = 42
self.json_dict = {
'file_id': self.file_id,
'thumb': self.thumb,
'file_name': self.file_name,
'mime_type': self.mime_type,
'file_size': self.file_size
}
def test_animation_de_json(self):
animation = telegram.Animation.de_json(self.json_dict, self._bot)
self.assertEqual(animation.file_id, self.file_id)
self.assertTrue(isinstance(animation.thumb, telegram.PhotoSize))
self.assertEqual(animation.file_name, self.file_name)
self.assertEqual(animation.mime_type, self.mime_type)
self.assertEqual(animation.file_size, self.file_size)
def test_game_to_json(self):
animation = telegram.Animation.de_json(self.json_dict, self._bot)
self.assertTrue(self.is_json(animation.to_json()))

View file

@ -17,7 +17,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram InlineKeyboardButton"""
import sys
import unittest

View file

@ -17,7 +17,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram InlineKeyboardMarkup"""
import sys
import unittest
@ -32,13 +32,15 @@ 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.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()]],
'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):

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQuery"""
import sys

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultArticle"""
import sys
@ -36,9 +36,8 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.url = 'url'
self.hide_url = True
self.description = 'description'

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultAudio"""
import sys
@ -38,10 +38,10 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
self.title = 'title'
self.performer = 'performer'
self.audio_duration = 'audio_duration'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,
@ -50,6 +50,7 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
'title': self.title,
'performer': self.performer,
'audio_duration': self.audio_duration,
'caption': self.caption,
'input_message_content': self.input_message_content.to_dict(),
'reply_markup': self.reply_markup.to_dict(),
}
@ -63,6 +64,7 @@ class InlineQueryResultAudioTest(BaseTest, unittest.TestCase):
self.assertEqual(audio.title, self.title)
self.assertEqual(audio.performer, self.performer)
self.assertEqual(audio.audio_duration, self.audio_duration)
self.assertEqual(audio.caption, self.caption)
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())

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedAudio"""
import sys
@ -36,15 +36,16 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
self.id = 'id'
self.type = 'audio'
self.audio_file_id = 'audio file id'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
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,
'caption': self.caption,
'input_message_content': self.input_message_content.to_dict(),
'reply_markup': self.reply_markup.to_dict(),
}
@ -55,6 +56,7 @@ class InlineQueryResultCachedAudioTest(BaseTest, unittest.TestCase):
self.assertEqual(audio.type, self.type)
self.assertEqual(audio.id, self.id)
self.assertEqual(audio.audio_file_id, self.audio_file_id)
self.assertEqual(audio.caption, self.caption)
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())

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedDocument"""
import sys
@ -40,9 +40,8 @@ class InlineQueryResultCachedDocumentTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedGif"""
import sys
@ -38,9 +38,8 @@ class InlineQueryResultCachedGifTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedMpeg4Gif"""
import sys
@ -39,9 +39,8 @@ class InlineQueryResultCachedMpeg4GifTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedPhoto"""
import sys
@ -40,9 +40,8 @@ class InlineQueryResultCachedPhotoTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedSticker"""
import sys
@ -37,9 +37,8 @@ class InlineQueryResultCachedStickerTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedVideo"""
import sys
@ -40,9 +40,8 @@ class InlineQueryResultCachedVideoTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultCachedVoice"""
import sys
@ -37,18 +37,17 @@ class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
self.type = 'voice'
self.voice_file_id = 'voice 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.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,
'caption': self.caption,
'input_message_content': self.input_message_content.to_dict(),
'reply_markup': self.reply_markup.to_dict(),
}
@ -60,7 +59,7 @@ class InlineQueryResultCachedVoiceTest(BaseTest, unittest.TestCase):
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.assertEqual(voice.caption, self.caption)
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())

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultContact"""
import sys
@ -41,9 +41,8 @@ class InlineQueryResultContactTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultDocument"""
import sys
@ -43,9 +43,8 @@ class InlineQueryResultDocumentTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultGif"""
import sys
@ -41,9 +41,8 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultLocation"""
import sys
@ -41,9 +41,8 @@ class InlineQueryResultLocationTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultMpeg4Gif"""
import sys
@ -41,9 +41,8 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultPhoto"""
import sys
@ -42,9 +42,8 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultVenue"""
import sys
@ -43,9 +43,8 @@ class InlineQueryResultVenueTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'id': self.id,
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultVideo"""
import sys
@ -44,9 +44,8 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
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.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InlineQueryResultVoice"""
import sys
@ -37,10 +37,10 @@ class InlineQueryResultVoiceTest(BaseTest, unittest.TestCase):
self.voice_url = 'voice url'
self.title = 'title'
self.voice_duration = 'voice_duration'
self.caption = 'caption'
self.input_message_content = telegram.InputTextMessageContent('input_message_content')
self.reply_markup = telegram.InlineKeyboardMarkup([[
telegram.InlineKeyboardButton('reply_markup')
]])
self.reply_markup = telegram.InlineKeyboardMarkup(
[[telegram.InlineKeyboardButton('reply_markup')]])
self.json_dict = {
'type': self.type,
@ -48,6 +48,7 @@ class InlineQueryResultVoiceTest(BaseTest, unittest.TestCase):
'voice_url': self.voice_url,
'title': self.title,
'voice_duration': self.voice_duration,
'caption': self.caption,
'input_message_content': self.input_message_content.to_dict(),
'reply_markup': self.reply_markup.to_dict(),
}
@ -60,6 +61,7 @@ class InlineQueryResultVoiceTest(BaseTest, unittest.TestCase):
self.assertEqual(voice.voice_url, self.voice_url)
self.assertEqual(voice.title, self.title)
self.assertEqual(voice.voice_duration, self.voice_duration)
self.assertEqual(voice.caption, self.caption)
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())

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InputContactMessageContent"""
import sys

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InputLocationMessageContent"""
import sys
@ -35,8 +35,10 @@ class InputLocationMessageContentTest(BaseTest, unittest.TestCase):
self.latitude = 1.
self.longitude = 2.
self.json_dict = {'longitude': self.longitude,
'latitude': self.latitude,}
self.json_dict = {
'longitude': self.longitude,
'latitude': self.latitude,
}
def test_ilmc_de_json(self):
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict, self._bot)

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InputMessageContent"""
import sys

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InputTextMessageContent"""
import sys

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
InputVenueMessageContent"""
import sys

View file

@ -18,7 +18,7 @@
# 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
This module contains an object that represents Tests for JobQueue
"""
import logging
import sys

View file

@ -17,7 +17,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
KeyboardButton"""
import sys

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram Location"""
import unittest
import sys

View file

@ -17,7 +17,7 @@
#
# 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 Message"""
"""This module contains an object that represents Tests for Telegram Message"""
import sys
import unittest
@ -55,8 +55,9 @@ class MessageTest(BaseTest, unittest.TestCase):
entities=[entity_2, entity])
self.assertDictEqual(
message.parse_entities(telegram.MessageEntity.URL), {entity: 'http://google.com'})
self.assertDictEqual(message.parse_entities(), {entity: 'http://google.com',
entity_2: 'h'})
self.assertDictEqual(message.parse_entities(),
{entity: 'http://google.com',
entity_2: 'h'})
@flaky(3, 1)
def test_reply_text(self):

View file

@ -16,7 +16,7 @@
#
# 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
"""This module contains an object that represents Tests for Telegram
MessageEntity"""
import sys

View file

@ -17,7 +17,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram ParseMode"""
import sys
import unittest

View file

@ -16,7 +16,7 @@
#
# 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"""
"""This module contains an object that represents Tests for Telegram Photo"""
import sys
import unittest

Some files were not shown because too many files have changed in this diff Show more