Exemple #1
0
def test_execute_func(bot_cls, manager: ModuleManager):
    manager.load_all()
    mock = MagicMock(spec=dummy, name='dummy')
    mock.__wrapped__ = dummy.__wrapped__
    bot = bot_cls.return_value = Mock(spec=RequestBot, name='bot')

    yield from manager.execute_func(
        func=mock,
        plugin=manager.plugins['dummy'],
        private=False,
        channel='#czarnobyl',
        user=User('a!b@c'),
        args=['lol'],
        kwargs={'b': '42'},
    )

    bot_cls.assert_called_once_with(
        protocol=manager.protocol,
        private=False,
        chan='#czarnobyl',
        config={'__nick__': 'bot'},
        plugin=manager.plugins['dummy'],
        user=User('a!b@c'),
        temp={},
    )

    mock.assert_called_once_with(bot, a='lol', b=42)
Exemple #2
0
def test_execute_as_reg(manager: ModuleManager):
    manager.execute_regs = CoroutineMock()
    yield from manager.execute('#czarnobyl', User('a!b@c'), 'dummmmmmy')
    manager.execute_regs.assert_called_once_with(
        'dummmmmmy',
        False,
        '#czarnobyl',
        User('a!b@c'),
    )
Exemple #3
0
def test_execute_as_cmd_and_reply(manager: ModuleManager):
    manager.execute_command = CoroutineMock()
    yield from manager.execute('#czarnobyl', User('a!b@c'), 'bot: dummy lol')
    manager.execute_command.assert_called_once_with(
        'dummy',
        'lol',
        False,
        '#czarnobyl',
        User('a!b@c'),
    )
Exemple #4
0
def test_execute_as_cmd_and_private(manager: ModuleManager):
    manager.execute_command = CoroutineMock()
    yield from manager.execute('socek', User('a!b@c'), '.dummy lol')
    manager.execute_command.assert_called_once_with(
        'dummy',
        'lol',
        True,
        'socek',
        User('a!b@c'),
    )
    def check(ctrl):  # wait for another coroutines
        importer = protocol_with_importer.importer
        assert protocol_with_importer.messages == []
        assert importer.execute.assert_called_once_with(
            '#czarnobyl', User('socek!a@b'), 'message')

        ctrl.log.assert_called_once_with('#czarnobyl', '<socek> message')
Exemple #6
0
def private_bot(protocol):
    return RequestBot(
        protocol=protocol,
        user=User('socek!a@b'),
        private=True,
        config={},
        temp={},
    )
Exemple #7
0
def public_bot_with_db(protocol_with_db):
    return RequestBot(
        protocol=protocol_with_db,
        user=User('socek!a@b'),
        chan='#czarnobyl',
        private=False,
        config={},
        temp={},
    )
Exemple #8
0
def test__user_and_channel_in_whitelist():
    whois = WhoisData()
    whois.account = 'FooNick'
    assert (yield from cmd_is_good(
        cfg={'whitelist': '#bar,#foobar{Barnick},#foo{FooNick;BarNick}'},
        func=create_func(cmd='cmd'),
        cmd='cmd',
        channel='#foo',
        user=User('foo!foo@foo'),
        whois=whois))
Exemple #9
0
def test_execute_regs(manager: ModuleManager):
    manager.execute_func = CoroutineMock()
    manager.load_all()
    yield from manager.execute_regs(
        msg='dummmmy a b',
        private=False,
        channel='#czarnobyl',
        user=User('a!b@c'),
    )

    from grazyna.test_mocks.dummy_plugin import dummy_reg
    manager.execute_func.assert_called_once_with(
        dummy_reg,
        manager.plugins['dummy'],
        False,
        '#czarnobyl',
        User('a!b@c'),
        ('a', 'b'),
        {},
    )
Exemple #10
0
def test_is_blocked(manager: ModuleManager):
    user = User('a!0@c')
    another_user = User('b!1@c')
    counters = manager.executed_counters
    with freeze_time('2017-01-01 12:00:00'):
        counter = ExecutedCounter()
        counter.counter = 50
        counters[user.prefix] = counter

    with freeze_time('2017-01-01 10:00:00'):
        counter = ExecutedCounter()
        counter.counter = 50
        counters[another_user.prefix] = counter

    with freeze_time('2017-01-01 12:00:00'):
        assert manager.is_blocked(user) is True
        assert manager.is_blocked(another_user) is False

    counters = manager.executed_counters
    assert counters[user.prefix].counter == 50
    assert counters[another_user.prefix].counter == 1
Exemple #11
0
def test_execute_command(manager: ModuleManager):
    manager.execute_func = CoroutineMock()
    manager.find_message_in_db = CoroutineMock()
    manager.load_all()
    yield from manager.execute_command(
        cmd='dummy',
        text='lol b=42',
        private=False,
        channel='#czarnobyl',
        user=User('a!b@c'),
    )

    assert not manager.find_message_in_db.called

    from grazyna.test_mocks.dummy_plugin import dummy
    manager.execute_func.assert_called_once_with(
        dummy,
        manager.plugins['dummy'],
        False,
        '#czarnobyl',
        User('a!b@c'),
        ['lol'],
        {'b': '42'},
    )
Exemple #12
0
def test_execute_not_exists_command(manager: ModuleManager):
    manager.execute_func = CoroutineMock()
    manager.find_message_in_db = CoroutineMock()
    manager.load_all()
    yield from manager.execute_command(
        cmd='szalona-dziewczyna',
        text='lol b=42',
        private=False,
        channel='#czarnobyl',
        user=User('a!b@c'),
    )

    assert not manager.execute_func.called

    manager.find_message_in_db.assert_called_once_with(
        'szalona-dziewczyna',
        '#czarnobyl',
        'lol b=42',
    )
Exemple #13
0
def bot_with_importer(protocol_with_importer):
    return RequestBot(
        protocol=protocol_with_importer,
        user=User('socek!a@b'),
        chan='#czarnobyl',
    )
Exemple #14
0
def make_bot(protocol, **kwargs):
    return RequestBot(protocol, user=User('socek!a@b'), chan='#czarnobyl', **kwargs)