2017-08-11 23:58:41 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2024-02-19 20:06:25 +01:00
|
|
|
# Copyright (C) 2015-2024
|
2017-08-11 23:58:41 +02:00
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser Public License
|
|
|
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
2022-04-24 12:38:09 +02:00
|
|
|
import asyncio
|
2019-10-12 15:11:09 +02:00
|
|
|
import datetime
|
2023-09-15 21:33:42 +02:00
|
|
|
import logging
|
2022-05-05 09:27:54 +02:00
|
|
|
import sys
|
2023-02-22 20:19:46 +01:00
|
|
|
from typing import Dict, List
|
2023-07-03 10:06:16 +02:00
|
|
|
from uuid import uuid4
|
2017-08-11 23:58:41 +02:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2019-11-15 21:51:22 +01:00
|
|
|
from telegram import (
|
|
|
|
CallbackQuery,
|
2022-05-05 09:27:54 +02:00
|
|
|
Chat,
|
2019-11-15 21:51:22 +01:00
|
|
|
ChosenInlineResult,
|
2022-05-05 09:27:54 +02:00
|
|
|
InlineQuery,
|
|
|
|
Message,
|
|
|
|
PreCheckoutQuery,
|
|
|
|
ShippingQuery,
|
|
|
|
Update,
|
|
|
|
User,
|
2019-11-15 21:51:22 +01:00
|
|
|
)
|
2023-02-22 20:19:46 +01:00
|
|
|
from telegram.ext import ApplicationBuilder, Defaults, Updater
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram.ext.filters import MessageFilter, UpdateFilter
|
2023-02-22 20:19:46 +01:00
|
|
|
from tests.auxil.build_messages import DATE
|
|
|
|
from tests.auxil.ci_bots import BOT_INFO_PROVIDER
|
|
|
|
from tests.auxil.constants import PRIVATE_KEY
|
2023-09-15 21:33:42 +02:00
|
|
|
from tests.auxil.envvars import RUN_TEST_OFFICIAL, TEST_WITH_OPT_DEPS
|
2023-02-22 20:19:46 +01:00
|
|
|
from tests.auxil.files import data_file
|
|
|
|
from tests.auxil.networking import NonchalantHttpxRequest
|
|
|
|
from tests.auxil.pytest_classes import PytestApplication, PytestBot, make_bot
|
|
|
|
from tests.auxil.timezones import BasicTimezone
|
2023-02-11 10:45:17 +01:00
|
|
|
|
2023-02-22 20:19:46 +01:00
|
|
|
if TEST_WITH_OPT_DEPS:
|
|
|
|
import pytz
|
2017-08-11 23:58:41 +02:00
|
|
|
|
2021-02-13 22:07:37 +01:00
|
|
|
|
2023-09-15 21:33:42 +02:00
|
|
|
# Don't collect `test_official.py` on Python 3.10- since it uses newer features like X | Y syntax.
|
|
|
|
# Docs: https://docs.pytest.org/en/7.1.x/example/pythoncollection.html#customizing-test-collection
|
|
|
|
collect_ignore = []
|
|
|
|
if sys.version_info < (3, 10):
|
|
|
|
if RUN_TEST_OFFICIAL:
|
|
|
|
logging.warning("Skipping test_official.py since it requires Python 3.10+")
|
2024-02-09 18:12:13 +01:00
|
|
|
collect_ignore_glob = ["test_official/*.py"]
|
2023-09-15 21:33:42 +02:00
|
|
|
|
|
|
|
|
2021-02-13 22:07:37 +01:00
|
|
|
# This is here instead of in setup.cfg due to https://github.com/pytest-dev/pytest/issues/8343
|
2023-02-11 10:45:17 +01:00
|
|
|
def pytest_runtestloop(session: pytest.Session):
|
2021-02-13 22:07:37 +01:00
|
|
|
session.add_marker(
|
2021-09-22 16:49:10 +02:00
|
|
|
pytest.mark.filterwarnings("ignore::telegram.warnings.PTBDeprecationWarning")
|
2021-02-13 22:07:37 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-02-22 20:19:46 +01:00
|
|
|
def no_rerun_after_xfail_or_flood(error, name, test: pytest.Function, plugin):
|
|
|
|
"""Don't rerun tests that have xfailed when marked with xfail, or when we hit a flood limit."""
|
|
|
|
xfail_present = test.get_closest_marker(name="xfail")
|
2024-02-08 17:12:00 +01:00
|
|
|
if getattr(error[1], "msg", "") is None:
|
|
|
|
raise error[1]
|
2023-02-22 20:19:46 +01:00
|
|
|
did_we_flood = "flood" in getattr(error[1], "msg", "") # _pytest.outcomes.XFailed has 'msg'
|
2024-04-05 17:26:08 +02:00
|
|
|
return not (xfail_present or did_we_flood)
|
2023-02-22 20:19:46 +01:00
|
|
|
|
|
|
|
|
2023-02-11 10:45:17 +01:00
|
|
|
def pytest_collection_modifyitems(items: List[pytest.Item]):
|
|
|
|
"""Here we add a flaky marker to all request making tests and a (no_)req marker to the rest."""
|
|
|
|
for item in items: # items are the test methods
|
|
|
|
parent = item.parent # Get the parent of the item (class, or module if defined outside)
|
|
|
|
if parent is None: # should never happen, but just in case
|
|
|
|
return
|
|
|
|
if ( # Check if the class name ends with 'WithRequest' and if it has no flaky marker
|
|
|
|
parent.name.endswith("WithRequest")
|
|
|
|
and not parent.get_closest_marker( # get_closest_marker gets pytest.marks with `name`
|
|
|
|
name="flaky"
|
|
|
|
) # don't add/override any previously set markers
|
|
|
|
and not parent.get_closest_marker(name="req")
|
|
|
|
): # Add the flaky marker with a rerun filter to the class
|
|
|
|
parent.add_marker(pytest.mark.flaky(3, 1, rerun_filter=no_rerun_after_xfail_or_flood))
|
|
|
|
parent.add_marker(pytest.mark.req)
|
|
|
|
# Add the no_req marker to all classes that end with 'WithoutRequest' and don't have it
|
|
|
|
elif parent.name.endswith("WithoutRequest") and not parent.get_closest_marker(
|
|
|
|
name="no_req"
|
|
|
|
):
|
|
|
|
parent.add_marker(pytest.mark.no_req)
|
|
|
|
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
# Redefine the event_loop fixture to have a session scope. Otherwise `bot` fixture can't be
|
|
|
|
# session. See https://github.com/pytest-dev/pytest-asyncio/issues/68 for more details.
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def event_loop(request):
|
2022-05-05 09:27:54 +02:00
|
|
|
# ever since ProactorEventLoop became the default in Win 3.8+, the app crashes after the loop
|
|
|
|
# is closed. Hence, we use SelectorEventLoop on Windows to avoid this. See
|
|
|
|
# https://github.com/python/cpython/issues/83413, https://github.com/encode/httpx/issues/914
|
2023-06-29 18:17:47 +02:00
|
|
|
if sys.platform.startswith("win"):
|
2022-05-05 09:27:54 +02:00
|
|
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
2023-03-25 19:18:04 +01:00
|
|
|
return asyncio.get_event_loop_policy().new_event_loop()
|
2022-04-24 12:38:09 +02:00
|
|
|
# loop.close() # instead of closing here, do that at the every end of the test session
|
|
|
|
|
|
|
|
|
2017-08-11 23:58:41 +02:00
|
|
|
@pytest.fixture(scope="session")
|
2023-02-11 10:45:17 +01:00
|
|
|
def bot_info() -> Dict[str, str]:
|
2023-02-22 20:19:46 +01:00
|
|
|
return BOT_INFO_PROVIDER.get_info()
|
2023-02-11 10:45:17 +01:00
|
|
|
|
|
|
|
|
2017-08-11 23:58:41 +02:00
|
|
|
@pytest.fixture(scope="session")
|
2022-04-24 12:38:09 +02:00
|
|
|
async def bot(bot_info):
|
|
|
|
"""Makes an ExtBot instance with the given bot_info"""
|
|
|
|
async with make_bot(bot_info) as _bot:
|
|
|
|
yield _bot
|
2017-08-11 23:58:41 +02:00
|
|
|
|
|
|
|
|
2023-03-25 19:18:04 +01:00
|
|
|
@pytest.fixture()
|
2023-02-11 10:45:17 +01:00
|
|
|
def one_time_bot(bot_info):
|
|
|
|
"""A function scoped bot since the session bot would shutdown when `async with app` finishes"""
|
|
|
|
return make_bot(bot_info)
|
|
|
|
|
|
|
|
|
2022-10-07 10:18:08 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
async def cdc_bot(bot_info):
|
|
|
|
"""Makes an ExtBot instance with the given bot_info that uses arbitrary callback_data"""
|
|
|
|
async with make_bot(bot_info, arbitrary_callback_data=True) as _bot:
|
|
|
|
yield _bot
|
|
|
|
|
|
|
|
|
2021-10-03 15:10:13 +02:00
|
|
|
@pytest.fixture(scope="session")
|
2022-04-24 12:38:09 +02:00
|
|
|
async def raw_bot(bot_info):
|
|
|
|
"""Makes an regular Bot instance with the given bot_info"""
|
2023-02-22 20:19:46 +01:00
|
|
|
async with PytestBot(
|
2022-04-24 12:38:09 +02:00
|
|
|
bot_info["token"],
|
2023-04-18 16:16:23 +02:00
|
|
|
private_key=PRIVATE_KEY if TEST_WITH_OPT_DEPS else None,
|
2023-02-22 20:19:46 +01:00
|
|
|
request=NonchalantHttpxRequest(8),
|
|
|
|
get_updates_request=NonchalantHttpxRequest(1),
|
2022-04-24 12:38:09 +02:00
|
|
|
) as _bot:
|
|
|
|
yield _bot
|
2020-10-06 19:28:40 +02:00
|
|
|
|
|
|
|
|
2023-02-11 10:45:17 +01:00
|
|
|
# Here we store the default bots so that we don't have to create them again and again.
|
|
|
|
# They are initialized but not shutdown on pytest_sessionfinish because it is causing
|
|
|
|
# problems with the event loop (Event loop is closed).
|
2023-02-22 20:19:46 +01:00
|
|
|
_default_bots = {}
|
2023-02-11 10:45:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2022-04-24 12:38:09 +02:00
|
|
|
async def default_bot(request, bot_info):
|
2020-02-06 11:22:56 +01:00
|
|
|
param = request.param if hasattr(request, "param") else {}
|
2023-02-11 10:45:17 +01:00
|
|
|
defaults = Defaults(**param)
|
2020-02-06 11:22:56 +01:00
|
|
|
|
2023-02-11 10:45:17 +01:00
|
|
|
# If the bot is already created, return it. Else make a new one.
|
2024-01-24 20:53:36 +01:00
|
|
|
default_bot = _default_bots.get(defaults)
|
2023-02-11 10:45:17 +01:00
|
|
|
if default_bot is None:
|
|
|
|
default_bot = make_bot(bot_info, defaults=defaults)
|
|
|
|
await default_bot.initialize()
|
2023-02-22 20:19:46 +01:00
|
|
|
_default_bots[defaults] = default_bot # Defaults object is hashable
|
2023-02-11 10:45:17 +01:00
|
|
|
return default_bot
|
2020-02-06 11:22:56 +01:00
|
|
|
|
|
|
|
|
2023-02-11 10:45:17 +01:00
|
|
|
@pytest.fixture(scope="session")
|
2022-04-24 12:38:09 +02:00
|
|
|
async def tz_bot(timezone, bot_info):
|
2023-02-11 10:45:17 +01:00
|
|
|
defaults = Defaults(tzinfo=timezone)
|
|
|
|
try: # If the bot is already created, return it. Saves time since get_me is not called again.
|
2023-02-22 20:19:46 +01:00
|
|
|
return _default_bots[defaults]
|
2023-02-11 10:45:17 +01:00
|
|
|
except KeyError:
|
|
|
|
default_bot = make_bot(bot_info, defaults=defaults)
|
|
|
|
await default_bot.initialize()
|
2023-02-22 20:19:46 +01:00
|
|
|
_default_bots[defaults] = default_bot
|
2023-02-11 10:45:17 +01:00
|
|
|
return default_bot
|
2020-09-27 12:59:48 +02:00
|
|
|
|
|
|
|
|
2017-08-11 23:58:41 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def chat_id(bot_info):
|
|
|
|
return bot_info["chat_id"]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
2019-08-23 21:20:41 +02:00
|
|
|
def super_group_id(bot_info):
|
|
|
|
return bot_info["super_group_id"]
|
2017-08-11 23:58:41 +02:00
|
|
|
|
|
|
|
|
2022-11-22 10:43:50 +01:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def forum_group_id(bot_info):
|
|
|
|
return int(bot_info["forum_group_id"])
|
|
|
|
|
|
|
|
|
2017-08-11 23:58:41 +02:00
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def channel_id(bot_info):
|
|
|
|
return bot_info["channel_id"]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def provider_token(bot_info):
|
|
|
|
return bot_info["payment_provider_token"]
|
|
|
|
|
|
|
|
|
2023-03-25 19:18:04 +01:00
|
|
|
@pytest.fixture()
|
2022-04-24 12:38:09 +02:00
|
|
|
async def app(bot_info):
|
|
|
|
# We build a new bot each time so that we use `app` in a context manager without problems
|
|
|
|
application = (
|
2023-02-22 20:19:46 +01:00
|
|
|
ApplicationBuilder().bot(make_bot(bot_info)).application_class(PytestApplication).build()
|
2022-04-24 12:38:09 +02:00
|
|
|
)
|
|
|
|
yield application
|
|
|
|
if application.running:
|
|
|
|
await application.stop()
|
|
|
|
await application.shutdown()
|
2017-08-11 23:58:41 +02:00
|
|
|
|
|
|
|
|
2023-03-25 19:18:04 +01:00
|
|
|
@pytest.fixture()
|
2022-04-24 12:38:09 +02:00
|
|
|
async def updater(bot_info):
|
|
|
|
# We build a new bot each time so that we use `updater` in a context manager without problems
|
|
|
|
up = Updater(bot=make_bot(bot_info), update_queue=asyncio.Queue())
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
yield up
|
|
|
|
if up.running:
|
2022-04-24 12:38:09 +02:00
|
|
|
await up.stop()
|
|
|
|
await up.shutdown()
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
|
|
|
|
|
2023-03-25 19:18:04 +01:00
|
|
|
@pytest.fixture()
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
def thumb_file():
|
2023-02-11 10:45:17 +01:00
|
|
|
with data_file("thumb.jpg").open("rb") as f:
|
|
|
|
yield f
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
|
|
|
|
|
2023-02-11 10:45:17 +01:00
|
|
|
@pytest.fixture(scope="module")
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
def class_thumb_file():
|
2023-02-11 10:45:17 +01:00
|
|
|
with data_file("thumb.jpg").open("rb") as f:
|
|
|
|
yield f
|
Bot API 4.0 (#1168)
Telegram Passport (#1174):
- Add full support for telegram passport.
- New types: PassportData, PassportFile, EncryptedPassportElement, EncryptedCredentials, PassportElementError, PassportElementErrorDataField, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorFile and PassportElementErrorFiles.
- New bot method: set_passport_data_errors
- New filter: Filters.passport_data
- Field passport_data field on Message
- PassportData is automagically decrypted when you specify your private key when creating Updater or Bot.
- PassportFiles is also automagically decrypted as you download/retrieve them.
- See new passportbot.py example for details on how to use, or go to our telegram passport wiki page for more info
- NOTE: Passport decryption requires new dependency `cryptography`.
Inputfile rework (#1184):
- Change how Inputfile is handled internally
- This allows support for specifying the thumbnails of photos and videos using the thumb= argument in the different send_ methods.
- Also allows Bot.send_media_group to actually finally send more than one media.
- Add thumb to Audio, Video and Videonote
- Add Bot.edit_message_media together with InputMediaAnimation, InputMediaAudio, and inputMediaDocument.
Other Bot API 4.0 changes:
- Add forusquare_type to Venue, InlineQueryResultVenue, InputVenueMessageContent, and Bot.send_venue. (#1170)
- Add vCard support by adding vcard field to Contact, InlineQueryResultContact, InputContactMessageContent, and Bot.send_contact. (#1166)
- Support new message entities: CASHTAG and PHONE_NUMBER. (#1179)
- Cashtag seems to be things like $USD and $GBP, but it seems telegram doesn't currently send them to bots.
- Phone number also seems to have limited support for now
- Add Bot.send_animation, add width, height, and duration to Animation, and add Filters.animation. (#1172)
Co-authored-by: Jasmin Bom <jsmnbom@gmail.com>
Co-authored-by: code1mountain <32801117+code1mountain@users.noreply.github.com>
Co-authored-by: Eldinnie <pieter.schutz+github@gmail.com>
Co-authored-by: mathefreak1 <mathefreak@hi2.in>
2018-08-29 14:18:58 +02:00
|
|
|
|
|
|
|
|
2020-07-28 09:10:32 +02:00
|
|
|
@pytest.fixture(
|
|
|
|
scope="class",
|
|
|
|
params=[{"class": MessageFilter}, {"class": UpdateFilter}],
|
|
|
|
ids=["MessageFilter", "UpdateFilter"],
|
|
|
|
)
|
|
|
|
def mock_filter(request):
|
|
|
|
class MockFilter(request.param["class"]):
|
2019-10-12 15:11:09 +02:00
|
|
|
def __init__(self):
|
2021-11-20 11:36:18 +01:00
|
|
|
super().__init__()
|
2019-10-12 15:11:09 +02:00
|
|
|
self.tested = False
|
|
|
|
|
2020-07-28 09:10:32 +02:00
|
|
|
def filter(self, _):
|
2019-10-12 15:11:09 +02:00
|
|
|
self.tested = True
|
|
|
|
|
|
|
|
return MockFilter()
|
|
|
|
|
|
|
|
|
2023-02-22 20:19:46 +01:00
|
|
|
def _get_false_update_fixture_decorator_params():
|
2020-10-06 19:28:40 +02:00
|
|
|
message = Message(1, DATE, Chat(1, ""), from_user=User(1, "", False), text="test")
|
2019-10-12 15:11:09 +02:00
|
|
|
params = [
|
|
|
|
{"callback_query": CallbackQuery(1, User(1, "", False), "chat", message=message)},
|
|
|
|
{"channel_post": message},
|
|
|
|
{"edited_channel_post": message},
|
|
|
|
{"inline_query": InlineQuery(1, User(1, "", False), "", "")},
|
|
|
|
{"chosen_inline_result": ChosenInlineResult("id", User(1, "", False), "")},
|
|
|
|
{"shipping_query": ShippingQuery("id", User(1, "", False), "", None)},
|
|
|
|
{"pre_checkout_query": PreCheckoutQuery("id", User(1, "", False), "", 0, "")},
|
|
|
|
{"callback_query": CallbackQuery(1, User(1, "", False), "chat")},
|
|
|
|
]
|
|
|
|
ids = tuple(key for kwargs in params for key in kwargs)
|
|
|
|
return {"params": params, "ids": ids}
|
|
|
|
|
|
|
|
|
2023-03-25 19:18:04 +01:00
|
|
|
@pytest.fixture(**_get_false_update_fixture_decorator_params())
|
2019-10-12 15:11:09 +02:00
|
|
|
def false_update(request):
|
|
|
|
return Update(update_id=1, **request.param)
|
2019-11-15 21:51:22 +01:00
|
|
|
|
|
|
|
|
2023-02-11 10:45:17 +01:00
|
|
|
@pytest.fixture(scope="session", params=["Europe/Berlin", "Asia/Singapore", "UTC"])
|
2020-07-10 13:11:28 +02:00
|
|
|
def tzinfo(request):
|
2022-10-31 10:12:18 +01:00
|
|
|
if TEST_WITH_OPT_DEPS:
|
|
|
|
return pytz.timezone(request.param)
|
2023-03-25 19:18:04 +01:00
|
|
|
hours_offset = {"Europe/Berlin": 2, "Asia/Singapore": 8, "UTC": 0}[request.param]
|
|
|
|
return BasicTimezone(offset=datetime.timedelta(hours=hours_offset), name=request.param)
|
2019-11-15 21:51:22 +01:00
|
|
|
|
|
|
|
|
2023-02-11 10:45:17 +01:00
|
|
|
@pytest.fixture(scope="session")
|
2020-07-10 13:11:28 +02:00
|
|
|
def timezone(tzinfo):
|
|
|
|
return tzinfo
|
2023-07-03 10:06:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def tmp_file(tmp_path):
|
|
|
|
with tmp_path / uuid4().hex as file:
|
|
|
|
yield file
|