mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added tests
This commit is contained in:
parent
86e4ab235d
commit
624ba40ab0
12 changed files with 184 additions and 36 deletions
11
.butcher/methods/setUserEmojiStatus/replace.yml
Normal file
11
.butcher/methods/setUserEmojiStatus/replace.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
annotations:
|
||||
emoji_status_expiration_date:
|
||||
parsed_type:
|
||||
type: union
|
||||
items:
|
||||
- type: std
|
||||
name: datetime.datetime
|
||||
- type: std
|
||||
name: datetime.timedelta
|
||||
- type: std
|
||||
name: int
|
||||
11
.butcher/types/PreparedInlineMessage/replace.yml
Normal file
11
.butcher/types/PreparedInlineMessage/replace.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
annotations:
|
||||
expiration_date:
|
||||
parsed_type:
|
||||
type: union
|
||||
items:
|
||||
- type: std
|
||||
name: datetime.datetime
|
||||
- type: std
|
||||
name: datetime.timedelta
|
||||
- type: std
|
||||
name: int
|
||||
|
|
@ -4968,7 +4968,9 @@ class Bot:
|
|||
self,
|
||||
user_id: int,
|
||||
emoji_status_custom_emoji_id: Optional[str] = None,
|
||||
emoji_status_expiration_date: Optional[int] = None,
|
||||
emoji_status_expiration_date: Optional[
|
||||
Union[datetime.datetime, datetime.timedelta, int]
|
||||
] = None,
|
||||
request_timeout: Optional[int] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -5,33 +5,32 @@ from typing import TYPE_CHECKING, Any, Optional, Union
|
|||
from ..types.prepared_inline_message import PreparedInlineMessage
|
||||
from .base import TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..types.inline_query_result_article import InlineQueryResultArticle
|
||||
from ..types.inline_query_result_audio import InlineQueryResultAudio
|
||||
from ..types.inline_query_result_cached_audio import InlineQueryResultCachedAudio
|
||||
from ..types.inline_query_result_cached_document import (
|
||||
InlineQueryResultCachedDocument,
|
||||
)
|
||||
from ..types.inline_query_result_cached_gif import InlineQueryResultCachedGif
|
||||
from ..types.inline_query_result_cached_mpeg4_gif import (
|
||||
InlineQueryResultCachedMpeg4Gif,
|
||||
)
|
||||
from ..types.inline_query_result_cached_photo import InlineQueryResultCachedPhoto
|
||||
from ..types.inline_query_result_cached_sticker import (
|
||||
InlineQueryResultCachedSticker,
|
||||
)
|
||||
from ..types.inline_query_result_cached_video import InlineQueryResultCachedVideo
|
||||
from ..types.inline_query_result_cached_voice import InlineQueryResultCachedVoice
|
||||
from ..types.inline_query_result_contact import InlineQueryResultContact
|
||||
from ..types.inline_query_result_document import InlineQueryResultDocument
|
||||
from ..types.inline_query_result_game import InlineQueryResultGame
|
||||
from ..types.inline_query_result_gif import InlineQueryResultGif
|
||||
from ..types.inline_query_result_location import InlineQueryResultLocation
|
||||
from ..types.inline_query_result_mpeg4_gif import InlineQueryResultMpeg4Gif
|
||||
from ..types.inline_query_result_photo import InlineQueryResultPhoto
|
||||
from ..types.inline_query_result_venue import InlineQueryResultVenue
|
||||
from ..types.inline_query_result_video import InlineQueryResultVideo
|
||||
from ..types.inline_query_result_voice import InlineQueryResultVoice
|
||||
from ..types.inline_query_result_article import InlineQueryResultArticle
|
||||
from ..types.inline_query_result_audio import InlineQueryResultAudio
|
||||
from ..types.inline_query_result_cached_audio import InlineQueryResultCachedAudio
|
||||
from ..types.inline_query_result_cached_document import (
|
||||
InlineQueryResultCachedDocument,
|
||||
)
|
||||
from ..types.inline_query_result_cached_gif import InlineQueryResultCachedGif
|
||||
from ..types.inline_query_result_cached_mpeg4_gif import (
|
||||
InlineQueryResultCachedMpeg4Gif,
|
||||
)
|
||||
from ..types.inline_query_result_cached_photo import InlineQueryResultCachedPhoto
|
||||
from ..types.inline_query_result_cached_sticker import (
|
||||
InlineQueryResultCachedSticker,
|
||||
)
|
||||
from ..types.inline_query_result_cached_video import InlineQueryResultCachedVideo
|
||||
from ..types.inline_query_result_cached_voice import InlineQueryResultCachedVoice
|
||||
from ..types.inline_query_result_contact import InlineQueryResultContact
|
||||
from ..types.inline_query_result_document import InlineQueryResultDocument
|
||||
from ..types.inline_query_result_game import InlineQueryResultGame
|
||||
from ..types.inline_query_result_gif import InlineQueryResultGif
|
||||
from ..types.inline_query_result_location import InlineQueryResultLocation
|
||||
from ..types.inline_query_result_mpeg4_gif import InlineQueryResultMpeg4Gif
|
||||
from ..types.inline_query_result_photo import InlineQueryResultPhoto
|
||||
from ..types.inline_query_result_venue import InlineQueryResultVenue
|
||||
from ..types.inline_query_result_video import InlineQueryResultVideo
|
||||
from ..types.inline_query_result_voice import InlineQueryResultVoice
|
||||
|
||||
|
||||
class SavePreparedInlineMessage(TelegramMethod[PreparedInlineMessage]):
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ from typing import TYPE_CHECKING, Any, Optional
|
|||
|
||||
from .base import TelegramMethod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..types import MessageEntity
|
||||
from ..types.message_entity import MessageEntity
|
||||
|
||||
|
||||
class SendGift(TelegramMethod[bool]):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
|
||||
from .base import TelegramMethod
|
||||
|
||||
|
|
@ -19,7 +20,9 @@ class SetUserEmojiStatus(TelegramMethod[bool]):
|
|||
"""Unique identifier of the target user"""
|
||||
emoji_status_custom_emoji_id: Optional[str] = None
|
||||
"""Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status."""
|
||||
emoji_status_expiration_date: Optional[int] = None
|
||||
emoji_status_expiration_date: Optional[Union[datetime.datetime, datetime.timedelta, int]] = (
|
||||
None
|
||||
)
|
||||
"""Expiration date of the emoji status, if any"""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -31,7 +34,9 @@ class SetUserEmojiStatus(TelegramMethod[bool]):
|
|||
*,
|
||||
user_id: int,
|
||||
emoji_status_custom_emoji_id: Optional[str] = None,
|
||||
emoji_status_expiration_date: Optional[int] = None,
|
||||
emoji_status_expiration_date: Optional[
|
||||
Union[datetime.datetime, datetime.timedelta, int]
|
||||
] = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Any, Union
|
||||
|
||||
from .base import TelegramObject
|
||||
|
||||
|
|
@ -14,7 +15,7 @@ class PreparedInlineMessage(TelegramObject):
|
|||
|
||||
id: str
|
||||
"""Unique identifier of the prepared message"""
|
||||
expiration_date: int
|
||||
expiration_date: Union[datetime.datetime, datetime.timedelta, int]
|
||||
"""Expiration date of the prepared message, in Unix time. Expired prepared messages can no longer be used"""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -22,7 +23,11 @@ class PreparedInlineMessage(TelegramObject):
|
|||
# This section was auto-generated via `butcher`
|
||||
|
||||
def __init__(
|
||||
__pydantic__self__, *, id: str, expiration_date: int, **__pydantic_kwargs: Any
|
||||
__pydantic__self__,
|
||||
*,
|
||||
id: str,
|
||||
expiration_date: Union[datetime.datetime, datetime.timedelta, int],
|
||||
**__pydantic_kwargs: Any,
|
||||
) -> None:
|
||||
# DO NOT EDIT MANUALLY!!!
|
||||
# This method was auto-generated via `butcher`
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
from aiogram.enums import StickerFormat
|
||||
from aiogram.methods import EditUserStarSubscription, Request, UploadStickerFile
|
||||
from aiogram.types import BufferedInputFile, File
|
||||
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
|
||||
33
tests/test_api/test_methods/test_get_available_gifts.py
Normal file
33
tests/test_api/test_methods/test_get_available_gifts.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from aiogram.enums import StickerFormat
|
||||
from aiogram.methods import GetAvailableGifts, Request, UploadStickerFile
|
||||
from aiogram.types import BufferedInputFile, File, 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
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
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
|
||||
13
tests/test_api/test_methods/test_send_gift.py
Normal file
13
tests/test_api/test_methods/test_send_gift.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from aiogram.enums import StickerFormat
|
||||
from aiogram.methods import GetAvailableGifts, Request, SendGift, UploadStickerFile
|
||||
from aiogram.types import BufferedInputFile, File, Gift, Gifts, Sticker
|
||||
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
|
||||
17
tests/test_api/test_methods/test_set_user_emoji_status.py
Normal file
17
tests/test_api/test_methods/test_set_user_emoji_status.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
from aiogram.methods import SetUserEmojiStatus
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
class TestSetUserEmojiStatus:
|
||||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(SetUserEmojiStatus, ok=True, result=True)
|
||||
|
||||
response: bool = await bot.set_user_emoji_status(
|
||||
user_id=42,
|
||||
emoji_status_custom_emoji_id="emoji_status_custom_emoji_id",
|
||||
emoji_status_expiration_date=datetime.now() + timedelta(days=1),
|
||||
)
|
||||
request = bot.get_request()
|
||||
assert response == prepare_result.result
|
||||
Loading…
Add table
Add a link
Reference in a new issue