Example #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
Example #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
Example #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"
Example #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
Example #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
Example #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
Example #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)
Example #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)
Example #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)
Example #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
Example #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
Example #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)
Example #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)
Example #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)
Example #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
Example #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
Example #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"
Example #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
Example #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
Example #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)
Example #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)
Example #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)
Example #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"
Example #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)
Example #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"
Example #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)
Example #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"
Example #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)
Example #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
Example #30
0
def test_plugin_invalid_dir():
    try:
        limbo.init_plugins("invalid/package")
    except limbo.InvalidPluginDir:
        return
    1 / 0
Example #31
0
def test_missing_hook():
    hooks = limbo.init_plugins("test/plugins")
    eq_(limbo.run_hook(hooks, "nonexistant", {"text": u"!echo bananas"}, None),
        [])
Example #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")
Example #33
0
def test_plugin_invalid_dir():
    try:
        limbo.init_plugins("invalid/package")
    except limbo.InvalidPluginDir:
        return
    1 / 0
Example #34
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    assert len(hooks) == 0
Example #35
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    assert len(hooks) == 0
Example #36
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    eq_(len(hooks), 0)
Example #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")
Example #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"])
Example #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"])
Example #40
0
def test_missing_hook():
    hooks = limbo.init_plugins("test/plugins")
    eq_(limbo.run_hook(hooks, "nonexistant", {"text": u"!echo bananas"}, None), [])
Example #41
0
def test_config_plugin_doesnt_exist():
    hooks = limbo.init_plugins("test/plugins", "doesnotexist")
    eq_(len(hooks), 0)