git reimport

This commit is contained in:
2019-03-15 15:02:19 +04:00
commit 742797309a
90 changed files with 4411 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
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