Example #1
0
def _do_test(
    plugin_name,
    loader,
    data_name,
    cmd,
    text: Optional[str] = "test _ data",
    is_nick_valid=None,
    nick=None,
    bot_nick=None,
):
    plugin = importlib.import_module("plugins." + plugin_name)
    bot = MagicMock()
    bot.data_dir = "data"
    bot.loop = asyncio.get_event_loop()
    event = Event(
        hook=MagicMock(),
        bot=bot,
        conn=MagicMock(),
        channel="#foo",
        nick=nick or "foobar",
    )
    if bot_nick:
        event.conn.nick = bot_nick
    else:
        event.conn.nick = "TestBot"

    if is_nick_valid:
        event.is_nick_valid = is_nick_valid

    if loader:
        _call(getattr(plugin, loader), event)

    if data_name:
        assert getattr(plugin, data_name)

    cmd_func = getattr(plugin, cmd)
    cmd_event = CommandEvent(
        text=text or "",
        cmd_prefix=".",
        hook=MagicMock(),
        triggered_command="foo",
        base_event=event,
    )
    if is_nick_valid:
        cmd_event.is_nick_valid = is_nick_valid

    return _call(cmd_func, cmd_event), cmd_event
Example #2
0
def _do_test(plugin_name,
             loader,
             data_name,
             cmd,
             text='test _ data',
             is_nick_valid=None,
             nick=None,
             bot_nick=None):
    plugin = importlib.import_module('plugins.' + plugin_name)
    bot = MagicMock()
    bot.data_dir = 'data'
    bot.loop = asyncio.get_event_loop()
    event = Event(hook=MagicMock(),
                  bot=bot,
                  conn=MagicMock(),
                  channel='#foo',
                  nick=nick or 'foobar')
    if bot_nick:
        event.conn.nick = bot_nick
    else:
        event.conn.nick = 'TestBot'

    if is_nick_valid:
        event.is_nick_valid = is_nick_valid

    if loader:
        _call(getattr(plugin, loader), event)

    if data_name:
        assert getattr(plugin, data_name)

    cmd_func = getattr(plugin, cmd)
    cmd_event = CommandEvent(text=text or '',
                             cmd_prefix='.',
                             hook=MagicMock(),
                             triggered_command='foo',
                             base_event=event)
    if is_nick_valid:
        cmd_event.is_nick_valid = is_nick_valid

    return _call(cmd_func, cmd_event), cmd_event