Merge branch 'aiogram:dev-3.x' into dev-3.x

This commit is contained in:
m-xim 2024-11-19 16:49:51 +03:00 committed by GitHub
commit 6748acc8a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
566 changed files with 13395 additions and 1469 deletions

View file

@ -1,3 +1,5 @@
import asyncio
import sys
from pathlib import Path
import pytest
@ -5,19 +7,27 @@ from _pytest.config import UsageError
from pymongo.errors import InvalidURI, PyMongoError
from pymongo.uri_parser import parse_uri as parse_mongo_url
from redis.asyncio.connection import parse_url as parse_redis_url
from redis.exceptions import ConnectionError
from aiogram import Dispatcher
from aiogram.fsm.storage.base import StorageKey
from aiogram.fsm.storage.memory import (
DisabledEventIsolation,
MemoryStorage,
SimpleEventIsolation,
)
from aiogram.fsm.storage.mongo import MongoStorage
from aiogram.fsm.storage.redis import RedisEventIsolation, RedisStorage
from aiogram.fsm.storage.redis import RedisStorage
from tests.mocked_bot import MockedBot
DATA_DIR = Path(__file__).parent / "data"
CHAT_ID = -42
USER_ID = 42
SKIP_MESSAGE_PATTERN = 'Need "--{db}" option with {db} URI to run'
INVALID_URI_PATTERN = "Invalid {db} URI {uri!r}: {err}"
def pytest_addoption(parser):
parser.addoption("--redis", default=None, help="run tests which require redis connection")
@ -28,38 +38,32 @@ def pytest_configure(config):
config.addinivalue_line("markers", "redis: marked tests require redis connection to run")
config.addinivalue_line("markers", "mongo: marked tests require mongo connection to run")
def pytest_collection_modifyitems(config, items):
for db, parse_uri in [("redis", parse_redis_url), ("mongo", parse_mongo_url)]:
uri = config.getoption(f"--{db}")
if uri is None:
skip = pytest.mark.skip(reason=f"need --{db} option with {db} URI to run")
for item in items:
if db in item.keywords:
item.add_marker(skip)
else:
try:
parse_uri(uri)
except (ValueError, InvalidURI) as e:
raise UsageError(f"Invalid {db} URI {uri!r}: {e}")
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
else:
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
@pytest.fixture()
def redis_server(request):
redis_uri = request.config.getoption("--redis")
return redis_uri
if redis_uri is None:
pytest.skip(SKIP_MESSAGE_PATTERN.format(db="redis"))
else:
return redis_uri
@pytest.fixture()
@pytest.mark.redis
async def redis_storage(redis_server):
if not redis_server:
pytest.skip("Redis is not available here")
try:
parse_redis_url(redis_server)
except ValueError as e:
raise UsageError(INVALID_URI_PATTERN.format(db="redis", uri=redis_server, err=e))
storage = RedisStorage.from_url(redis_server)
try:
await storage.redis.info()
except ConnectionError as e:
pytest.skip(str(e))
pytest.fail(str(e))
try:
yield storage
finally:
@ -71,19 +75,26 @@ async def redis_storage(redis_server):
@pytest.fixture()
def mongo_server(request):
mongo_uri = request.config.getoption("--mongo")
return mongo_uri
if mongo_uri is None:
pytest.skip(SKIP_MESSAGE_PATTERN.format(db="mongo"))
else:
return mongo_uri
@pytest.fixture()
@pytest.mark.mongo
async def mongo_storage(mongo_server):
if not mongo_server:
pytest.skip("MongoDB is not available here")
storage = MongoStorage.from_url(mongo_server)
try:
parse_mongo_url(mongo_server)
except InvalidURI as e:
raise UsageError(INVALID_URI_PATTERN.format(db="mongo", uri=mongo_server, err=e))
storage = MongoStorage.from_url(
url=mongo_server,
connection_kwargs={"serverSelectionTimeoutMS": 2000},
)
try:
await storage._client.server_info()
except PyMongoError as e:
pytest.skip(str(e))
pytest.fail(str(e))
else:
yield storage
await storage._client.drop_database(storage._database)
@ -101,7 +112,6 @@ async def memory_storage():
@pytest.fixture()
@pytest.mark.redis
async def redis_isolation(redis_storage):
isolation = redis_storage.create_isolation()
return isolation
@ -130,6 +140,11 @@ def bot():
return MockedBot()
@pytest.fixture(name="storage_key")
def create_storage_key(bot: MockedBot):
return StorageKey(chat_id=CHAT_ID, user_id=USER_ID, bot_id=bot.id)
@pytest.fixture()
async def dispatcher():
dp = Dispatcher()
@ -138,3 +153,10 @@ async def dispatcher():
yield dp
finally:
await dp.emit_shutdown()
# @pytest.fixture(scope="session")
# def event_loop_policy(request):
# if sys.platform == "win32":
# return asyncio.WindowsSelectorEventLoopPolicy()
# return asyncio.DefaultEventLoopPolicy()

View file

@ -21,7 +21,7 @@ from aiogram.client.session import aiohttp
from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.exceptions import TelegramNetworkError
from aiogram.methods import TelegramMethod
from aiogram.types import UNSET_PARSE_MODE, InputFile
from aiogram.types import InputFile
from tests.mocked_bot import MockedBot
@ -248,13 +248,16 @@ class TestAiohttpSession:
async with AiohttpSession() as session:
assert isinstance(session, AsyncContextManager)
with patch(
"aiogram.client.session.aiohttp.AiohttpSession.create_session",
new_callable=AsyncMock,
) as mocked_create_session, patch(
"aiogram.client.session.aiohttp.AiohttpSession.close",
new_callable=AsyncMock,
) as mocked_close:
with (
patch(
"aiogram.client.session.aiohttp.AiohttpSession.create_session",
new_callable=AsyncMock,
) as mocked_create_session,
patch(
"aiogram.client.session.aiohttp.AiohttpSession.close",
new_callable=AsyncMock,
) as mocked_close,
):
async with session as ctx:
assert session == ctx
mocked_close.assert_awaited_once()

View file

@ -1,4 +1,4 @@
from aiogram.methods import AnswerCallbackQuery, Request
from aiogram.methods import AnswerCallbackQuery
from tests.mocked_bot import MockedBot

View file

@ -1,11 +1,5 @@
from aiogram import Bot
from aiogram.methods import AnswerInlineQuery, Request
from aiogram.types import (
InlineQueryResult,
InlineQueryResultArticle,
InlineQueryResultPhoto,
InputTextMessageContent,
)
from aiogram.methods import AnswerInlineQuery
from aiogram.types import InlineQueryResultArticle, InputTextMessageContent
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import AnswerPreCheckoutQuery, Request
from aiogram.methods import AnswerPreCheckoutQuery
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import AnswerShippingQuery, Request
from aiogram.methods import AnswerShippingQuery
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import ApproveChatJoinRequest, Request
from aiogram.methods import ApproveChatJoinRequest
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import BanChatMember, Request
from aiogram.methods import BanChatMember
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import BanChatSenderChat, Request
from aiogram.methods import BanChatSenderChat
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Close, Request
from aiogram.methods import Close
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import CloseForumTopic, Request
from aiogram.methods import CloseForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import CloseGeneralForumTopic, Request
from aiogram.methods import CloseGeneralForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import CopyMessage, Request
from aiogram.methods import CopyMessage
from aiogram.types import MessageId
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import CreateChatInviteLink, Request
from aiogram.methods import CreateChatInviteLink
from aiogram.types import ChatInviteLink, User
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,28 @@
from datetime import timedelta
from aiogram.methods import CreateChatSubscriptionInviteLink
from aiogram.types import ChatInviteLink, User
from tests.mocked_bot import MockedBot
class TestCreateChatSubscriptionInviteLink:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
CreateChatSubscriptionInviteLink,
ok=True,
result=ChatInviteLink(
invite_link="https://t.me/username",
creator=User(id=42, is_bot=False, first_name="User"),
is_primary=False,
is_revoked=False,
creates_join_request=False,
),
)
response: ChatInviteLink = await bot.create_chat_subscription_invite_link(
chat_id=-42,
subscription_period=timedelta(days=30),
subscription_price=42,
)
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,4 +1,4 @@
from aiogram.methods import CreateForumTopic, Request
from aiogram.methods import CreateForumTopic
from aiogram.types import ForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import CreateInvoiceLink, Request
from aiogram.methods import CreateInvoiceLink
from aiogram.types import LabeledPrice
from tests.mocked_bot import MockedBot

View file

@ -1,5 +1,5 @@
from aiogram.enums import StickerFormat
from aiogram.methods import CreateNewStickerSet, Request
from aiogram.methods import CreateNewStickerSet
from aiogram.types import FSInputFile, InputSticker
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeclineChatJoinRequest, Request
from aiogram.methods import DeclineChatJoinRequest
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteChatPhoto, Request
from aiogram.methods import DeleteChatPhoto
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteChatStickerSet, Request
from aiogram.methods import DeleteChatStickerSet
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteForumTopic, Request
from aiogram.methods import DeleteForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteMessage, Request
from aiogram.methods import DeleteMessage
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteMyCommands, Request
from aiogram.methods import DeleteMyCommands
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteStickerFromSet, Request
from aiogram.methods import DeleteStickerFromSet
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteStickerSet, Request
from aiogram.methods import DeleteStickerSet
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import DeleteWebhook, Request
from aiogram.methods import DeleteWebhook
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import EditChatInviteLink, Request
from aiogram.methods import EditChatInviteLink
from aiogram.types import ChatInviteLink, User
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,26 @@
from aiogram.methods import EditChatSubscriptionInviteLink
from aiogram.types import ChatInviteLink, User
from tests.mocked_bot import MockedBot
class TestEditChatSubscriptionInviteLink:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
EditChatSubscriptionInviteLink,
ok=True,
result=ChatInviteLink(
invite_link="https://t.me/username",
creator=User(id=42, is_bot=False, first_name="User"),
is_primary=False,
is_revoked=False,
creates_join_request=False,
),
)
response: ChatInviteLink = await bot.edit_chat_subscription_invite_link(
chat_id=-42,
invite_link="https://t.me/username/test",
name="test",
)
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,4 +1,4 @@
from aiogram.methods import EditForumTopic, Request
from aiogram.methods import EditForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import EditGeneralForumTopic, Request
from aiogram.methods import EditGeneralForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,7 +1,7 @@
import datetime
from typing import Union
from aiogram.methods import EditMessageCaption, Request
from aiogram.methods import EditMessageCaption
from aiogram.types import Chat, Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import Union
from aiogram.methods import EditMessageLiveLocation, Request
from aiogram.methods import EditMessageLiveLocation
from aiogram.types import Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import Union
from aiogram.methods import EditMessageMedia, Request
from aiogram.methods import EditMessageMedia
from aiogram.types import BufferedInputFile, InputMediaPhoto, Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import Union
from aiogram.methods import EditMessageReplyMarkup, Request
from aiogram.methods import EditMessageReplyMarkup
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import Union
from aiogram.methods import EditMessageText, Request
from aiogram.methods import EditMessageText
from aiogram.types import Message
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,15 @@
from aiogram.methods import EditUserStarSubscription
from tests.mocked_bot import MockedBot
class TestEditUserStarSubscription:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(EditUserStarSubscription, ok=True, result=True)
response: bool = await bot.edit_user_star_subscription(
user_id=42,
telegram_payment_charge_id="telegram_payment_charge_id",
is_canceled=False,
)
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,4 +1,4 @@
from aiogram.methods import ExportChatInviteLink, Request
from aiogram.methods import ExportChatInviteLink
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import ForwardMessage, Request
from aiogram.methods import ForwardMessage
from aiogram.types import Chat, Message
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,32 @@
from aiogram.methods import GetAvailableGifts
from aiogram.types import Gift, Gifts, Sticker
from tests.mocked_bot import MockedBot
class TestGetAvailableGifts:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
GetAvailableGifts,
ok=True,
result=Gifts(
gifts=[
Gift(
id="gift_id",
sticker=Sticker(
file_id="file_id",
file_unique_id="file_id",
type="regular",
width=512,
height=512,
is_animated=False,
is_video=False,
),
star_count=1,
)
]
),
)
response: Gifts = await bot.get_available_gifts()
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,6 +1,6 @@
from typing import List
from aiogram.methods import GetChatAdministrators, Request
from aiogram.methods import GetChatAdministrators
from aiogram.types import ChatMember, ChatMemberOwner, User
from tests.mocked_bot import MockedBot

View file

@ -1,5 +1,5 @@
from aiogram.methods import GetChatMember, Request
from aiogram.types import ChatMember, ChatMemberOwner, User
from aiogram.methods import GetChatMember
from aiogram.types import ChatMemberOwner, User
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetChatMemberCount, Request
from aiogram.methods import GetChatMemberCount
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetChatMenuButton, Request
from aiogram.methods import GetChatMenuButton
from aiogram.types import MenuButton, MenuButtonDefault
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import List
from aiogram.methods import GetCustomEmojiStickers, Request
from aiogram.methods import GetCustomEmojiStickers
from aiogram.types import Sticker
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetFile, Request
from aiogram.methods import GetFile
from aiogram.types import File
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import List
from aiogram.methods import GetForumTopicIconStickers, Request
from aiogram.methods import GetForumTopicIconStickers
from aiogram.types import Sticker
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import List
from aiogram.methods import GetGameHighScores, Request
from aiogram.methods import GetGameHighScores
from aiogram.types import GameHighScore, User
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetMe, Request
from aiogram.methods import GetMe
from aiogram.types import User
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import List
from aiogram.methods import GetMyCommands, Request
from aiogram.methods import GetMyCommands
from aiogram.types import BotCommand
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetMyDefaultAdministratorRights, Request
from aiogram.methods import GetMyDefaultAdministratorRights
from aiogram.types import ChatAdministratorRights
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetMyDescription, Request
from aiogram.methods import GetMyDescription
from aiogram.types import BotDescription
from tests.mocked_bot import MockedBot

View file

@ -1,5 +1,5 @@
from aiogram.methods import GetMyName
from aiogram.types import BotDescription, BotName
from aiogram.types import BotName
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetMyShortDescription, Request
from aiogram.methods import GetMyShortDescription
from aiogram.types import BotShortDescription
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,46 @@
from datetime import datetime
from aiogram.methods import GetStarTransactions
from aiogram.types import (
File,
StarTransaction,
StarTransactions,
TransactionPartnerUser,
User,
)
from tests.mocked_bot import MockedBot
class TestGetStarTransactions:
async def test_bot_method(self, bot: MockedBot):
user = User(id=42, is_bot=False, first_name="Test")
prepare_result = bot.add_result_for(
GetStarTransactions,
ok=True,
result=StarTransactions(
transactions=[
StarTransaction(
id="test1",
user=user,
amount=1,
date=datetime.now(),
source=TransactionPartnerUser(
user=user,
),
),
StarTransaction(
id="test2",
user=user,
amount=1,
date=datetime.now(),
receiver=TransactionPartnerUser(
user=user,
),
),
]
),
)
response: File = await bot.get_star_transactions(limit=10, offset=0)
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetStickerSet, Request
from aiogram.methods import GetStickerSet
from aiogram.types import Sticker, StickerSet
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import List
from aiogram.methods import GetUpdates, Request
from aiogram.methods import GetUpdates
from aiogram.types import Update
from tests.mocked_bot import MockedBot

View file

@ -26,7 +26,7 @@ class TestGetMessageUrl:
["supergroup", -10012345678901, None, True, "https://t.me/c/12345678901/10"],
],
)
def test_method(
def test_get_url_non_topic_message(
self,
bot: MockedBot,
chat_type: str,
@ -46,5 +46,61 @@ class TestGetMessageUrl:
if expected_result is None:
assert fake_message.get_url(force_private=force_private) is None
assert (
fake_message.get_url(force_private=force_private, include_thread_id=True) is None
)
else:
assert fake_message.get_url(force_private=force_private) == expected_result
assert (
fake_message.get_url(force_private=force_private, include_thread_id=True)
== expected_result
)
@pytest.mark.parametrize(
"chat_username,force_private,include_thread_id,fake_thread_id_topic,expected_result",
[
[None, False, False, None, "https://t.me/c/1234567890/10"],
[None, False, False, 3, "https://t.me/c/1234567890/10"],
[None, False, True, None, "https://t.me/c/1234567890/10"],
[None, False, True, 3, "https://t.me/c/1234567890/3/10"],
[None, True, False, None, "https://t.me/c/1234567890/10"],
[None, True, False, 3, "https://t.me/c/1234567890/10"],
[None, True, True, None, "https://t.me/c/1234567890/10"],
[None, True, True, 3, "https://t.me/c/1234567890/3/10"],
["name", False, False, None, "https://t.me/name/10"],
["name", False, False, 3, "https://t.me/name/10"],
["name", False, True, None, "https://t.me/name/10"],
["name", False, True, 3, "https://t.me/name/3/10"],
["name", True, False, None, "https://t.me/c/1234567890/10"],
["name", True, False, 3, "https://t.me/c/1234567890/10"],
["name", True, True, None, "https://t.me/c/1234567890/10"],
["name", True, True, 3, "https://t.me/c/1234567890/3/10"],
],
)
def test_get_url_if_topic_message(
self,
bot: MockedBot,
chat_username: Optional[str],
force_private: bool,
include_thread_id: bool,
fake_thread_id_topic: Optional[int],
expected_result: Optional[str],
):
fake_message_id = 10
fake_chat_id = -1001234567890
fake_chat_type = "supergroup"
fake_chat_with_topics = Chat(
id=fake_chat_id, username=chat_username, type=fake_chat_type, is_forum=True
)
fake_message_from_topic = Message(
message_id=fake_message_id,
date=datetime.datetime.now(),
text="test",
chat=fake_chat_with_topics,
is_topic_message=True,
message_thread_id=fake_thread_id_topic,
)
actual_result = fake_message_from_topic.get_url(
force_private=force_private, include_thread_id=include_thread_id
)
assert actual_result == expected_result

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetUserProfilePhotos, Request
from aiogram.methods import GetUserProfilePhotos
from aiogram.types import PhotoSize, UserProfilePhotos
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import GetWebhookInfo, Request
from aiogram.methods import GetWebhookInfo
from aiogram.types import WebhookInfo
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import HideGeneralForumTopic, Request
from aiogram.methods import HideGeneralForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import LeaveChat, Request
from aiogram.methods import LeaveChat
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import LogOut, Request
from aiogram.methods import LogOut
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import PinChatMessage, Request
from aiogram.methods import PinChatMessage
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import PromoteChatMember, Request
from aiogram.methods import PromoteChatMember
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,4 @@
from aiogram.enums import StickerFormat
from aiogram.methods import AddStickerToSet, RefundStarPayment
from aiogram.types import InputSticker
from aiogram.methods import RefundStarPayment
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import ReopenForumTopic, Request
from aiogram.methods import ReopenForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import ReopenGeneralForumTopic, Request
from aiogram.methods import ReopenGeneralForumTopic
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, RestrictChatMember
from aiogram.methods import RestrictChatMember
from aiogram.types import ChatPermissions
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, RevokeChatInviteLink
from aiogram.methods import RevokeChatInviteLink
from aiogram.types import ChatInviteLink, User
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,34 @@
from datetime import datetime, timedelta
from aiogram.methods import SavePreparedInlineMessage
from aiogram.types import (
InlineQueryResultArticle,
InputTextMessageContent,
PreparedInlineMessage,
)
from tests.mocked_bot import MockedBot
class TestSavePreparedInlineMessage:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
SavePreparedInlineMessage,
ok=True,
result=PreparedInlineMessage(
id="id",
expiration_date=datetime.now() + timedelta(days=1),
),
)
response: PreparedInlineMessage = await bot.save_prepared_inline_message(
user_id=42,
result=InlineQueryResultArticle(
id="id",
title="title",
input_message_content=InputTextMessageContent(
message_text="message_text",
),
),
)
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendAnimation
from aiogram.methods import SendAnimation
from aiogram.types import Animation, Chat, Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendAudio
from aiogram.methods import SendAudio
from aiogram.types import Audio, Chat, Message
from tests.mocked_bot import MockedBot

View file

@ -1,5 +1,5 @@
from aiogram.enums import ChatAction
from aiogram.methods import Request, SendChatAction
from aiogram.methods import SendChatAction
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendContact
from aiogram.methods import SendContact
from aiogram.types import Chat, Contact, Message
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SendDice
from aiogram.methods import SendDice
from aiogram.types import Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendDocument
from aiogram.methods import SendDocument
from aiogram.types import Chat, Document, Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendGame
from aiogram.methods import SendGame
from aiogram.types import Chat, Game, Message, PhotoSize
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,11 @@
from aiogram.methods import SendGift
from tests.mocked_bot import MockedBot
class TestSendGift:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SendGift, ok=True, result=True)
response: bool = await bot.send_gift(user_id=42, gift_id="gift_id")
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendInvoice
from aiogram.methods import SendInvoice
from aiogram.types import Chat, Invoice, LabeledPrice, Message
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendLocation
from aiogram.methods import SendLocation
from aiogram.types import Chat, Location, Message
from tests.mocked_bot import MockedBot

View file

@ -1,7 +1,7 @@
import datetime
from typing import List
from aiogram.methods import Request, SendMediaGroup
from aiogram.methods import SendMediaGroup
from aiogram.types import (
BufferedInputFile,
Chat,

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendMessage
from aiogram.methods import SendMessage
from aiogram.types import Chat, ForceReply, Message, ReplyKeyboardRemove
from tests.mocked_bot import MockedBot

View file

@ -0,0 +1,43 @@
import datetime
from aiogram.methods import SendPaidMedia
from aiogram.types import (
Chat,
InputPaidMediaPhoto,
Message,
PaidMediaInfo,
PaidMediaPhoto,
PhotoSize,
)
from tests.mocked_bot import MockedBot
class TestSendPaidMedia:
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
SendPaidMedia,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
chat=Chat(id=42, type="private"),
paid_media=PaidMediaInfo(
paid_media=[
PaidMediaPhoto(
photo=[
PhotoSize(
file_id="test", width=42, height=42, file_unique_id="test"
)
]
)
],
star_count=1,
),
),
)
response: Message = await bot.send_paid_media(
chat_id=-42, star_count=1, media=[InputPaidMediaPhoto(media="file_id")]
)
request = bot.get_request()
assert response == prepare_result.result

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendPhoto
from aiogram.methods import SendPhoto
from aiogram.types import Chat, Message, PhotoSize
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendPoll
from aiogram.methods import SendPoll
from aiogram.types import Chat, Message, Poll, PollOption
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendSticker
from aiogram.methods import SendSticker
from aiogram.types import Chat, Message, Sticker
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendVenue
from aiogram.methods import SendVenue
from aiogram.types import Chat, Location, Message, Venue
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendVideo
from aiogram.methods import SendVideo
from aiogram.types import Chat, Message, Video
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendVideoNote
from aiogram.methods import SendVideoNote
from aiogram.types import BufferedInputFile, Chat, Message, VideoNote
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
import datetime
from aiogram.methods import Request, SendVoice
from aiogram.methods import SendVoice
from aiogram.types import Chat, Message, Voice
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetChatAdministratorCustomTitle
from aiogram.methods import SetChatAdministratorCustomTitle
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetChatDescription
from aiogram.methods import SetChatDescription
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetChatMenuButton
from aiogram.methods import SetChatMenuButton
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetChatPermissions
from aiogram.methods import SetChatPermissions
from aiogram.types import ChatPermissions
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetChatPhoto
from aiogram.methods import SetChatPhoto
from aiogram.types import BufferedInputFile
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetChatStickerSet
from aiogram.methods import SetChatStickerSet
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetChatTitle
from aiogram.methods import SetChatTitle
from tests.mocked_bot import MockedBot

View file

@ -1,4 +1,4 @@
from aiogram.methods import Request, SetCustomEmojiStickerSetThumbnail
from aiogram.methods import SetCustomEmojiStickerSetThumbnail
from tests.mocked_bot import MockedBot

View file

@ -1,6 +1,6 @@
from typing import Union
from aiogram.methods import Request, SetGameScore
from aiogram.methods import SetGameScore
from aiogram.types import Message
from tests.mocked_bot import MockedBot

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