mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Cover tests
This commit is contained in:
parent
9d65238e43
commit
3d38577bb0
4 changed files with 208 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ from .menu_button_type import MenuButtonType
|
||||||
from .message_entity_type import MessageEntityType
|
from .message_entity_type import MessageEntityType
|
||||||
from .parse_mode import ParseMode
|
from .parse_mode import ParseMode
|
||||||
from .poll_type import PollType
|
from .poll_type import PollType
|
||||||
|
from .sticker_type import StickerType
|
||||||
from .topic_icon_color import TopicIconColor
|
from .topic_icon_color import TopicIconColor
|
||||||
from .update_type import UpdateType
|
from .update_type import UpdateType
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ __all__ = (
|
||||||
"MessageEntityType",
|
"MessageEntityType",
|
||||||
"ParseMode",
|
"ParseMode",
|
||||||
"PollType",
|
"PollType",
|
||||||
|
"StickerType",
|
||||||
"TopicIconColor",
|
"TopicIconColor",
|
||||||
"UpdateType",
|
"UpdateType",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ from typing import Optional
|
||||||
|
|
||||||
from pytest import mark, param
|
from pytest import mark, param
|
||||||
|
|
||||||
from aiogram.types import Chat
|
from aiogram.enums import ChatAction
|
||||||
|
from aiogram.types import BufferedInputFile, Chat, ChatPermissions
|
||||||
|
|
||||||
|
|
||||||
class TestChat:
|
class TestChat:
|
||||||
|
|
@ -20,6 +21,172 @@ class TestChat:
|
||||||
assert method.chat_id == chat.id
|
assert method.chat_id == chat.id
|
||||||
assert method.sender_chat_id == -1337
|
assert method.sender_chat_id == -1337
|
||||||
|
|
||||||
|
def test_get_administrators(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.get_administrators()
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_delete_message(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.delete_message(message_id=1)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_revoke_invite_link(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.revoke_invite_link(invite_link="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_edit_invite_link(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.edit_invite_link(invite_link="test", name="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_create_invite_link(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.create_invite_link(name="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_export_invite_link(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.export_invite_link()
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_do(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.do(ChatAction.TYPING)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_delete_sticker_set(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.delete_sticker_set()
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_set_sticker_set(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.set_sticker_set(sticker_set_name="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_get_member(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.get_member(user_id=42)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_get_member_count(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.get_member_count()
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_leave(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.leave()
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_unpin_all_messages(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.unpin_all_messages()
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_unpin_message(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.unpin_message()
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_pin_message(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.pin_message(message_id=1)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_set_administrator_custom_title(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.set_administrator_custom_title(user_id=1, custom_title="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_set_permissions(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.set_permissions(
|
||||||
|
permissions=ChatPermissions(
|
||||||
|
can_send_messages=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_promote(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.promote(
|
||||||
|
user_id=42,
|
||||||
|
can_manage_chat=True,
|
||||||
|
)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_restrict(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.restrict(
|
||||||
|
user_id=42,
|
||||||
|
permissions=ChatPermissions(
|
||||||
|
can_send_messages=True,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_unban(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.unban(
|
||||||
|
user_id=42,
|
||||||
|
)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_ban(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.ban(
|
||||||
|
user_id=42,
|
||||||
|
)
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_set_description(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.set_description(description="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_set_title(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.set_title(title="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_delete_photo(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.delete_photo(description="test")
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
|
def test_set_photo(self):
|
||||||
|
chat = Chat(id=-42, type="supergroup")
|
||||||
|
|
||||||
|
method = chat.set_photo(photo=BufferedInputFile(b"PNG", filename="photo.png"))
|
||||||
|
assert method.chat_id == chat.id
|
||||||
|
|
||||||
@mark.parametrize(
|
@mark.parametrize(
|
||||||
"first,last,title,chat_type,result",
|
"first,last,title,chat_type,result",
|
||||||
[
|
[
|
||||||
|
|
|
||||||
32
tests/test_api/test_types/test_sticker.py
Normal file
32
tests/test_api/test_types/test_sticker.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
from aiogram.enums import StickerType
|
||||||
|
from aiogram.types import Sticker
|
||||||
|
|
||||||
|
|
||||||
|
class TestSticker:
|
||||||
|
def test_get_profile_photos(self):
|
||||||
|
sticker = Sticker(
|
||||||
|
file_id="test",
|
||||||
|
file_unique_id="test",
|
||||||
|
type=StickerType.REGULAR,
|
||||||
|
width=100,
|
||||||
|
height=100,
|
||||||
|
is_animated=False,
|
||||||
|
is_video=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
method = sticker.set_position_in_set(position=1)
|
||||||
|
assert method.sticker == sticker.file_id
|
||||||
|
|
||||||
|
def test_delete_from_set(self):
|
||||||
|
sticker = Sticker(
|
||||||
|
file_id="test",
|
||||||
|
file_unique_id="test",
|
||||||
|
type=StickerType.REGULAR,
|
||||||
|
width=100,
|
||||||
|
height=100,
|
||||||
|
is_animated=False,
|
||||||
|
is_video=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
method = sticker.delete_from_set()
|
||||||
|
assert method.sticker == sticker.file_id
|
||||||
|
|
@ -50,3 +50,9 @@ class TestUser:
|
||||||
user = User(id=42, is_bot=False, first_name=first, last_name=last)
|
user = User(id=42, is_bot=False, first_name=first, last_name=last)
|
||||||
assert user.mention_html() == f'<a href="tg://user?id=42">{user.full_name}</a>'
|
assert user.mention_html() == f'<a href="tg://user?id=42">{user.full_name}</a>'
|
||||||
assert user.mention_html(name=name) == f'<a href="tg://user?id=42">{name}</a>'
|
assert user.mention_html(name=name) == f'<a href="tg://user?id=42">{name}</a>'
|
||||||
|
|
||||||
|
def test_get_profile_photos(self):
|
||||||
|
user = User(id=42, is_bot=False, first_name="Test", last_name="User")
|
||||||
|
|
||||||
|
method = user.get_profile_photos(description="test")
|
||||||
|
assert method.user_id == user.id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue