Ejemplo n.º 1
0
    def test_plugin_with_exception_callback(self):
        plugin = Plugin(exceptions=0)

        async def on_processed(message, env):
            if env.exception:
                plugin.exceptions += 1

        plugin.on_after_processed()(on_processed)

        async def on_has_text(message, env):
            raise Exception

        plugin.on_has_text()(on_has_text)

        app = Kutana()

        app.register_plugins([plugin])

        loop = asyncio.get_event_loop()

        set_logger_level(logging.CRITICAL)

        loop.run_until_complete(app.process(DebugManager(), "message"))

        set_logger_level(logging.ERROR)

        self.assertEqual(plugin.exceptions, 1)
Ejemplo n.º 2
0
    def test_plugin_on_after_processed(self):
        plugin = Plugin()

        plugin.on_after_processed(messages=True, updates=False)(1)

        self.assertTrue(plugin._callbacks)
        self.assertFalse(plugin._callbacks_raw)

        plugin = Plugin()

        plugin.on_after_processed(messages=False, updates=True)(1)

        self.assertFalse(plugin._callbacks)
        self.assertTrue(plugin._callbacks_raw)

        plugin = Plugin()

        plugin.on_after_processed(messages=True, updates=True)(1)

        self.assertTrue(plugin._callbacks)
        self.assertTrue(plugin._callbacks_raw)
Ejemplo n.º 3
0
    def test_plugin_on_after_processed_exception(self):
        plugin = Plugin()

        with self.assertRaises(ValueError):
            plugin.on_after_processed(messages=False, updates=False)