mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-16 12:25:45 +01:00
Merge remote-tracking branch 'origin/master' into V12
This commit is contained in:
commit
f252436cd4
30 changed files with 128 additions and 106 deletions
|
@ -29,6 +29,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
|||
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
|
||||
- `Eugene Lisitsky <https://github.com/lisitsky>`_
|
||||
- `Eugenio Panadero <https://github.com/azogue>`_
|
||||
- `Evan Haberecht <https://github.com/habereet>`_
|
||||
- `evgfilim1 <https://github.com/evgfilim1>`_
|
||||
- `franciscod <https://github.com/franciscod>`_
|
||||
- `Hugo Damer <https://github.com/HakimusGIT>`_
|
||||
|
|
|
@ -46,6 +46,10 @@ We have a vibrant community of developers helping each other in our `Telegram gr
|
|||
:target: http://isitmaintained.com/project/python-telegram-bot/python-telegram-bot
|
||||
:alt: Median time to resolve an issue
|
||||
|
||||
.. image:: https://api.codacy.com/project/badge/Grade/99d901eaa09b44b4819aec05c330c968
|
||||
:target: https://www.codacy.com/app/python-telegram-bot/python-telegram-bot?utm_source=github.com&utm_medium=referral&utm_content=python-telegram-bot/python-telegram-bot&utm_campaign=Badge_Grade
|
||||
:alt: Code quality
|
||||
|
||||
.. image:: https://img.shields.io/badge/Telegram-Group-blue.svg
|
||||
:target: https://telegram.me/pythontelegrambotgroup
|
||||
:alt: Telegram Group
|
||||
|
|
|
@ -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-2018
|
||||
|
|
|
@ -369,7 +369,7 @@ class Bot(TelegramObject):
|
|||
Internet, or upload a new photo using multipart/form-data. Lastly you can pass
|
||||
an existing :class:`telegram.PhotoSize` object to send.
|
||||
caption (:obj:`str`, optional): Photo caption (may also be used when resending photos
|
||||
by file_id), 0-200 characters.
|
||||
by file_id), 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
|
||||
show bold, italic, fixed-width text or inline URLs in the media caption. See the
|
||||
constants in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -442,7 +442,7 @@ class Bot(TelegramObject):
|
|||
(recommended), pass an HTTP URL as a String for Telegram to get an audio file from
|
||||
the Internet, or upload a new one using multipart/form-data. Lastly you can pass
|
||||
an existing :class:`telegram.Audio` object to send.
|
||||
caption (:obj:`str`, optional): Audio caption, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Audio caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
|
||||
show bold, italic, fixed-width text or inline URLs in the media caption. See the
|
||||
constants in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -527,7 +527,7 @@ class Bot(TelegramObject):
|
|||
filename (:obj:`str`, optional): File name that shows in telegram message (it is useful
|
||||
when you send file generated by temp module, for example). Undocumented.
|
||||
caption (:obj:`str`, optional): Document caption (may also be used when resending
|
||||
documents by file_id), 0-200 characters.
|
||||
documents by file_id), 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
|
||||
show bold, italic, fixed-width text or inline URLs in the media caption. See the
|
||||
constants in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -661,7 +661,7 @@ class Bot(TelegramObject):
|
|||
width (:obj:`int`, optional): Video width.
|
||||
height (:obj:`int`, optional): Video height.
|
||||
caption (:obj:`str`, optional): Video caption (may also be used when resending videos
|
||||
by file_id), 0-200 characters.
|
||||
by file_id), 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
|
||||
show bold, italic, fixed-width text or inline URLs in the media caption. See the
|
||||
constants in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -821,7 +821,7 @@ class Bot(TelegramObject):
|
|||
A thumbnail's width and height should not exceed 90. Ignored if the file is not
|
||||
is passed as a string or file_id.
|
||||
caption (:obj:`str`, optional): Animation caption (may also be used when resending
|
||||
animations by file_id), 0-200 characters.
|
||||
animations by file_id), 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
|
||||
show bold, italic, fixed-width text or inline URLs in the media caption. See the
|
||||
constants in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -898,7 +898,7 @@ class Bot(TelegramObject):
|
|||
(recommended), pass an HTTP URL as a String for Telegram to get an voice file from
|
||||
the Internet, or upload a new one using multipart/form-data. Lastly you can pass
|
||||
an existing :class:`telegram.Voice` object to send.
|
||||
caption (:obj:`str`, optional): Voice message caption, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Voice message caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to
|
||||
show bold, italic, fixed-width text or inline URLs in the media caption. See the
|
||||
constants in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -21,7 +21,7 @@ The following constants were extracted from the
|
|||
|
||||
Attributes:
|
||||
MAX_MESSAGE_LENGTH (:obj:`int`): 4096
|
||||
MAX_CAPTION_LENGTH (:obj:`int`): 200
|
||||
MAX_CAPTION_LENGTH (:obj:`int`): 1024
|
||||
SUPPORTED_WEBHOOK_PORTS (List[:obj:`int`]): [443, 80, 88, 8443]
|
||||
MAX_FILESIZE_DOWNLOAD (:obj:`int`): In bytes (20MB)
|
||||
MAX_FILESIZE_UPLOAD (:obj:`int`): In bytes (50MB)
|
||||
|
@ -40,7 +40,7 @@ Attributes:
|
|||
"""
|
||||
|
||||
MAX_MESSAGE_LENGTH = 4096
|
||||
MAX_CAPTION_LENGTH = 200
|
||||
MAX_CAPTION_LENGTH = 1024
|
||||
|
||||
# constants above this line are tested
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ class Unauthorized(TelegramError):
|
|||
|
||||
|
||||
class InvalidToken(TelegramError):
|
||||
|
||||
def __init__(self):
|
||||
super(InvalidToken, self).__init__('Invalid token')
|
||||
|
||||
|
@ -71,7 +70,6 @@ class BadRequest(NetworkError):
|
|||
|
||||
|
||||
class TimedOut(NetworkError):
|
||||
|
||||
def __init__(self):
|
||||
super(TimedOut, self).__init__('Timed out')
|
||||
|
||||
|
@ -100,3 +98,16 @@ class RetryAfter(TelegramError):
|
|||
super(RetryAfter,
|
||||
self).__init__('Flood control exceeded. Retry in {} seconds'.format(retry_after))
|
||||
self.retry_after = float(retry_after)
|
||||
|
||||
|
||||
class Conflict(TelegramError):
|
||||
"""
|
||||
Raised when a long poll or webhook conflicts with another one.
|
||||
|
||||
Args:
|
||||
msg (:obj:`str`): The message from telegrams server.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, msg):
|
||||
super(Conflict, self).__init__(msg)
|
||||
|
|
|
@ -345,11 +345,10 @@ class ConversationHandler(Handler):
|
|||
def update_state(self, new_state, key):
|
||||
if new_state == self.END:
|
||||
if key in self.conversations:
|
||||
# If there is no key in conversations, nothing is done.
|
||||
del self.conversations[key]
|
||||
if self.persistent:
|
||||
self.persistence.update_conversation(self.name, key, None)
|
||||
else:
|
||||
pass
|
||||
|
||||
elif isinstance(new_state, Promise):
|
||||
self.conversations[key] = (self.conversations.get(key), new_state)
|
||||
|
|
|
@ -247,7 +247,7 @@ class MessageQueue(object):
|
|||
is_group_msg (:obj:`bool`, optional): Defines whether ``promise`` would be processed in
|
||||
group*+*all* ``DelayQueue``s (if set to ``True``), or only through *all*
|
||||
``DelayQueue`` (if set to ``False``), resulting in needed delays to avoid
|
||||
hitting specified limits. Defaults to ``True``.
|
||||
hitting specified limits. Defaults to ``False``.
|
||||
|
||||
Notes:
|
||||
Method is designed to accept ``telegram.utils.promise.Promise`` as ``promise``
|
||||
|
|
|
@ -44,7 +44,7 @@ class InputMediaAnimation(InputMedia):
|
|||
file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
|
||||
A thumbnail's width and height should not exceed 90. Ignored if the file is not
|
||||
is passed as a string or file_id.
|
||||
caption (:obj:`str`): Optional. Caption of the animation to be sent, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption of the animation to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -61,7 +61,7 @@ class InputMediaAnimation(InputMedia):
|
|||
file sent. The thumbnail should be in JPEG format and less than 200 kB in size.
|
||||
A thumbnail's width and height should not exceed 90. Ignored if the file is not
|
||||
is passed as a string or file_id.
|
||||
caption (:obj:`str`, optional): Caption of the animation to be sent, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption of the animation to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -114,7 +114,7 @@ class InputMediaPhoto(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the
|
||||
Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the
|
||||
Internet. Lastly you can pass an existing :class:`telegram.PhotoSize` object to send.
|
||||
caption (:obj:`str`): Optional. Caption of the photo to be sent, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption of the photo to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -123,7 +123,7 @@ class InputMediaPhoto(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the
|
||||
Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the
|
||||
Internet. Lastly you can pass an existing :class:`telegram.PhotoSize` object to send.
|
||||
caption (:obj:`str`, optional ): Caption of the photo to be sent, 0-200 characters.
|
||||
caption (:obj:`str`, optional ): Caption of the photo to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -153,7 +153,7 @@ class InputMediaVideo(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the Telegram
|
||||
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
|
||||
Lastly you can pass an existing :class:`telegram.Video` object to send.
|
||||
caption (:obj:`str`): Optional. Caption of the video to be sent, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption of the video to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -171,7 +171,7 @@ class InputMediaVideo(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the Telegram
|
||||
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
|
||||
Lastly you can pass an existing :class:`telegram.Video` object to send.
|
||||
caption (:obj:`str`, optional): Caption of the video to be sent, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption of the video to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -232,7 +232,7 @@ class InputMediaAudio(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the Telegram
|
||||
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
|
||||
Lastly you can pass an existing :class:`telegram.Audio` object to send.
|
||||
caption (:obj:`str`): Optional. Caption of the audio to be sent, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption of the audio to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -249,7 +249,7 @@ class InputMediaAudio(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the Telegram
|
||||
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
|
||||
Lastly you can pass an existing :class:`telegram.Document` object to send.
|
||||
caption (:obj:`str`, optional): Caption of the audio to be sent, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption of the audio to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -307,7 +307,7 @@ class InputMediaDocument(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the Telegram
|
||||
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
|
||||
Lastly you can pass an existing :class:`telegram.Document` object to send.
|
||||
caption (:obj:`str`): Optional. Caption of the document to be sent, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption of the document to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -320,7 +320,7 @@ class InputMediaDocument(InputMedia):
|
|||
media (:obj:`str`): File to send. Pass a file_id to send a file that exists on the Telegram
|
||||
servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet.
|
||||
Lastly you can pass an existing :class:`telegram.Document` object to send.
|
||||
caption (:obj:`str`, optional): Caption of the document to be sent, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption of the document to be sent, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -31,7 +31,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
|||
type (:obj:`str`): 'audio'.
|
||||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
audio_file_id (:obj:`str`): A valid file identifier for the audio file.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -43,7 +43,7 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
|
|||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
audio_file_id (:obj:`str`): A valid file identifier for the audio file.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -33,7 +33,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
|||
title (:obj:`str`): Title for the result.
|
||||
document_file_id (:obj:`str`): A valid file identifier for the file.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -47,7 +47,7 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
|
|||
title (:obj:`str`): Title for the result.
|
||||
document_file_id (:obj:`str`): A valid file identifier for the file.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -33,7 +33,7 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
gif_file_id (:obj:`str`): A valid file identifier for the GIF file.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -46,7 +46,7 @@ class InlineQueryResultCachedGif(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
gif_file_id (:obj:`str`): A valid file identifier for the GIF file.
|
||||
title (:obj:`str`, optional): Title for the result.caption (:obj:`str`, optional):
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -33,7 +33,7 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
mpeg4_file_id (:obj:`str`): A valid file identifier for the MP4 file.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -46,7 +46,7 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
mpeg4_file_id (:obj:`str`): A valid file identifier for the MP4 file.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -34,7 +34,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
|||
photo_file_id (:obj:`str`): A valid file identifier of the photo.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -48,7 +48,7 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
|
|||
photo_file_id (:obj:`str`): A valid file identifier of the photo.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -34,7 +34,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
|||
video_file_id (:obj:`str`): A valid file identifier for the video file.
|
||||
title (:obj:`str`): Title for the result.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -48,7 +48,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
|
|||
video_file_id (:obj:`str`): A valid file identifier for the video file.
|
||||
title (:obj:`str`): Title for the result.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -32,7 +32,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
voice_file_id (:obj:`str`): A valid file identifier for the voice message.
|
||||
title (:obj:`str`): Voice message title.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -45,7 +45,7 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
voice_file_id (:obj:`str`): A valid file identifier for the voice message.
|
||||
title (:obj:`str`): Voice message title.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -32,7 +32,7 @@ class InlineQueryResultDocument(InlineQueryResult):
|
|||
type (:obj:`str`): 'document'.
|
||||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -51,7 +51,7 @@ class InlineQueryResultDocument(InlineQueryResult):
|
|||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -36,7 +36,7 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
gif_duration (:obj:`int`): Optional. Duration of the GIF.
|
||||
thumb_url (:obj:`str`): URL of the static thumbnail for the result (jpeg or gif).
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -53,7 +53,7 @@ class InlineQueryResultGif(InlineQueryResult):
|
|||
gif_duration (:obj:`int`, optional): Duration of the GIF
|
||||
thumb_url (:obj:`str`): URL of the static thumbnail for the result (jpeg or gif).
|
||||
title (:obj:`str`, optional): Title for the result.caption (:obj:`str`, optional):
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -37,7 +37,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
mpeg4_duration (:obj:`int`): Optional. Video duration.
|
||||
thumb_url (:obj:`str`): URL of the static thumbnail (jpeg or gif) for the result.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -54,7 +54,7 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
|||
mpeg4_duration (:obj:`int`, optional): Video duration.
|
||||
thumb_url (:obj:`str`): URL of the static thumbnail (jpeg or gif) for the result.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -37,7 +37,7 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
photo_height (:obj:`int`): Optional. Height of the photo.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -55,7 +55,7 @@ class InlineQueryResultPhoto(InlineQueryResult):
|
|||
photo_height (:obj:`int`, optional): Height of the photo.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -35,7 +35,7 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4".
|
||||
thumb_url (:obj:`str`): URL of the thumbnail (jpeg only) for the video.
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -54,7 +54,7 @@ class InlineQueryResultVideo(InlineQueryResult):
|
|||
mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4".
|
||||
thumb_url (:obj:`str`): URL of the thumbnail (jpeg only) for the video.
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -33,7 +33,7 @@ class InlineQueryResultVoice(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
voice_url (:obj:`str`): A valid URL for the voice recording.
|
||||
title (:obj:`str`): Voice message title.
|
||||
caption (:obj:`str`): Optional. Caption, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`): Optional. Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
@ -47,7 +47,7 @@ class InlineQueryResultVoice(InlineQueryResult):
|
|||
id (:obj:`str`): Unique identifier for this result, 1-64 bytes.
|
||||
voice_url (:obj:`str`): A valid URL for the voice recording.
|
||||
title (:obj:`str`): Voice message title.
|
||||
caption (:obj:`str`, optional): Caption, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption, 0-1024 characters.
|
||||
parse_mode (:obj:`str`, optional): Send Markdown or HTML, if you want Telegram apps to show
|
||||
bold, italic, fixed-width text or inline URLs in the media caption.. See the constants
|
||||
in :class:`telegram.ParseMode` for the available modes.
|
||||
|
|
|
@ -73,7 +73,8 @@ class Message(TelegramObject):
|
|||
video_note (:class:`telegram.VideoNote`): Optional. Information about the video message.
|
||||
new_chat_members (List[:class:`telegram.User`]): Optional. Information about new members to
|
||||
the chat. (the bot itself may be one of these members).
|
||||
caption (:obj:`str`): Optional. Caption for the document, photo or video, 0-200 characters.
|
||||
caption (:obj:`str`): Optional. Caption for the document, photo or video, 0-1024
|
||||
characters.
|
||||
contact (:class:`telegram.Contact`): Optional. Information about the contact.
|
||||
location (:class:`telegram.Location`): Optional. Information about the location.
|
||||
venue (:class:`telegram.Venue`): Optional. Information about the venue.
|
||||
|
@ -154,7 +155,8 @@ class Message(TelegramObject):
|
|||
new_chat_members (List[:class:`telegram.User`], optional): New members that were added to
|
||||
the group or supergroup and information about them (the bot itself may be one of these
|
||||
members).
|
||||
caption (:obj:`str`, optional): Caption for the document, photo or video, 0-200 characters.
|
||||
caption (:obj:`str`, optional): Caption for the document, photo or video, 0-1024
|
||||
characters.
|
||||
contact (:class:`telegram.Contact`, optional): Message is a shared contact, information
|
||||
about the contact.
|
||||
location (:class:`telegram.Location`, optional): Message is a shared location, information
|
||||
|
|
|
@ -44,7 +44,7 @@ except ImportError: # pragma: no cover
|
|||
|
||||
from telegram import (InputFile, TelegramError, InputMedia)
|
||||
from telegram.error import (Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated,
|
||||
RetryAfter, InvalidToken)
|
||||
RetryAfter, InvalidToken, Conflict)
|
||||
|
||||
|
||||
def _render_part(self, name, value):
|
||||
|
@ -238,6 +238,8 @@ class Request(object):
|
|||
raise BadRequest(message)
|
||||
elif resp.status == 404:
|
||||
raise InvalidToken()
|
||||
elif resp.status == 409:
|
||||
raise Conflict(message)
|
||||
elif resp.status == 413:
|
||||
raise NetworkError('File too large. Check telegram api limits '
|
||||
'https://core.telegram.org/bots/api#senddocument')
|
||||
|
|
|
@ -18,26 +18,37 @@
|
|||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""Provide a bot to tests"""
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
|
||||
from platform import python_implementation
|
||||
|
||||
# Provide some public fallbacks so it's easy for contributors to run tests on their local machine
|
||||
FALLBACKS = {
|
||||
'token': '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0',
|
||||
'payment_provider_token': '284685063:TEST:ZGJlMmQxZDI3ZTc3',
|
||||
'chat_id': '12173560',
|
||||
'group_id': '-49740850',
|
||||
'channel_id': '@pythontelegrambottests'
|
||||
}
|
||||
# These bots are only able to talk in our test chats, so they are quite useless for other
|
||||
# purposes than testing.
|
||||
FALLBACKS = [
|
||||
{
|
||||
'token': '579694714:AAHRLL5zBVy4Blx2jRFKe1HlfnXCg08WuLY',
|
||||
'payment_provider_token': '284685063:TEST:NjQ0NjZlNzI5YjJi',
|
||||
'chat_id': '675666224',
|
||||
'group_id': '-269513406',
|
||||
'channel_id': '@pythontelegrambottests'
|
||||
}, {
|
||||
'token': '558194066:AAEEylntuKSLXj9odiv3TnX7Z5KY2J3zY3M',
|
||||
'payment_provider_token': '284685063:TEST:YjEwODQwMTFmNDcy',
|
||||
'chat_id': '675666224',
|
||||
'group_id': '-269513406',
|
||||
'channel_id': '@pythontelegrambottests'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def get(name, fallback):
|
||||
full_name = '{0}-{1}-{2[0]}{2[1]}'.format(name, python_implementation(),
|
||||
full_name = '{0}_{1}_{2[0]}{2[1]}'.format(name, python_implementation(),
|
||||
sys.version_info).upper()
|
||||
# First try fullnames such as
|
||||
# TOKEN-CPYTHON-33
|
||||
# CHAT_ID-PYPY-27
|
||||
# First try full_names such as
|
||||
# TOKEN_CPYTHON_33
|
||||
# CHAT_ID_PYPY_27
|
||||
val = os.getenv(full_name)
|
||||
if val:
|
||||
return val
|
||||
|
@ -52,4 +63,4 @@ def get(name, fallback):
|
|||
|
||||
|
||||
def get_bot():
|
||||
return {k: get(k, v) for k, v in FALLBACKS.items()}
|
||||
return {k: get(k, v) for k, v in random.choice(FALLBACKS).items()}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
import os
|
||||
import time
|
||||
from datetime import datetime
|
||||
from platform import python_implementation
|
||||
|
@ -146,16 +145,16 @@ class TestBot(object):
|
|||
assert message.contact.first_name == first_name
|
||||
assert message.contact.last_name == last_name
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (''yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_send_game(self, bot, chat_id):
|
||||
game_short_name = 'python_telegram_bot_test_game'
|
||||
game_short_name = 'test_game'
|
||||
message = bot.send_game(chat_id, game_short_name)
|
||||
|
||||
assert message.game
|
||||
assert message.game.description == 'This is a test game for python-telegram-bot.'
|
||||
assert message.game.animation.file_id == 'CgADAQADKwIAAvjAuQABozciVqhFDO0C'
|
||||
assert message.game.description == ('A no-op test game, for python-telegram-bot '
|
||||
'bot framework testing.')
|
||||
assert message.game.animation.file_id != ''
|
||||
assert message.game.photo[0].file_size == 851
|
||||
|
||||
@flaky(3, 1)
|
||||
|
@ -190,18 +189,16 @@ class TestBot(object):
|
|||
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_get_user_profile_photos(self, bot):
|
||||
chat_id = 12173560 # hardcoded Leandro's chat_id
|
||||
def test_get_user_profile_photos(self, bot, chat_id):
|
||||
user_profile_photos = bot.get_user_profile_photos(chat_id)
|
||||
|
||||
assert user_profile_photos.photos[0][0].file_size == 9999
|
||||
assert user_profile_photos.photos[0][0].file_size == 5403
|
||||
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_get_one_user_profile_photo(self, bot):
|
||||
chat_id = 12173560 # hardcoded Leandro's chat_id
|
||||
def test_get_one_user_profile_photo(self, bot, chat_id):
|
||||
user_profile_photos = bot.get_user_profile_photos(chat_id, offset=0, limit=1)
|
||||
assert user_profile_photos.photos[0][0].file_size == 9999
|
||||
assert user_profile_photos.photos[0][0].file_size == 5403
|
||||
|
||||
# get_file is tested multiple times in the test_*media* modules.
|
||||
|
||||
|
@ -275,7 +272,6 @@ class TestBot(object):
|
|||
|
||||
assert message.caption == 'new caption'
|
||||
|
||||
@pytest.mark.xfail(raises=TelegramError) # TODO: remove when #744 is merged
|
||||
def test_edit_message_caption_without_required(self, bot):
|
||||
with pytest.raises(ValueError, match='Both chat_id and message_id are required when'):
|
||||
bot.edit_message_caption(caption='new_caption')
|
||||
|
@ -294,7 +290,6 @@ class TestBot(object):
|
|||
|
||||
assert message is not True
|
||||
|
||||
@pytest.mark.xfail(raises=TelegramError) # TODO: remove when #744 is merged
|
||||
def test_edit_message_reply_markup_without_required(self, bot):
|
||||
new_markup = InlineKeyboardMarkup([[InlineKeyboardButton(text='test', callback_data='1')]])
|
||||
with pytest.raises(ValueError, match='Both chat_id and message_id are required when'):
|
||||
|
@ -349,7 +344,7 @@ class TestBot(object):
|
|||
chat = bot.get_chat(group_id)
|
||||
|
||||
assert chat.type == 'group'
|
||||
assert chat.title == '>>> telegram.Bot() - Developers'
|
||||
assert chat.title == '>>> telegram.Bot(test)'
|
||||
assert chat.id == int(group_id)
|
||||
|
||||
@flaky(3, 1)
|
||||
|
@ -370,11 +365,12 @@ class TestBot(object):
|
|||
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_get_chat_member(self, bot, channel_id):
|
||||
chat_member = bot.get_chat_member(channel_id, 103246792) # Eldin
|
||||
def test_get_chat_member(self, bot, channel_id, chat_id):
|
||||
chat_member = bot.get_chat_member(channel_id, chat_id)
|
||||
|
||||
assert chat_member.status == 'administrator'
|
||||
assert chat_member.user.username == 'EchteEldin'
|
||||
assert chat_member.user.first_name == 'PTB'
|
||||
assert chat_member.user.last_name == 'Test user'
|
||||
|
||||
@pytest.mark.skip(reason="Not implemented yet.")
|
||||
def test_set_chat_sticker_set(self):
|
||||
|
@ -384,12 +380,11 @@ class TestBot(object):
|
|||
def test_delete_chat_sticker_set(self):
|
||||
pass
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_set_game_score_1(self, bot, chat_id):
|
||||
# NOTE: numbering of methods assures proper order between test_set_game_scoreX methods
|
||||
game_short_name = 'python_telegram_bot_test_game'
|
||||
game_short_name = 'test_game'
|
||||
game = bot.send_game(chat_id, game_short_name)
|
||||
|
||||
message = bot.set_game_score(
|
||||
|
@ -403,12 +398,11 @@ class TestBot(object):
|
|||
assert message.game.photo[0].file_size == game.game.photo[0].file_size
|
||||
assert message.game.text != game.game.text
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_set_game_score_2(self, bot, chat_id):
|
||||
# NOTE: numbering of methods assures proper order between test_set_game_scoreX methods
|
||||
game_short_name = 'python_telegram_bot_test_game'
|
||||
game_short_name = 'test_game'
|
||||
game = bot.send_game(chat_id, game_short_name)
|
||||
|
||||
score = int(BASE_TIME) - HIGHSCORE_DELTA + 1
|
||||
|
@ -425,12 +419,11 @@ class TestBot(object):
|
|||
assert message.game.photo[0].file_size == game.game.photo[0].file_size
|
||||
assert message.game.text == game.game.text
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_set_game_score_3(self, bot, chat_id):
|
||||
# NOTE: numbering of methods assures proper order between test_set_game_scoreX methods
|
||||
game_short_name = 'python_telegram_bot_test_game'
|
||||
game_short_name = 'test_game'
|
||||
game = bot.send_game(chat_id, game_short_name)
|
||||
|
||||
score = int(BASE_TIME) - HIGHSCORE_DELTA - 1
|
||||
|
@ -442,12 +435,11 @@ class TestBot(object):
|
|||
chat_id=game.chat_id,
|
||||
message_id=game.message_id)
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_set_game_score_4(self, bot, chat_id):
|
||||
# NOTE: numbering of methods assures proper order between test_set_game_scoreX methods
|
||||
game_short_name = 'python_telegram_bot_test_game'
|
||||
game_short_name = 'test_game'
|
||||
game = bot.send_game(chat_id, game_short_name)
|
||||
|
||||
score = int(BASE_TIME) - HIGHSCORE_DELTA - 2
|
||||
|
@ -468,24 +460,22 @@ class TestBot(object):
|
|||
game2 = bot.send_game(chat_id, game_short_name)
|
||||
assert str(score) in game2.game.text
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_set_game_score_too_low_score(self, bot, chat_id):
|
||||
# We need a game to set the score for
|
||||
game_short_name = 'python_telegram_bot_test_game'
|
||||
game_short_name = 'test_game'
|
||||
game = bot.send_game(chat_id, game_short_name)
|
||||
|
||||
with pytest.raises(BadRequest):
|
||||
bot.set_game_score(user_id=chat_id, score=100,
|
||||
chat_id=game.chat_id, message_id=game.message_id)
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No game made for Appveyor bot (yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_get_game_high_scores(self, bot, chat_id):
|
||||
# We need a game to get the scores for
|
||||
game_short_name = 'python_telegram_bot_test_game'
|
||||
game_short_name = 'test_game'
|
||||
game = bot.send_game(chat_id, game_short_name)
|
||||
high_scores = bot.get_game_high_scores(chat_id, game.chat_id, game.message_id)
|
||||
# We assume that the other game score tests ran within 20 sec
|
||||
|
@ -572,7 +562,7 @@ class TestBot(object):
|
|||
@pytest.mark.timeout(10)
|
||||
def test_promote_chat_member(self, bot, channel_id):
|
||||
# TODO: Add bot to supergroup so this can be tested properly / give bot perms
|
||||
with pytest.raises(BadRequest, match='Chat_admin_required'):
|
||||
with pytest.raises(BadRequest, match='Not enough rights'):
|
||||
assert bot.promote_chat_member(channel_id,
|
||||
95205500,
|
||||
can_change_info=True,
|
||||
|
|
|
@ -29,8 +29,8 @@ class TestConstants(object):
|
|||
def test_max_message_length(self, bot, chat_id):
|
||||
bot.send_message(chat_id=chat_id, text='a' * constants.MAX_MESSAGE_LENGTH)
|
||||
|
||||
with pytest.raises(BadRequest, message='MAX_MESSAGE_LENGTH is no longer valid',
|
||||
match='too long'):
|
||||
with pytest.raises(BadRequest, match='Message is too long',
|
||||
message='MAX_MESSAGE_LENGTH is no longer valid'):
|
||||
bot.send_message(chat_id=chat_id, text='a' * (constants.MAX_MESSAGE_LENGTH + 1))
|
||||
|
||||
@flaky(3, 1)
|
||||
|
@ -42,6 +42,7 @@ class TestConstants(object):
|
|||
assert good_msg.caption == good_caption
|
||||
|
||||
bad_caption = good_caption + 'Z'
|
||||
with pytest.raises(BadRequest, message="Media_caption_too_long"):
|
||||
with pytest.raises(BadRequest, match="Media_caption_too_long",
|
||||
message='MAX_CAPTION_LENGTH is no longer valid'):
|
||||
with open('tests/data/telegram.png', 'rb') as f:
|
||||
bot.send_photo(photo=f, caption=bad_caption, chat_id=chat_id)
|
||||
|
|
|
@ -20,7 +20,7 @@ import pytest
|
|||
|
||||
from telegram import TelegramError
|
||||
from telegram.error import Unauthorized, InvalidToken, NetworkError, BadRequest, TimedOut, \
|
||||
ChatMigrated, RetryAfter
|
||||
ChatMigrated, RetryAfter, Conflict
|
||||
|
||||
|
||||
class TestErrors(object):
|
||||
|
@ -83,3 +83,7 @@ class TestErrors(object):
|
|||
def test_retry_after(self):
|
||||
with pytest.raises(RetryAfter, match="Flood control exceeded. Retry in 12 seconds"):
|
||||
raise RetryAfter(12)
|
||||
|
||||
def test_conflict(self):
|
||||
with pytest.raises(Conflict, match='Something something.'):
|
||||
raise Conflict('Something something.')
|
||||
|
|
|
@ -243,7 +243,6 @@ class TestStickerSet(object):
|
|||
assert sticker_set.contains_masks == self.contains_masks
|
||||
assert sticker_set.stickers == self.stickers
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
|
||||
def test_sticker_set_to_dict(self, sticker_set):
|
||||
sticker_set_dict = sticker_set.to_dict()
|
||||
|
||||
|
@ -253,23 +252,20 @@ class TestStickerSet(object):
|
|||
assert sticker_set_dict['contains_masks'] == sticker_set.contains_masks
|
||||
assert sticker_set_dict['stickers'][0] == sticker_set.stickers[0].to_dict()
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_bot_methods_1(self, bot, sticker_set):
|
||||
def test_bot_methods_1(self, bot, chat_id, sticker_set):
|
||||
with open('tests/data/telegram_sticker.png', 'rb') as f:
|
||||
file = bot.upload_sticker_file(95205500, f)
|
||||
assert file
|
||||
assert bot.add_sticker_to_set(95205500, sticker_set.name, file.file_id, '😄')
|
||||
assert bot.add_sticker_to_set(chat_id, sticker_set.name, file.file_id, '😄')
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
|
||||
@flaky(3, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_bot_methods_2(self, bot, sticker_set):
|
||||
file_id = sticker_set.stickers[0].file_id
|
||||
assert bot.set_sticker_position_in_set(file_id, 1)
|
||||
|
||||
@pytest.mark.skipif(os.getenv('APPVEYOR'), reason='No Sticker(set) for Appveyor bot (''yet)')
|
||||
@flaky(10, 1)
|
||||
@pytest.mark.timeout(10)
|
||||
def test_bot_methods_3(self, bot, sticker_set):
|
||||
|
|
|
@ -105,7 +105,8 @@ class TestUpdater(object):
|
|||
updater.start_polling(0.01)
|
||||
assert self.err_handler_called.wait(1) is not True
|
||||
|
||||
# NOTE: This test might hit a race condition and fail (though the 0.5 seconds delay above
|
||||
sleep(1)
|
||||
# NOTE: This test might hit a race condition and fail (though the 1 seconds delay above
|
||||
# should work around it).
|
||||
# NOTE: Checking Updater.running is problematic because it is not set to False when there's
|
||||
# an unhandled exception.
|
||||
|
|
Loading…
Add table
Reference in a new issue