34 lines
986 B
Python
34 lines
986 B
Python
import pytest
|
|
|
|
from zvk.event.consumer import on_startup
|
|
from zvk.plugins.vk.command import Argument, command
|
|
|
|
|
|
@on_startup
|
|
async def event_emitter(bot):
|
|
yield bot.dummy_message_event(',a --inc=100', from_id=111)
|
|
yield bot.dummy_message_event(',a --inc=10', from_id=111)
|
|
yield bot.dummy_message_event(',a --inc=a', from_id=111)
|
|
yield bot.dummy_message_event(',a --inc=1', from_id=123)
|
|
|
|
|
|
@command('a', Argument('--inc', type=int, default=0), permissions=['admin'])
|
|
async def command_a(bot, inc):
|
|
bot.testing_counter += inc
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_command(bot, api):
|
|
api.expect(method_name='messages.send', peer_id=111,
|
|
message="🤖: Command .a argument --inc: invalid int value: 'a'")
|
|
|
|
api.expect(method_name='messages.send', peer_id=123,
|
|
message="🤖: Access denied")
|
|
|
|
bot.event_queue.register_consumer(event_emitter)
|
|
bot.event_queue.register_consumer(command_a)
|
|
|
|
assert await bot.run()
|
|
|
|
assert bot.testing_counter == 110
|