Ejemplo n.º 1
0
def test_stop():
    manager = Manager()

    # Launch Manager.run in a separate thread
    thread = threading.Thread(target=manager.run)
    thread.daemon = True
    thread.start()

    # Check if the manager terminates properly
    manager.stop()
    thread.join(1)
    if thread.is_alive():
        pytest.fail('Manager did not terminate.')
Ejemplo n.º 2
0
def run(config):
    """Runs the bot."""
    def signal_handler(signum, frame):
        manager.stop()

    def attach_signals():
        for sig in [
                signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT
        ]:
            signal.signal(sig, signal_handler)

    print('Bot started...')
    manager = Manager(config_path=config)
    attach_signals()
    manager.run()
Ejemplo n.º 3
0
def test_load_module():
    class DummyModule(modules.BaseModule):
        pass

    manager = Manager()

    manager.load_module(DummyModule)
    assert manager.get_wrapper(DummyModule) is not None

    manager.unload_module(DummyModule)
    assert manager.get_wrapper(DummyModule) is None
Ejemplo n.º 4
0
def test_help(cl, msg_t, make_privmsg, rec_msg):
    """Test help command. Only Meta module should respond to that command
    without any parameters."""
    msg = make_privmsg('.help')
    config = make_config()
    mng = Manager()
    re = Meta(config)

    rec_msg(msg)
    assert msg_t.msg
Ejemplo n.º 5
0
def test_load_twice():
    class DummyModule(modules.BaseModule):
        pass

    manager = Manager()

    manager.load_module(DummyModule)
    assert manager.get_wrapper(DummyModule) is not None
    assert len(manager.module_wrappers) == 1

    manager.load_module(DummyModule)
    assert manager.get_wrapper(DummyModule) is not None
    assert len(manager.module_wrappers) == 1
Ejemplo n.º 6
0
def test_load_twice_by_name():
    manager = Manager()

    manager.load_module_by_name('meta')
    assert len(manager.module_wrappers) == 1

    manager.load_module_by_name('meta')
    assert len(manager.module_wrappers) == 1
Ejemplo n.º 7
0
def test_reload_tv_with_admin(cl, msg_l, make_privmsg, rec_msg):
    """Load, send, unload, send, load, send."""
    from botnet.manager import Manager
    from modules.builtin.test_admin import admin_make_message, data4, send_data

    msg = make_privmsg('.next_episode a')

    manager = Manager()
    manager.config = make_admin_config()
    manager.load_module_by_name('admin')

    # load
    amsg = admin_make_message('nick4', ':.module_load tv')
    rec_msg(amsg)
    send_data(data4)
    assert len(msg_l.msgs) == 2  # WHOIS, loaded module

    # send
    rec_msg(msg)
    assert len(msg_l.msgs) == 3  # response

    # unload
    amsg = admin_make_message('nick4', ':.module_unload tv')
    rec_msg(amsg)
    assert len(msg_l.msgs) == 4  # unloaded module

    # send
    rec_msg(msg)
    assert len(msg_l.msgs) == 4  # should not respond

    # load
    amsg = admin_make_message('nick4', ':.module_load tv')
    rec_msg(amsg)
    assert len(msg_l.msgs) == 5  # loaded module

    # send
    rec_msg(msg)
    assert len(msg_l.msgs) == 6  # response
Ejemplo n.º 8
0
def test_reload_meta_with_admin(cl, msg_l, make_privmsg, rec_msg):
    """Load, send, unload, send, load, send."""
    from botnet.manager import Manager
    from modules.builtin.test_admin import admin_make_message, data4, send_data

    msg = make_privmsg('.bots')

    manager = Manager()
    manager.config = make_admin_config()
    manager.load_module_by_name('admin')

    # load
    amsg = admin_make_message('nick4', ':.module_load meta')
    rec_msg(amsg)
    send_data(data4)
    assert len(msg_l.msgs) == 2 # WHOIS, loaded module

    # send
    rec_msg(msg)
    assert len(msg_l.msgs) == 3 # response

    # unload
    amsg = admin_make_message('nick4', ':.module_unload meta')
    rec_msg(amsg)
    assert len(msg_l.msgs) == 4 # unloaded module

    # send
    rec_msg(msg)
    assert len(msg_l.msgs) == 4 # should not respond 

    # load
    amsg = admin_make_message('nick4', ':.module_load meta')
    rec_msg(amsg)
    assert len(msg_l.msgs) == 5 # loaded module

    # send
    rec_msg(msg)
    assert len(msg_l.msgs) == 6 # response
Ejemplo n.º 9
0
def test_reload_tv(cl, msg_l, make_privmsg, rec_msg):
    """Load, send, unload, send, load, send."""
    from botnet.manager import Manager

    manager = Manager()

    msg = make_privmsg('.next_episode a')

    manager.load_module_by_name('tv')
    rec_msg(msg)
    assert len(msg_l.msgs) == 1

    manager.unload_module_by_name('tv')
    rec_msg(msg)
    assert len(msg_l.msgs) == 1

    manager.load_module_by_name('tv')
    rec_msg(msg)
    assert len(msg_l.msgs) == 2
Ejemplo n.º 10
0
def test_reload_tv(cl, msg_l, make_privmsg, rec_msg):
    """Load, send, unload, send, load, send."""
    from botnet.manager import Manager

    manager = Manager()

    msg = make_privmsg('.next_episode a')

    manager.load_module_by_name('tv')
    rec_msg(msg)
    assert len(msg_l.msgs) == 1

    manager.unload_module_by_name('tv')
    rec_msg(msg)
    assert len(msg_l.msgs) == 1

    manager.load_module_by_name('tv')
    rec_msg(msg)
    assert len(msg_l.msgs) == 2
Ejemplo n.º 11
0
def test_get_wrapper():
    """Checks if get_wrapper properly handles inheritance. Ensures that
    a child is not returned when querying for a parent."""
    class DummyModule(modules.BaseModule):
        value = 'parent'

    class DummyModuleChild(DummyModule):
        value = 'child'

    def test(manager):
        parent = manager.get_wrapper(DummyModule)
        child = manager.get_wrapper(DummyModuleChild)
        assert parent.module.value == 'parent'
        assert child.module.value == 'child'

    manager = Manager()
    manager.load_module(DummyModule)
    manager.load_module(DummyModuleChild)
    test(manager)

    manager = Manager()
    manager.load_module(DummyModuleChild)
    manager.load_module(DummyModule)
    test(manager)