Add missing shortcuts, new enums, reworked old stuff (#1070)

* Render shortcuts

* Render docs

* Added enumerations

* Added docs

* Use enums, removed Helper

* Bump butcher

* Added InputMediaType enum

* Added MaskPositionPoint, InlineQueryResultType enums

* Update texts

* Added StickerType enum

* Cover tests

* Update docs

* Fixed imports

* Re-enabled all pre-commit hooks
This commit is contained in:
Alex Root Junior 2022-12-04 03:05:49 +02:00 committed by GitHub
parent 3438d2446d
commit 3ea73fbbbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
370 changed files with 19735 additions and 8380 deletions

View file

@ -1,7 +1,7 @@
import pytest
from aiogram.enums import ChatAction
from aiogram.methods import Request, SendChatAction
from aiogram.types import ChatAction
from tests.mocked_bot import MockedBot
pytestmark = pytest.mark.asyncio

View file

@ -2,7 +2,8 @@ from typing import Optional
from pytest import mark, param
from aiogram.types import Chat
from aiogram.enums import ChatAction
from aiogram.types import BufferedInputFile, Chat, ChatPermissions
class TestChat:
@ -20,6 +21,172 @@ class TestChat:
assert method.chat_id == chat.id
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(
"first,last,title,chat_type,result",
[

View 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

View file

@ -50,3 +50,9 @@ class TestUser:
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(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