Exemplo n.º 1
0
    def test_wrapper_no_permissions(self):
        global called
        called = False

        def func(*args, **kwargs):
            global called
            called = True

        wrapped_func = irc_admin.admin_command_handler(lambda x: False, func)
        self.patch_connect()
        b = irc.IrcBot("irc.example.com", "TulipBot", loop=self.loop)

        self.assertRaises(PermissionError, wrapped_func, b, irc.command.Command("Nick", "test", "target", []))
        self.assertFalse(called)
Exemplo n.º 2
0
    def test_wrapper_with_permissions(self):
        # TODO find better way to store called state
        global called
        called = False

        @asyncio.coroutine
        def func(*args, **kwargs):
            global called
            called = True

        wrapped_func = irc_admin.admin_command_handler(lambda x: True, func)
        self.patch_connect()
        b = irc.IrcBot("irc.example.com", "TulipBot", loop=self.loop)
        wf_task = asyncio.Task(wrapped_func(b, irc.command.Command("Nick", "test", "target", [])), loop=self.loop)
        self.loop.run_until_complete(wf_task)
        self.assertTrue(called)