示例#1
0
def test_plugin_logs():
    tfh = tempfile.NamedTemporaryFile()

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

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

    assert "DEBUG:plugin: test/plugins/echo.py" in log
    assert "DEBUG:attaching plugins." in log
示例#2
0
def test_handle_message_basic():
    client = FakeClient()

    msg = u"Iñtërnâtiônàlizætiøn"
    event = {"user": "******", "text": msg}

    hooks = slask.init_plugins("test/plugins")
    eq_(slask.handle_message(client, event, hooks, None), msg)
示例#3
0
def test_plugin_success():
    hooks = slask.init_plugins("test/plugins")
    eq_( len(hooks) ,  1)
    assert "message" in hooks
    assert isinstance(hooks, dict)
    assert isinstance(hooks["message"], list)
    eq_( len(hooks["message"]) ,  1)
    eq_( hooks["message"][0]({"text": u"bananas"}, None) ,  u"bananas")
示例#4
0
def test_missing_hook():
    hooks = slask.init_plugins("test/plugins")
    eq_(slask.run_hook(hooks, "nonexistant", {"text": u"bananas"}, None), [])
示例#5
0
def test_run_hook():
    hooks = slask.init_plugins("test/plugins")
    eq_(slask.run_hook(hooks, "message", {"text": u"bananas"}, None), [u"bananas"])
示例#6
0
def test_plugin_invalid_dir():
    hooks = slask.init_plugins("invalid/package")
    eq_( len(hooks) ,  0)