def test_storage(): app, __, __ = make_kutana_no_run() pl = Plugin("", storage={}) pl.app = app assert pl.storage == {} pl = Plugin("", storage='default') pl.app = app assert pl.storage == app._storages['default'] pl = Plugin("", storage='unknown') pl.app = app assert pl.storage is None
def test_receiver_states(): app, debug, hu = make_kutana_no_run() pl = Plugin("") pl.app = app @pl.on_commands(["a"]) @pl.expect_receiver(state="") async def __(msg, ctx): await ctx.receiver.update({"state": "state"}) await ctx.reply("ok:a") @pl.on_commands(["b"]) @pl.expect_receiver(state="state") async def __(msg, ctx): await ctx.receiver.update({"state": ""}) await ctx.reply("ok:b") @pl.on_commands(["a"]) @pl.expect_receiver(state="other_state") async def __(msg, ctx): await ctx.receiver.update({"state": ""}) await ctx.reply("ok:b") app.add_plugin(pl) hu(Message(None, UpdateType.MSG, ".a", (), 1, 0, 0, 0, {})) hu(Message(None, UpdateType.MSG, ".b", (), 1, 0, 0, 0, {})) hu(Message(None, UpdateType.MSG, ".b", (), 1, 0, 0, 0, {})) hu(Message(None, UpdateType.MSG, ".a", (), 1, 0, 0, 0, {})) assert len(debug.answers[1]) == 3 assert debug.answers[1].count(("ok:a", (), {})) == 2 assert debug.answers[1].count(("ok:b", (), {})) == 1 assert debug.answers[1][-1] == ("ok:a", (), {})
def test_on_start(): pl = Plugin("API") pl.app = 2 @pl.on_start() async def __(): return 1 # Deprecated version @pl.on_start() async def __(app): return app assert sync(pl._handlers['start'][0].handle()) == 1 assert sync(pl._handlers['start'][1].handle()) == 2