mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2026-06-25 02:34:43 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10a98211f8 | |||
| b5570ddfa5 | |||
| 99c9544a27 | |||
| 0e0611767a | |||
| 4ba5fbf4f5 | |||
| 4b0be65a76 | |||
| 6e5302c089 | |||
| 5aab4525c2 | |||
| 62c651d167 | |||
| 41e457f5ed | |||
| 4ce0ab53d0 | |||
| d940afa718 | |||
| a327e9d6ff | |||
| 998040da92 | |||
| 0c74b3cfb9 | |||
| 0ca3ef7a38 | |||
| e160355190 | |||
| d80e0b4b8c | |||
| 96d98084c7 | |||
| a686db2c6f |
+13
@@ -1,3 +1,16 @@
|
||||
**2016-05-01**
|
||||
|
||||
*Released 4.0.3*
|
||||
|
||||
- Add missing attribute ``location`` to ``InlineQuery``
|
||||
|
||||
**2016-04-29**
|
||||
|
||||
*Released 4.0.2*
|
||||
|
||||
- Bugfixes
|
||||
- ``KeyboardReplyMarkup`` now accepts ``str`` again
|
||||
|
||||
**2016-04-27**
|
||||
|
||||
*Released 4.0.1*
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ You can install or upgrade python-telegram-bot with:
|
||||
|
||||
.. code:: shell
|
||||
|
||||
$ pip install python-telegram-bot==4.0rc1 --upgrade
|
||||
$ pip install python-telegram-bot --upgrade
|
||||
|
||||
===================
|
||||
_`Getting the code`
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ author = u'Leandro Toledo'
|
||||
# The short X.Y version.
|
||||
version = '4.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '4.0.1'
|
||||
release = '4.0.3'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ def main():
|
||||
# Regex handlers will receive all updates on which their regex matches,
|
||||
# but we have to add it in a separate group, since in one group,
|
||||
# only one handler will be executed
|
||||
dp.addHandler(RegexHandler('.*', any_message), group='log')
|
||||
dp.addHandler(RegexHandler('.*', any_message), group=1)
|
||||
|
||||
# String handlers work pretty much the same. Note that we have to tell
|
||||
# the handler to pass the args or update_queue parameter
|
||||
|
||||
@@ -75,7 +75,7 @@ def main():
|
||||
# on different commands - answer in Telegram
|
||||
dp.addHandler(CommandHandler("start", start))
|
||||
dp.addHandler(CommandHandler("help", start))
|
||||
dp.addHandler(CommandHandler("set", set))
|
||||
dp.addHandler(CommandHandler("set", set, pass_args=True))
|
||||
|
||||
# log all errors
|
||||
dp.addErrorHandler(error)
|
||||
|
||||
@@ -26,7 +26,7 @@ def requirements():
|
||||
|
||||
setup(
|
||||
name='python-telegram-bot',
|
||||
version='4.0.1',
|
||||
version='4.0.3',
|
||||
author='Leandro Toledo',
|
||||
author_email='devs@python-telegram-bot.org',
|
||||
license='LGPLv3',
|
||||
|
||||
@@ -81,7 +81,7 @@ from .bot import Bot
|
||||
|
||||
|
||||
__author__ = 'devs@python-telegram-bot.org'
|
||||
__version__ = '4.0.1'
|
||||
__version__ = '4.0.3'
|
||||
__all__ = ['Audio',
|
||||
'Bot',
|
||||
'Chat',
|
||||
|
||||
+36
-117
@@ -43,11 +43,9 @@ class Bot(TelegramObject):
|
||||
|
||||
Args:
|
||||
token (str): Bot's unique authentication.
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
base_url (Optional[str]): Telegram Bot API service URL.
|
||||
base_file_url (Optional[str]): Telegram Bot API file URL.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
@@ -141,8 +139,7 @@ class Bot(TelegramObject):
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
if result is True:
|
||||
return result
|
||||
@@ -208,10 +205,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, the sent message is
|
||||
@@ -258,10 +251,6 @@ class Bot(TelegramObject):
|
||||
receive a notification with no sound.
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -317,10 +306,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -387,10 +372,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -451,10 +432,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -505,10 +482,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -562,10 +535,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -624,10 +593,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -677,10 +642,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -739,10 +700,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -800,10 +757,6 @@ class Bot(TelegramObject):
|
||||
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.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, instance representing the
|
||||
@@ -895,10 +848,6 @@ class Bot(TelegramObject):
|
||||
Keyword Args:
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
bool: On success, `True` is returned.
|
||||
@@ -927,8 +876,7 @@ class Bot(TelegramObject):
|
||||
data['switch_pm_parameter'] = switch_pm_parameter
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
return result
|
||||
|
||||
@@ -953,10 +901,6 @@ class Bot(TelegramObject):
|
||||
Keyword Args:
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
list[:class:`telegram.UserProfilePhotos`]: A list of
|
||||
@@ -977,8 +921,7 @@ class Bot(TelegramObject):
|
||||
data['limit'] = limit
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
return UserProfilePhotos.de_json(result)
|
||||
|
||||
@@ -997,10 +940,6 @@ class Bot(TelegramObject):
|
||||
Keyword Args:
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.File`: On success, a :class:`telegram.File`
|
||||
@@ -1016,8 +955,7 @@ class Bot(TelegramObject):
|
||||
data = {'file_id': file_id}
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
if result.get('file_path'):
|
||||
result['file_path'] = '%s/%s' % (self.base_file_url,
|
||||
@@ -1045,10 +983,6 @@ class Bot(TelegramObject):
|
||||
Keyword Args:
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
bool: On success, `True` is returned.
|
||||
@@ -1064,8 +998,7 @@ class Bot(TelegramObject):
|
||||
'user_id': user_id}
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
return result
|
||||
|
||||
@@ -1089,10 +1022,6 @@ class Bot(TelegramObject):
|
||||
Keyword Args:
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
bool: On success, `True` is returned.
|
||||
@@ -1108,8 +1037,7 @@ class Bot(TelegramObject):
|
||||
'user_id': user_id}
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
return result
|
||||
|
||||
@@ -1158,13 +1086,11 @@ class Bot(TelegramObject):
|
||||
data['show_alert'] = show_alert
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
return result
|
||||
|
||||
@log
|
||||
@message
|
||||
def editMessageText(self,
|
||||
text,
|
||||
chat_id=None,
|
||||
@@ -1172,6 +1098,7 @@ class Bot(TelegramObject):
|
||||
inline_message_id=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None,
|
||||
reply_markup=None,
|
||||
**kwargs):
|
||||
"""Use this method to edit text messages sent by the bot or via the bot
|
||||
(for inline bots).
|
||||
@@ -1194,16 +1121,12 @@ class Bot(TelegramObject):
|
||||
italic, fixed-width text or inline URLs in your bot's message.
|
||||
disable_web_page_preview:
|
||||
Disables link previews for links in this message.
|
||||
reply_markup:
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
|
||||
Keyword Args:
|
||||
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by
|
||||
@@ -1229,8 +1152,16 @@ class Bot(TelegramObject):
|
||||
data['parse_mode'] = parse_mode
|
||||
if disable_web_page_preview:
|
||||
data['disable_web_page_preview'] = disable_web_page_preview
|
||||
if reply_markup:
|
||||
if isinstance(reply_markup, ReplyMarkup):
|
||||
data['reply_markup'] = reply_markup.to_json()
|
||||
else:
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
return url, data
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
return Message.de_json(result)
|
||||
|
||||
@log
|
||||
@message
|
||||
@@ -1259,10 +1190,6 @@ class Bot(TelegramObject):
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by
|
||||
@@ -1314,10 +1241,6 @@ class Bot(TelegramObject):
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by
|
||||
@@ -1346,7 +1269,8 @@ class Bot(TelegramObject):
|
||||
def getUpdates(self,
|
||||
offset=None,
|
||||
limit=100,
|
||||
**kwargs):
|
||||
timeout=0,
|
||||
network_delay=.2):
|
||||
"""Use this method to receive incoming updates using long polling.
|
||||
|
||||
Args:
|
||||
@@ -1359,17 +1283,17 @@ class Bot(TelegramObject):
|
||||
limit:
|
||||
Limits the number of updates to be retrieved. Values between 1-100
|
||||
are accepted. Defaults to 100.
|
||||
|
||||
Keyword Args:
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
timeout:
|
||||
Timeout in seconds for long polling. Defaults to 0, i.e. usual
|
||||
short polling.
|
||||
network_delay:
|
||||
Additional timeout in seconds to allow the response from Telegram
|
||||
to take some time when using long polling. Defaults to 2, which
|
||||
should be enough for most connections. Increase it if it takes very
|
||||
long for data to be transmitted from and to the Telegram servers.
|
||||
|
||||
Returns:
|
||||
list[:class:`telegram.Message`]: A list of :class:`telegram.Update`
|
||||
list[:class:`telegram.Update`]: A list of :class:`telegram.Update`
|
||||
objects are returned.
|
||||
|
||||
Raises:
|
||||
@@ -1379,16 +1303,16 @@ class Bot(TelegramObject):
|
||||
|
||||
url = '{0}/getUpdates'.format(self.base_url)
|
||||
|
||||
data = {}
|
||||
data = {'timeout': timeout}
|
||||
|
||||
if offset:
|
||||
data['offset'] = offset
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
urlopen_timeout = timeout + network_delay
|
||||
|
||||
result = request.post(url, data, timeout=urlopen_timeout)
|
||||
|
||||
if result:
|
||||
self.logger.debug(
|
||||
@@ -1417,10 +1341,6 @@ class Bot(TelegramObject):
|
||||
Keyword Args:
|
||||
timeout (Optional[float]): If this value is specified, use it as
|
||||
the definitive timeout (in seconds) for urlopen() operations.
|
||||
network_delay (Optional[float]): If using the timeout (which is
|
||||
a `timeout` for the Telegram servers operation),
|
||||
then `network_delay` as an extra delay (in seconds) to
|
||||
compensate for network latency. Defaults to 2.
|
||||
|
||||
Returns:
|
||||
bool: On success, `True` is returned.
|
||||
@@ -1440,8 +1360,7 @@ class Bot(TelegramObject):
|
||||
data['certificate'] = certificate
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
timeout=kwargs.get('timeout'))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
"""This module contains a object that represents a Telegram InlineQuery"""
|
||||
|
||||
from telegram import TelegramObject, User
|
||||
from telegram import TelegramObject, User, Location
|
||||
|
||||
|
||||
class InlineQuery(TelegramObject):
|
||||
@@ -39,6 +39,10 @@ class InlineQuery(TelegramObject):
|
||||
from_user (:class:`telegram.User`):
|
||||
query (str):
|
||||
offset (str):
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
location (optional[:class:`telegram.Location`]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
@@ -53,6 +57,9 @@ class InlineQuery(TelegramObject):
|
||||
self.query = query
|
||||
self.offset = offset
|
||||
|
||||
# Optional
|
||||
self.location = kwargs.get('location')
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
@@ -68,6 +75,7 @@ class InlineQuery(TelegramObject):
|
||||
return None
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
|
||||
return InlineQuery(**data)
|
||||
|
||||
|
||||
+11
-7
@@ -20,17 +20,19 @@
|
||||
|
||||
"""This module contains a object that represents a Telegram InputFile."""
|
||||
|
||||
try:
|
||||
# python 3
|
||||
from email.generator import _make_boundary as choose_boundary
|
||||
except ImportError:
|
||||
# python 2
|
||||
from mimetools import choose_boundary
|
||||
|
||||
import imghdr
|
||||
import mimetypes
|
||||
import os
|
||||
import sys
|
||||
import imghdr
|
||||
|
||||
try:
|
||||
from email.generator import _make_boundary as choose_boundary
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from mimetools import choose_boundary
|
||||
from urllib2 import urlopen
|
||||
from future.moves.urllib.request import urlopen
|
||||
|
||||
from telegram import TelegramError
|
||||
|
||||
@@ -81,6 +83,8 @@ class InputFile(object):
|
||||
if 'filename' in data:
|
||||
self.filename = self.data.pop('filename')
|
||||
elif hasattr(self.input_file, 'name'):
|
||||
# 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) \
|
||||
|
||||
@@ -73,7 +73,12 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
||||
data = super(ReplyKeyboardMarkup, self).to_dict()
|
||||
|
||||
data['keyboard'] = []
|
||||
for keyboard in self.keyboard:
|
||||
data['keyboard'].append([x.to_dict() for x in keyboard])
|
||||
|
||||
for row in self.keyboard:
|
||||
r = []
|
||||
for button in row:
|
||||
if hasattr(button, 'to_dict'):
|
||||
r.append(button.to_dict()) # telegram.KeyboardButton
|
||||
else:
|
||||
r.append(button) # str
|
||||
data['keyboard'].append(r)
|
||||
return data
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
# pylint: disable=no-name-in-module,unused-import
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
@@ -25,22 +24,9 @@ import json
|
||||
import socket
|
||||
from ssl import SSLError
|
||||
|
||||
try:
|
||||
# python2
|
||||
from httplib import HTTPException
|
||||
except ImportError:
|
||||
# python3
|
||||
from http.client import HTTPException
|
||||
|
||||
try:
|
||||
# python3
|
||||
from urllib.request import urlopen, urlretrieve, Request
|
||||
from urllib.error import HTTPError, URLError
|
||||
except ImportError:
|
||||
# python2
|
||||
from urllib import urlretrieve
|
||||
from urllib2 import urlopen, Request, URLError
|
||||
from urllib2 import HTTPError
|
||||
from future.moves.http.client import HTTPException
|
||||
from future.moves.urllib.error import HTTPError, URLError
|
||||
from future.moves.urllib.request import urlopen, urlretrieve, Request
|
||||
|
||||
from telegram import (InputFile, TelegramError)
|
||||
from telegram.error import Unauthorized, NetworkError, TimedOut
|
||||
@@ -130,8 +116,7 @@ def get(url):
|
||||
@_try_except_req
|
||||
def post(url,
|
||||
data,
|
||||
timeout=None,
|
||||
network_delay=2.):
|
||||
timeout=None):
|
||||
"""Request an URL.
|
||||
Args:
|
||||
url:
|
||||
@@ -141,11 +126,6 @@ def post(url,
|
||||
timeout:
|
||||
float. If this value is specified, use it as the definitive timeout (in
|
||||
seconds) for urlopen() operations. [Optional]
|
||||
network_delay:
|
||||
float. If using the timeout specified in `data` (which is a timeout for
|
||||
the Telegram servers operation), then `network_delay` as an extra delay
|
||||
(in seconds) to compensate for network latency.
|
||||
default: 2 [Optional]
|
||||
|
||||
Notes:
|
||||
If neither `timeout` nor `data['timeout']` is specified. The underlying
|
||||
@@ -159,8 +139,6 @@ def post(url,
|
||||
|
||||
if timeout is not None:
|
||||
urlopen_kwargs['timeout'] = timeout
|
||||
elif 'timeout' in data:
|
||||
urlopen_kwargs['timeout'] = data['timeout'] + network_delay
|
||||
|
||||
if InputFile.is_inputfile(data):
|
||||
data = InputFile(data)
|
||||
|
||||
+5
-3
@@ -16,12 +16,13 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Base class for tests"""
|
||||
|
||||
import signal
|
||||
import sys
|
||||
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
|
||||
from nose.tools import make_decorator
|
||||
|
||||
sys.path.append('.')
|
||||
@@ -61,6 +62,7 @@ class BaseTest(object):
|
||||
|
||||
|
||||
class TestTimedOut(AssertionError):
|
||||
|
||||
def __init__(self, time_limit, frame):
|
||||
super(TestTimedOut, self).__init__('time_limit={0}'.format(time_limit))
|
||||
self.time_limit = time_limit
|
||||
|
||||
+31
-44
@@ -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"""
|
||||
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import io
|
||||
from datetime import datetime
|
||||
import sys
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
@@ -54,26 +55,22 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendMessage(self):
|
||||
message = self._bot.sendMessage(
|
||||
chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей')
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertTrue(isinstance(message.date, datetime))
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSilentSendMessage(self):
|
||||
message = self._bot.sendMessage(
|
||||
chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей',
|
||||
disable_notification=True)
|
||||
message = self._bot.sendMessage(chat_id=self._chat_id,
|
||||
text='Моё судно на воздушной подушке полно угрей',
|
||||
disable_notification=True)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
self.assertTrue(isinstance(message.date, datetime))
|
||||
|
||||
@flaky(3, 1)
|
||||
@@ -100,10 +97,9 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendPhoto(self):
|
||||
message = self._bot.sendPhoto(
|
||||
photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 1451)
|
||||
@@ -112,11 +108,10 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSilentSendPhoto(self):
|
||||
message = self._bot.sendPhoto(
|
||||
photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id,
|
||||
disable_notification=True)
|
||||
message = self._bot.sendPhoto(photo=open('tests/data/telegram.png', 'rb'),
|
||||
caption='testSendPhoto',
|
||||
chat_id=self._chat_id,
|
||||
disable_notification=True)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 1451)
|
||||
@@ -125,21 +120,17 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testResendPhoto(self):
|
||||
message = self._bot.sendPhoto(
|
||||
photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo='AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(
|
||||
message.photo[0].file_id,
|
||||
'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
||||
self.assertEqual(message.photo[0].file_id, 'AgADAQADyKcxGx8j9Qdp6d-gpUsw4Gja1i8ABEVJsVqQk8LfJ3wAAgI')
|
||||
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendJPGURLPhoto(self):
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 822)
|
||||
@@ -147,9 +138,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendPNGURLPhoto(self):
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.png&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 684)
|
||||
@@ -157,9 +147,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
@flaky(3, 1)
|
||||
@timeout(10)
|
||||
def testSendGIFURLPhoto(self):
|
||||
message = self._bot.sendPhoto(
|
||||
photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram',
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 684)
|
||||
@@ -169,7 +158,8 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
def testSendBufferedReaderPhoto(self):
|
||||
photo = open('tests/data/telegram.png', 'rb')
|
||||
br_photo = io.BufferedReader(io.BytesIO(photo.read()))
|
||||
message = self._bot.sendPhoto(photo=br_photo, chat_id=self._chat_id)
|
||||
message = self._bot.sendPhoto(photo=br_photo,
|
||||
chat_id=self._chat_id)
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.photo[0].file_size, 1451)
|
||||
@@ -189,8 +179,7 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(upf.photos[0][0].file_size, 12421)
|
||||
|
||||
def _test_invalid_token(self, token):
|
||||
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token',
|
||||
telegram.Bot, token)
|
||||
self.assertRaisesRegexp(telegram.error.InvalidToken, 'Invalid token', telegram.Bot, token)
|
||||
|
||||
def testInvalidToken1(self):
|
||||
self._test_invalid_token('123')
|
||||
@@ -202,14 +191,12 @@ class BotTest(BaseTest, unittest.TestCase):
|
||||
self._test_invalid_token('12:')
|
||||
|
||||
def testUnauthToken(self):
|
||||
with self.assertRaisesRegexp(telegram.error.Unauthorized,
|
||||
'Unauthorized'):
|
||||
with self.assertRaisesRegexp(telegram.error.Unauthorized, 'Unauthorized'):
|
||||
bot = telegram.Bot('1234:abcd1234')
|
||||
bot.getMe()
|
||||
|
||||
def testInvalidSrvResp(self):
|
||||
with self.assertRaisesRegexp(telegram.TelegramError,
|
||||
'Invalid server response'):
|
||||
with self.assertRaisesRegexp(telegram.TelegramError, 'Invalid server response'):
|
||||
# bypass the valid token check
|
||||
bot = telegram.Bot.__new__(telegram.Bot)
|
||||
bot.base_url = 'https://api.telegram.org/bot{0}'.format('12')
|
||||
|
||||
+3
-4
@@ -1,4 +1,4 @@
|
||||
# !/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
@@ -16,11 +16,11 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Chat"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
@@ -66,6 +66,5 @@ class ChatTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(group_chat['title'], self.title)
|
||||
self.assertEqual(group_chat['type'], self.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# !/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
@@ -16,11 +16,11 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Contact"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
@@ -65,6 +65,5 @@ class ContactTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(contact['last_name'], self.last_name)
|
||||
self.assertEqual(contact['user_id'], self.user_id)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
+3
-2
@@ -16,13 +16,14 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Emoji"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from telegram.emoji import Emoji
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
@@ -56,6 +56,11 @@ class ForceReplyTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(force_reply.force_reply, self.force_reply)
|
||||
self.assertEqual(force_reply.selective, self.selective)
|
||||
|
||||
def test_force_reply_de_json_empty(self):
|
||||
force_reply = telegram.ForceReply.de_json(None)
|
||||
|
||||
self.assertFalse(force_reply)
|
||||
|
||||
def test_force_reply_to_json(self):
|
||||
force_reply = telegram.ForceReply.de_json(self.json_dict)
|
||||
|
||||
|
||||
@@ -59,6 +59,16 @@ class InlineKeyboardButtonTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(inline_keyboard_button.switch_inline_query,
|
||||
self.switch_inline_query)
|
||||
|
||||
def test_inline_keyboard_button_de_json_empty(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(None)
|
||||
|
||||
self.assertFalse(inline_keyboard_button)
|
||||
|
||||
def test_inline_keyboard_button_de_list_empty(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_list(None)
|
||||
|
||||
self.assertFalse(inline_keyboard_button)
|
||||
|
||||
def test_inline_keyboard_button_to_json(self):
|
||||
inline_keyboard_button = telegram.InlineKeyboardButton.de_json(
|
||||
self.json_dict)
|
||||
|
||||
@@ -51,6 +51,11 @@ class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, 'Testing InlineKeyboardMarkup')
|
||||
|
||||
def test_inline_keyboard_markup_de_json_empty(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(None)
|
||||
|
||||
self.assertFalse(inline_keyboard_markup)
|
||||
|
||||
def test_inline_keyboard_markup_de_json(self):
|
||||
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
@@ -37,17 +37,20 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
user = telegram.User(1, 'First name')
|
||||
location = telegram.Location(8.8, 53.1)
|
||||
|
||||
self.id = 'id'
|
||||
self.from_user = user
|
||||
self.query = 'query text'
|
||||
self.offset = 'offset'
|
||||
self.location = location
|
||||
|
||||
self.json_dict = {
|
||||
'id': self.id,
|
||||
'from': self.from_user.to_dict(),
|
||||
'query': self.query,
|
||||
'offset': self.offset
|
||||
'offset': self.offset,
|
||||
'location': self.location.to_dict()
|
||||
}
|
||||
|
||||
def test_inlinequery_de_json(self):
|
||||
@@ -56,6 +59,8 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(inlinequery.id, self.id)
|
||||
self.assertDictEqual(inlinequery.from_user.to_dict(),
|
||||
self.from_user.to_dict())
|
||||
self.assertDictEqual(inlinequery.location.to_dict(),
|
||||
self.location.to_dict())
|
||||
self.assertEqual(inlinequery.query, self.query)
|
||||
self.assertEqual(inlinequery.offset, self.offset)
|
||||
|
||||
|
||||
@@ -29,11 +29,6 @@ if sys.version_info[0:2] == (2, 6):
|
||||
else:
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from urllib2 import urlopen, Request
|
||||
except ImportError:
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
from telegram.ext import JobQueue, Updater
|
||||
|
||||
@@ -55,6 +55,16 @@ class KeyboardButtonTest(BaseTest, unittest.TestCase):
|
||||
self.request_location)
|
||||
self.assertEqual(keyboard_button.request_contact, self.request_contact)
|
||||
|
||||
def test_keyboard_button_de_json_empty(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(None)
|
||||
|
||||
self.assertFalse(keyboard_button)
|
||||
|
||||
def test_keyboard_button_de_list_empty(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_list(None)
|
||||
|
||||
self.assertFalse(keyboard_button)
|
||||
|
||||
def test_keyboard_button_to_json(self):
|
||||
keyboard_button = telegram.KeyboardButton.de_json(self.json_dict)
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram Location"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
@@ -40,7 +40,8 @@ class LocationTest(BaseTest, unittest.TestCase):
|
||||
}
|
||||
|
||||
def test_send_location_implicit_args(self):
|
||||
message = self._bot.sendLocation(self._chat_id, self.latitude,
|
||||
message = self._bot.sendLocation(self._chat_id,
|
||||
self.latitude,
|
||||
self.longitude)
|
||||
|
||||
location = message.location
|
||||
|
||||
@@ -57,6 +57,11 @@ class ReplyKeyboardHideTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(reply_keyboard_hide.hide_keyboard, self.hide_keyboard)
|
||||
self.assertEqual(reply_keyboard_hide.selective, self.selective)
|
||||
|
||||
def test_reply_keyboard_hide_de_json_empty(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(None)
|
||||
|
||||
self.assertFalse(reply_keyboard_hide)
|
||||
|
||||
def test_reply_keyboard_hide_to_json(self):
|
||||
reply_keyboard_hide = telegram.ReplyKeyboardHide.de_json(
|
||||
self.json_dict)
|
||||
|
||||
@@ -56,6 +56,11 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(message.text,
|
||||
u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_reply_markup_empty_de_json_empty(self):
|
||||
reply_markup_empty = telegram.ReplyKeyboardMarkup.de_json(None)
|
||||
|
||||
self.assertFalse(reply_markup_empty)
|
||||
|
||||
def test_reply_keyboard_markup_de_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(
|
||||
self.json_dict)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains a object that represents Tests for Telegram
|
||||
ReplyMarkup"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0:2] == (2, 6):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
from tests.base import BaseTest
|
||||
|
||||
|
||||
class ReplyMarkupTest(BaseTest, unittest.TestCase):
|
||||
"""This object represents Tests for Telegram ReplyMarkup."""
|
||||
|
||||
def test_reply_markup_de_json_empty(self):
|
||||
reply_markup = telegram.ReplyMarkup.de_json(None)
|
||||
|
||||
self.assertFalse(reply_markup)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -53,6 +53,11 @@ class UpdateTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(update.update_id, self.update_id)
|
||||
self.assertTrue(isinstance(update.message, telegram.Message))
|
||||
|
||||
def test_update_de_json_empty(self):
|
||||
update = telegram.Update.de_json(None)
|
||||
|
||||
self.assertFalse(update)
|
||||
|
||||
def test_update_to_json(self):
|
||||
update = telegram.Update.de_json(self.json_dict)
|
||||
|
||||
|
||||
+8
-9
@@ -1,4 +1,4 @@
|
||||
# !/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
@@ -16,11 +16,11 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents Tests for Telegram User"""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
sys.path.append('.')
|
||||
|
||||
import telegram
|
||||
@@ -59,7 +59,7 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||
def test_user_de_json_without_username(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del (json_dict['username'])
|
||||
del(json_dict['username'])
|
||||
|
||||
user = telegram.User.de_json(self.json_dict)
|
||||
|
||||
@@ -68,14 +68,14 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(user.last_name, self.last_name)
|
||||
self.assertEqual(user.type, self.type)
|
||||
|
||||
self.assertEqual(user.name,
|
||||
'%s %s' % (self.first_name, self.last_name))
|
||||
self.assertEqual(user.name, '%s %s' % (self.first_name, self.last_name))
|
||||
|
||||
|
||||
def test_user_de_json_without_username_and_lastname(self):
|
||||
json_dict = self.json_dict
|
||||
|
||||
del (json_dict['username'])
|
||||
del (json_dict['last_name'])
|
||||
del(json_dict['username'])
|
||||
del(json_dict['last_name'])
|
||||
|
||||
user = telegram.User.de_json(self.json_dict)
|
||||
|
||||
@@ -99,6 +99,5 @@ class UserTest(BaseTest, unittest.TestCase):
|
||||
self.assertEqual(user['username'], self.username)
|
||||
self.assertEqual(user['type'], self.type)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user