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
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)
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")
def test_missing_hook(): hooks = slask.init_plugins("test/plugins") eq_(slask.run_hook(hooks, "nonexistant", {"text": u"bananas"}, None), [])
def test_run_hook(): hooks = slask.init_plugins("test/plugins") eq_(slask.run_hook(hooks, "message", {"text": u"bananas"}, None), [u"bananas"])
def test_plugin_invalid_dir(): hooks = slask.init_plugins("invalid/package") eq_( len(hooks) , 0)