Ejemplo n.º 1
0
async def test_handler_check() -> None:
    async def func1(_: Bot, __: BotUpdate) -> None:
        ...

    handler = Handler(func1, (
        UpdateTypeFilter(UpdateType.MESSAGE),
        StateFilter('state1'),
    ))

    table = HandlerTable()
    table.freeze()
    _bot = PollBot('token', table, MemoryStorage())
    ctx = Context({'key1': 'str1', 'key2': 'str2', 'key3': 4})
    message = Message.from_dict({
        'message_id': 1,
        'date': 1,
        'chat': {
            'id': 1,
            'type': 'private'
        }
    })
    bu1 = BotUpdate('state1', ctx, Update(update_id=1, message=message))
    assert await handler.check(_bot, bu1)
    bu2 = BotUpdate('state2', ctx, Update(update_id=2, message=message))
    assert not await handler.check(_bot, bu2)
Ejemplo n.º 2
0
def test_poll_answer(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.poll_answer(state='state1', filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.POLL_ANSWER),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 3
0
def test_edited_message(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.edited_message(state='state1',
                      filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.EDITED_MESSAGE),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 4
0
def test_chat_member(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.chat_member(state='state1',
                   filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.CHAT_MEMBER),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 5
0
def test_pre_checkout_query(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.pre_checkout_query(state='state1',
                          filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.PRE_CHECKOUT_QUERY),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 6
0
def test_shipping_query(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.shipping_query(state='state1',
                      filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.SHIPPING_QUERY),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 7
0
def test_chosen_inline_result(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.chosen_inline_result(state='state1',
                            filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.CHOSEN_INLINE_RESULT),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 8
0
def test_table_inline_query(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.inline_query(state='state1',
                    filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.INLINE_QUERY),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 9
0
def test_table_edited_channel_post(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.edited_channel_post(state='state1',
                           filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.EDITED_CHANNEL_POST),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 10
0
def test_channel_post_handler(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.channel_post_handler(handler,
                            state='state1',
                            filters=[GroupChatFilter()])

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.CHANNEL_POST),
        StateFilter('state1'),
        GroupChatFilter()
    ))]
Ejemplo n.º 11
0
def test_callback_query(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.callback_query(state='state1',
                      data_match='pattern',
                      filters=[GroupChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.CALLBACK_QUERY),
        StateFilter('state1'),
        CallbackQueryDataFilter(re.compile('pattern')),
        GroupChatFilter()
    ))]
Ejemplo n.º 12
0
def test_message(handler: HandlerCallable) -> None:
    ht = HandlerTable()
    ht.message(state='state1', commands=['command1'],
               content_types=[ContentType.CONTACT],
               text_match='pattern',
               filters=[PrivateChatFilter()])(handler)

    assert ht._handlers == [Handler(handler, filters=(
        UpdateTypeFilter(UpdateType.MESSAGE),
        StateFilter('state1'),
        CommandsFilter(('command1',)),
        ContentTypeFilter((ContentType.CONTACT,)),
        MessageTextFilter(re.compile('pattern')),
        PrivateChatFilter()
    ))]