mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add tests for GetChatGifts, GetUserGifts, RepostStory, and SendMessageDraft methods
This commit is contained in:
parent
f7574296b0
commit
8ffd714834
4 changed files with 125 additions and 0 deletions
41
tests/test_api/test_methods/test_get_chat_gifts.py
Normal file
41
tests/test_api/test_methods/test_get_chat_gifts.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import datetime
|
||||
|
||||
from aiogram.methods import GetChatGifts
|
||||
from aiogram.types import Gift, OwnedGiftRegular, OwnedGifts, Sticker
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
class TestGetChatGifts:
|
||||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(
|
||||
GetChatGifts,
|
||||
ok=True,
|
||||
result=OwnedGifts(
|
||||
total_count=1,
|
||||
gifts=[
|
||||
OwnedGiftRegular(
|
||||
gift=Gift(
|
||||
id="test_gift_id",
|
||||
sticker=Sticker(
|
||||
file_id="test_file_id",
|
||||
file_unique_id="test_file_unique_id",
|
||||
type="regular",
|
||||
width=512,
|
||||
height=512,
|
||||
is_animated=False,
|
||||
is_video=False,
|
||||
),
|
||||
star_count=100,
|
||||
),
|
||||
send_date=int(datetime.datetime.now().timestamp()),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
response: OwnedGifts = await bot.get_chat_gifts(
|
||||
chat_id=42,
|
||||
limit=10,
|
||||
)
|
||||
request = bot.get_request()
|
||||
assert response == prepare_result.result
|
||||
41
tests/test_api/test_methods/test_get_user_gifts.py
Normal file
41
tests/test_api/test_methods/test_get_user_gifts.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import datetime
|
||||
|
||||
from aiogram.methods import GetUserGifts
|
||||
from aiogram.types import Gift, OwnedGiftRegular, OwnedGifts, Sticker
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
class TestGetUserGifts:
|
||||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(
|
||||
GetUserGifts,
|
||||
ok=True,
|
||||
result=OwnedGifts(
|
||||
total_count=1,
|
||||
gifts=[
|
||||
OwnedGiftRegular(
|
||||
gift=Gift(
|
||||
id="test_gift_id",
|
||||
sticker=Sticker(
|
||||
file_id="test_file_id",
|
||||
file_unique_id="test_file_unique_id",
|
||||
type="regular",
|
||||
width=512,
|
||||
height=512,
|
||||
is_animated=False,
|
||||
is_video=False,
|
||||
),
|
||||
star_count=100,
|
||||
),
|
||||
send_date=int(datetime.datetime.now().timestamp()),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
response: OwnedGifts = await bot.get_user_gifts(
|
||||
user_id=42,
|
||||
limit=10,
|
||||
)
|
||||
request = bot.get_request()
|
||||
assert response == prepare_result.result
|
||||
24
tests/test_api/test_methods/test_repost_story.py
Normal file
24
tests/test_api/test_methods/test_repost_story.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from aiogram.methods import RepostStory
|
||||
from aiogram.types import Chat, Story
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
class TestRepostStory:
|
||||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(
|
||||
RepostStory,
|
||||
ok=True,
|
||||
result=Story(
|
||||
id=42,
|
||||
chat=Chat(id=42, type="private"),
|
||||
),
|
||||
)
|
||||
|
||||
response: Story = await bot.repost_story(
|
||||
business_connection_id="test_connection_id",
|
||||
from_chat_id=123,
|
||||
from_story_id=456,
|
||||
active_period=6 * 3600,
|
||||
)
|
||||
request = bot.get_request()
|
||||
assert response == prepare_result.result
|
||||
19
tests/test_api/test_methods/test_send_message_draft.py
Normal file
19
tests/test_api/test_methods/test_send_message_draft.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from aiogram.methods import SendMessageDraft
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
class TestSendMessageDraft:
|
||||
async def test_bot_method(self, bot: MockedBot):
|
||||
prepare_result = bot.add_result_for(
|
||||
SendMessageDraft,
|
||||
ok=True,
|
||||
result=True,
|
||||
)
|
||||
|
||||
response: bool = await bot.send_message_draft(
|
||||
chat_id=42,
|
||||
draft_id=1,
|
||||
text="test draft",
|
||||
)
|
||||
request = bot.get_request()
|
||||
assert response == prepare_result.result
|
||||
Loading…
Add table
Add a link
Reference in a new issue