Exemplo n.º 1
0
def test_plugin_logs():
    tfh = tempfile.NamedTemporaryFile()

    limbo.init_log(config={
        "logfile": tfh.name,
        "loglevel": logging.DEBUG,
    })
    limbo.init_plugins("test/plugins")

    tfh.seek(0)
    log = tfh.read()

    assert "DEBUG:plugin: test/plugins/echo.py" in log
    assert "DEBUG:attaching" in log
Exemplo n.º 2
0
def test_config_plugin_empty_string_success():
    hooks = limbo.init_plugins("test/plugins", "")
    assert len(hooks) == 9
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    assert len(hooks["message"]) == 2
Exemplo n.º 3
0
def test_handle_member_left():
    event = {"type": "member_left_channel", "user": "******"}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_event(event, server) == "user 2 left"
Exemplo n.º 4
0
def test_config_plugin_success():
    hooks = limbo.init_plugins("test/plugins", "echo,loop")
    assert len(hooks) == 5
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    assert len(hooks["message"]) == 1
Exemplo n.º 5
0
def test_config_plugin_empty_string_success():
    hooks = limbo.init_plugins("test/plugins", "")
    assert len(hooks) == 9
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    assert len(hooks["message"]) == 2
Exemplo n.º 6
0
def test_config_plugin_success():
    hooks = limbo.init_plugins("test/plugins", "echo,loop")
    assert len(hooks) == 5
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    assert len(hooks["message"]) == 1
Exemplo n.º 7
0
def test_loop_hook():
    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)
    slack = limbo.FakeSlack()
    limbo.loop(server, test_loop=1)

    eq_(server._loop_plugin_ran, True)
Exemplo n.º 8
0
def test_plugin_success():
    hooks = limbo.init_plugins("test/plugins")
    eq_(len(hooks), 4)
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    eq_(len(hooks["message"]), 2)
Exemplo n.º 9
0
def test_plugin_success():
    hooks = limbo.init_plugins("test/plugins")
    eq_(len(hooks), 2)
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    eq_(len(hooks["message"]), 2)
Exemplo n.º 10
0
def test_loop_hook():
    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)
    slack = limbo.FakeSlack()
    limbo.loop(server, test_loop=1)

    assert server._loop_plugin_ran == True
Exemplo n.º 11
0
def test_config_plugin_none_success():
    hooks = limbo.init_plugins("test/plugins", None)
    assert len(hooks) == 7
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    assert len(hooks["message"]) == 2
Exemplo n.º 12
0
def test_handle_message_basic():
    msg = u"!echo Iñtërnâtiônàlizætiøn"
    event = {"user": "******", "text": msg}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    eq_(limbo.handle_message(event, server), msg)
Exemplo n.º 13
0
def test_handle_message_basic():
    msg = u"!echo Iñtërnâtiônàlizætiøn"
    event = {"user": "******", "text": msg}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    eq_(limbo.handle_message(event, server), msg)
Exemplo n.º 14
0
def test_handle_bot_message():
    msg = u"!echo Iñtërnâtiônàlizætiøn bot"
    event = {"bot_id": "1", "text": msg, "subtype": "bot_message"}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    eq_(limbo.handle_message(event, server), msg)
Exemplo n.º 15
0
def test_handle_bot_message():
    msg = u"!echo Iñtërnâtiônàlizætiøn bot"
    event = {"bot_id": "2", "text": msg, "subtype": "bot_message"}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_message(event, server) == msg
Exemplo n.º 16
0
def test_loop_hook():
    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)
    slack = limbo.FakeSlack()
    metrics = limbo.NullMetrics()
    limbo.loop(server, metrics, test_loop=1)

    assert server._loop_plugin_ran == True
    assert metrics.count == 0
Exemplo n.º 17
0
def test_handle_message_slack_user_nil():
    msg = u"!echo Iñtërnâtiônàlizætiøn"
    event = {"user": "******", "text": msg}
    users = {"0": User("nobody", 0, "", 0)}

    hooks = limbo.init_plugins("test/plugins")
    slack = limbo.FakeSlack(users=users)
    server = limbo.FakeServer(slack=slack, hooks=hooks)

    assert limbo.handle_message(event, server) == u"!echo Iñtërnâtiônàlizætiøn"
Exemplo n.º 18
0
def test_handle_message_handles_mention():
    msg = u"!echo Iñtërnâtiônàlizætiøn <@1>"
    event = {"user": "******", "text": msg}

    config = {"needmention": "true"}
    slack = limbo.FakeSlack()
    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(config=config, slack=slack, hooks=hooks)

    assert limbo.handle_message(event, server) == msg
Exemplo n.º 19
0
def test_handle_message_ignores_wrongmention():
    msg = u"!echo Iñtërnâtiônàlizætiøn bot <@3>"
    event = {"bot_id": "2", "text": msg, "subtype": "bot_message"}

    config = {"needmention": "true"}
    slack = limbo.FakeSlack()
    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(config=config, slack=slack, hooks=hooks)

    assert limbo.handle_message(event, server) == None
Exemplo n.º 20
0
def test_handle_delete_message():
    oldmsg = u"!echo old message"
    event = {"type": "message",
            "subtype": "message_deleted",
            "previous_message": {"text": oldmsg, "user": "******"}}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_message(event, server) == "Deleted: {}".format(oldmsg)
Exemplo n.º 21
0
def test_handle_delete_message():
    oldmsg = u"!echo old message"
    event = {"type": "message",
            "subtype": "message_deleted",
            "previous_message": {"text": oldmsg, "user": "******"}}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_message(event, server) == "Deleted: {}".format(oldmsg)
Exemplo n.º 22
0
def test_handle_message_slack_user_nil():
    msg = u"!echo Iñtërnâtiônàlizætiøn"
    event = {"user": "******", "text": msg}
    users = SearchList([User(None, "nobody", 0, "", 0)])

    hooks = limbo.init_plugins("test/plugins")
    slack = limbo.FakeSlack(users=users)
    server = limbo.FakeServer(slack=slack, hooks=hooks)

    eq_(limbo.handle_message(event, server), None)
Exemplo n.º 23
0
def test_handle_member_left():
    event = {
      "type": "member_left_channel",
      "user": "******"
    }

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_event(event, server) == "user 2 left"
Exemplo n.º 24
0
def test_handle_message_slack_user_nil():
    msg = u"!echo Iñtërnâtiônàlizætiøn"
    event = {"user": "******", "text": msg}
    users = {"0": User(None, "nobody", 0, "", 0)}

    hooks = limbo.init_plugins("test/plugins")
    slack = limbo.FakeSlack(users=users)
    server = limbo.FakeServer(slack=slack, hooks=hooks)

    eq_(limbo.handle_message(event, server), None)
Exemplo n.º 25
0
def test_handle_channel_join():
    event = {
      "user": "******",
      "type": "message",
      "subtype": "channel_join",
      "text": "User has joined"
    }

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_message(event, server) == "saw user 2 join"
Exemplo n.º 26
0
def test_handle_edit_message():
    oldmsg = u"old message"
    newmsg = u"!echo new message"
    event = {"type": "message",
            "subtype": "message_changed",
            "previous_message": {"text": oldmsg},
            "message": {"text": newmsg, "user": "******"}}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_message(event, server) == "Changed: {}".format(newmsg)
Exemplo n.º 27
0
def test_handle_channel_join():
    event = {
      "user": "******",
      "type": "message",
      "subtype": "channel_join",
      "text": "User has joined"
    }

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_message(event, server) == "saw user 2 join"
Exemplo n.º 28
0
def test_handle_edit_message():
    oldmsg = u"old message"
    newmsg = u"!echo new message"
    event = {"type": "message",
            "subtype": "message_changed",
            "previous_message": {"text": oldmsg},
            "message": {"text": newmsg, "user": "******"}}

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks)

    assert limbo.handle_message(event, server) == "Changed: {}".format(newmsg)
Exemplo n.º 29
0
def test_event_count():
    msg = u"!echo Iñtërnâtiônàlizætiøn bot"
    oldmsg = u"old message"
    newmsg = u"!echo new message"
    events = [[{
        "channel": "none",
        "user": "******",
        "text": msg
    }, {
        "channel": "none",
        "user": "******",
        "type": "message",
        "subtype": "channel_join",
        "text": "User has joined"
    }, {
        "channel": "none",
        "user": "******",
        "type": "member_left_channel"
    }, {
        "channel": "none",
        "type": "message",
        "subtype": "message_changed",
        "previous_message": {
            "text": oldmsg
        },
        "message": {
            "text": newmsg,
            "user": "******"
        }
    }]]
    slack = limbo.FakeSlack(events=events)

    hooks = limbo.init_plugins("test/plugins")
    server = limbo.FakeServer(hooks=hooks, slack=slack)

    metrics = limbo.NullMetrics()

    limbo.loop(server, metrics, test_loop=1)

    assert metrics.count == 4
Exemplo n.º 30
0
def test_plugin_invalid_dir():
    try:
        limbo.init_plugins("invalid/package")
    except limbo.InvalidPluginDir:
        return
    1 / 0
Exemplo n.º 31
0
def test_missing_hook():
    hooks = limbo.init_plugins("test/plugins")
    eq_(limbo.run_hook(hooks, "nonexistant", {"text": u"!echo bananas"}, None),
        [])
Exemplo n.º 32
0
def test_plugin_logs():
    mhdr = MockHandler()
    logging.getLogger("limbo.limbo").addHandler(mhdr)
    limbo.init_plugins("test/plugins")
    mhdr.check("debug", "attaching message hook for echo")
Exemplo n.º 33
0
def test_plugin_invalid_dir():
    try:
        limbo.init_plugins("invalid/package")
    except limbo.InvalidPluginDir:
        return
    1 / 0
Exemplo n.º 34
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    assert len(hooks) == 0
Exemplo n.º 35
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    assert len(hooks) == 0
Exemplo n.º 36
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    eq_(len(hooks), 0)
Exemplo n.º 37
0
def test_plugin_logs():
    mhdr = MockHandler()
    logging.getLogger("limbo.limbo").addHandler(mhdr)
    limbo.init_plugins("test/plugins")
    mhdr.check("debug", "attaching message hook for echo")
Exemplo n.º 38
0
def test_run_hook():
    hooks = limbo.init_plugins("test/plugins")
    eq_(limbo.run_hook(hooks, "message", {"text": u"!echo bananas"}, None),
        [u"!echo bananas"])
Exemplo n.º 39
0
def test_run_hook():
    hooks = limbo.init_plugins("test/plugins")
    eq_(limbo.run_hook(hooks, "message", {"text": u"!echo bananas"}, None), [u"!echo bananas"])
Exemplo n.º 40
0
def test_missing_hook():
    hooks = limbo.init_plugins("test/plugins")
    eq_(limbo.run_hook(hooks, "nonexistant", {"text": u"!echo bananas"}, None), [])
Exemplo n.º 41
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    eq_(len(hooks), 0)