示例#1
0
async def test_get_chat(bot: Bot, event_loop):
    """ getChat method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_dict=CHAT, loop=event_loop):
        result = await bot.get_chat(chat_id=chat.id)
        assert result == chat
示例#2
0
async def test_export_chat_invite_link(bot: Bot, event_loop):
    """ exportChatInviteLink method test """
    from .types.dataset import CHAT, INVITE_LINK
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_dict=INVITE_LINK, loop=event_loop):
        result = await bot.export_chat_invite_link(chat_id=chat.id)
        assert result == INVITE_LINK
示例#3
0
async def test_delete_chat_photo(bot: Bot):
    """ deleteChatPhoto method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_data=True):
        result = await bot.delete_chat_photo(chat_id=chat.id)
        assert isinstance(result, bool)
        assert result is True
示例#4
0
async def test_send_chat_action(bot: Bot):
    """ sendChatAction method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_data=True):
        result = await bot.send_chat_action(chat_id=chat.id, action=types.ChatActions.TYPING)
        assert isinstance(result, bool)
        assert result is True
示例#5
0
async def test_set_chat_description(bot: Bot):
    """ setChatDescription method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_data=True):
        result = await bot.set_chat_description(chat_id=chat.id, description='Test description')
        assert isinstance(result, bool)
        assert result is True
示例#6
0
async def test_set_chat_sticker_set(bot: Bot):
    """ setChatStickerSet method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_data=True):
        result = await bot.set_chat_sticker_set(chat_id=chat.id, sticker_set_name='aiogram_stickers')
        assert isinstance(result, bool)
        assert result is True
示例#7
0
async def test_unpin_chat_message(bot: Bot, event_loop):
    """ unpinChatMessage method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_dict=True, loop=event_loop):
        result = await bot.unpin_chat_message(chat_id=chat.id)
        assert isinstance(result, bool)
        assert result is True
示例#8
0
async def test_leave_chat(bot: Bot, event_loop):
    """ leaveChat method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_data=True, loop=event_loop):
        result = await bot.leave_chat(chat_id=chat.id)
        assert isinstance(result, bool)
        assert result is True
示例#9
0
async def test_set_chat_title(bot: Bot, event_loop):
    """ setChatTitle method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_dict=True, loop=event_loop):
        result = await bot.set_chat_title(chat_id=chat.id, title='Test title')
        assert isinstance(result, bool)
        assert result is True
示例#10
0
async def test_get_chat_members_count(bot: Bot, event_loop):
    """ getChatMembersCount method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)
    count = 5

    async with FakeTelegram(message_data=count, loop=event_loop):
        result = await bot.get_chat_members_count(chat_id=chat.id)
        assert result == count
示例#11
0
async def test_delete_chat_sticker_set(bot: Bot, event_loop):
    """ setChatStickerSet method test """
    from .types.dataset import CHAT
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_dict=True, loop=event_loop):
        result = await bot.delete_chat_sticker_set(chat_id=chat.id)
        assert isinstance(result, bool)
        assert result is True
示例#12
0
async def test_kick_chat_member(bot: Bot):
    """ kickChatMember method test """
    from .types.dataset import USER, CHAT
    user = types.User(**USER)
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_data=True):
        result = await bot.kick_chat_member(chat_id=chat.id, user_id=user.id, until_date=123)
        assert isinstance(result, bool)
        assert result is True
示例#13
0
async def test_unban_chat_member(bot: Bot, event_loop):
    """ unbanChatMember method test """
    from .types.dataset import USER, CHAT
    user = types.User(**USER)
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_dict=True, loop=event_loop):
        result = await bot.unban_chat_member(chat_id=chat.id, user_id=user.id)
        assert isinstance(result, bool)
        assert result is True
示例#14
0
async def test_get_chat_administrators(bot: Bot):
    """ getChatAdministrators method test """
    from .types.dataset import CHAT, CHAT_MEMBER
    chat = types.Chat(**CHAT)
    member = types.ChatMember.resolve(**CHAT_MEMBER)

    async with FakeTelegram(message_data=[CHAT_MEMBER, CHAT_MEMBER]):
        result = await bot.get_chat_administrators(chat_id=chat.id)
        assert result[0] == member
        assert len(result) == 2
示例#15
0
async def test_get_chat_member(bot: Bot):
    """ getChatMember method test """
    from .types.dataset import CHAT, CHAT_MEMBER
    chat = types.Chat(**CHAT)
    member = types.ChatMember.resolve(**CHAT_MEMBER)

    async with FakeTelegram(message_data=CHAT_MEMBER):
        result = await bot.get_chat_member(chat_id=chat.id, user_id=member.user.id)
        assert isinstance(result, types.ChatMember)
        assert result == member
示例#16
0
async def send_all_yes(query: types.CallbackQuery, state: FSMContext):
    await query.answer()
    await query.message.delete_reply_markup()

    sending_message_id = await services.admin.get_sending_message_id(state)
    sending_message = types.Message(message_id=sending_message_id,
                                    chat=types.Chat(id=query.from_user.id))
    count_alive_users = await services.admin.send_all(
        sending_message=sending_message, user_model=User)
    await query.message.answer(
        config.MSG_SUCCESFUL_SEND_ALL.format(count_alive_users))
示例#17
0
async def test_promote_chat_member(bot: Bot):
    """ promoteChatMember method test """
    from .types.dataset import USER, CHAT
    user = types.User(**USER)
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_data=True):
        result = await bot.promote_chat_member(chat_id=chat.id, user_id=user.id, can_change_info=True,
                                               can_delete_messages=True, can_edit_messages=True,
                                               can_invite_users=True, can_pin_messages=True, can_post_messages=True,
                                               can_promote_members=True, can_restrict_members=True)
        assert isinstance(result, bool)
        assert result is True
示例#18
0
async def test_get_chat_administrators(bot: Bot):
    """ getChatAdministrators method test """
    from .types.dataset import CHAT, CHAT_MEMBER, CHAT_MEMBER_OWNER
    chat = types.Chat(**CHAT)
    member = types.ChatMember.resolve(**CHAT_MEMBER)
    owner = types.ChatMember.resolve(**CHAT_MEMBER_OWNER)

    async with FakeTelegram(message_data=[CHAT_MEMBER, CHAT_MEMBER_OWNER]):
        result = await bot.get_chat_administrators(chat_id=chat.id)
        assert result[0] == member
        assert result[1] == owner
        assert len(result) == 2
        for m in result:
            assert m.is_chat_admin()
            assert hasattr(m, "can_be_edited")
示例#19
0
async def test_restrict_chat_member(bot: Bot, event_loop):
    """ restrictChatMember method test """
    from .types.dataset import USER, CHAT
    user = types.User(**USER)
    chat = types.Chat(**CHAT)

    async with FakeTelegram(message_dict=True, loop=event_loop):
        result = await bot.restrict_chat_member(
            chat_id=chat.id,
            user_id=user.id,
            can_add_web_page_previews=False,
            can_send_media_messages=False,
            can_send_messages=False,
            can_send_other_messages=False,
            until_date=123)
        assert isinstance(result, bool)
        assert result is True
示例#20
0
    def chat_and_user_from_update(
            self,
            update: Optional[types.Message]) -> Tuple[types.Chat, types.User]:
        chat = types.Chat()
        user = types.User()
        if update is None:
            return chat, user

        if update.message:
            user = update.message.from_user
            chat = update.message.chat

        elif update.edited_message:
            user = update.edited_message.from_user
            chat = update.edited_message.chat

        elif update.channel_post:
            chat = update.channel_post.chat

        elif update.edited_channel_post:
            chat = update.edited_channel_post.chat

        elif update.inline_query:
            user = update.inline_query.from_user

        elif update.chosen_inline_result:
            user = update.chosen_inline_result.from_user

        elif update.callback_query:
            if update.callback_query.message:
                chat = update.callback_query.message.chat
            user = update.callback_query.from_user

        elif update.shipping_query:
            user = update.shipping_query.from_user

        elif update.pre_checkout_query:
            user = update.pre_checkout_query.from_user

        elif update.poll:
            pass

        elif update.poll_answer:
            pass

        return chat, user
示例#21
0
async def scheduler():
    if RSS:
        for feed in RSS_FEEDS:
            aioschedule.every(DELAY).seconds.do(rss_task, feed["url"],
                                                feed["feed_id"],
                                                feed["chat_id"])

    if VK:
        aioschedule.every(DELAY).seconds.do(vk_timer)

    if KATZ_BOTS:
        aioschedule.every(DELAY).seconds.do(Poll.close_old)

    if BLOODYKNIGHT:
        message = types.Message(chat=types.Chat(id=-1001410092459))
        aioschedule.every().day.at("8:00").do(monobank, message)

    while True:
        await aioschedule.run_pending()
        await asyncio.sleep(5)
示例#22
0
from aiogram import types
from .dataset import CHAT

chat = types.Chat(**CHAT)


def test_export():
    exported = chat.to_python()
    assert isinstance(exported, dict)
    assert exported == CHAT


def test_id():
    assert isinstance(chat.id, int)
    assert chat.id == CHAT['id']
    # assert hash(chat) == CHAT['id']


def test_name():
    assert isinstance(chat.first_name, str)
    assert chat.first_name == CHAT['first_name']

    assert isinstance(chat.last_name, str)
    assert chat.last_name == CHAT['last_name']

    assert isinstance(chat.username, str)
    assert chat.username == CHAT['username']


def test_type():
    assert isinstance(chat.type, str)