Files
zvk2_public/tests/zvk/plugins/vk/test_command_parser.py
2019-03-15 15:02:19 +04:00

60 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pytest
from zvk.bot.bot import Bot
from zvk.event.consumer import event_consumer, on_startup
from zvk.event.event import Event
from zvk.plugins.vk.api import VKApi
from zvk.plugins.vk.command_parser import CommandEventType
from zvk.plugins.vk.event_type import VKEventType
@on_startup
async def vk_event_emitter():
yield Event(VKEventType.MESSAGE_NEW,
vk_event_args=[528220, 33, 50951365, 1539933254, 'Я в автобусе щас ваще', {'title': ' ... '}, {}, 0])
yield Event(VKEventType.MESSAGE_NEW,
vk_event_args=[528392, 532481, 2000000049, 1539947094, ',command1', {'from': '363656437'}, {}, 0])
yield Event(VKEventType.MESSAGE_NEW,
vk_event_args=[528393, 532481, 2000000049, 1539947094, ',command2', {'from': '363656437'}, {}, 0])
yield Event(VKEventType.MESSAGE_NEW,
vk_event_args=[528397, 33, 173489181, 1539955700, 'Я литералли ходил на перекур с преподом',
{'fwd_all_count': '0', 'fwd_count': '1', 'title': ' ... '}, {'fwd': '0_0'}, 0])
yield Event(VKEventType.MESSAGE_NEW,
vk_event_args=[540583, 35, 50951365, 1541763627, ',command2 sponge bob square pants', {'title': ' ... '},
{}, 431864521])
yield Event(VKEventType.MESSAGE_NEW,
vk_event_args=[540974, 8227, 2000000055, 1541779800, ',command3 thinking stock imagte',
{'from': '9002294'},
{}, 1729925714])
@event_consumer(consumes=[CommandEventType(command_name='command1')])
async def consumer1(bot):
bot.testing_counter += 1
@event_consumer(consumes=[CommandEventType(command_name='command2')])
async def consumer2(bot):
bot.testing_counter += 2
@event_consumer(consumes=[CommandEventType(command_name='command3')])
async def consumer3(bot, echo):
await echo('chat reply')
@pytest.mark.asyncio
async def test_command_parser(bot: Bot, api: VKApi):
api.expect('messages.send', peer_id=2000000055, message='🤖: chat reply')
bot.event_queue.register_consumer(vk_event_emitter)
bot.event_queue.register_consumer(consumer1)
bot.event_queue.register_consumer(consumer2)
bot.event_queue.register_consumer(consumer3)
assert await bot.run()
assert bot.testing_counter == 5