Exemplo n.º 1
0
 def test_regex_called(self):
     mocked_f = mock.Mock(spec=f)
     pluginmanager.register_regex(compile("test"), mocked_f)
     pluginmanager._handle_message("user", "channel", "regex")
     self.assertFalse(mocked_f.called)
     pluginmanager._handle_message("user", "channel", "test foobar")
     self.assertTrue(mocked_f.called)
Exemplo n.º 2
0
    def test_disabled_regex(self):
        regex = compile("command")
        c = util.regex(regex)
        c(regex_f)

        pluginmanager.disable(regex.pattern)
        self.assertFalse(pluginmanager._regexes[regex].enabled)
        pluginmanager._handle_message("user", "channel", "command")
Exemplo n.º 3
0
    def test_disabled_command(self):
        c = util.command("command", aliases=["foo"])
        c(f3)

        pluginmanager.disable("command")
        self.assertFalse(pluginmanager._callbacks["command"].enabled)
        self.assertFalse(pluginmanager._callbacks["foo"].enabled)
        pluginmanager._handle_message("user", "channel", "!command")
Exemplo n.º 4
0
    def test_automatically_adds_errbacks_deferred(self, mock):
        d = Deferred()

        def return_deferred(u, c, t):
            return d

        util.command(command="mock")(return_deferred)
        f = Failure(ValueError(""))
        pluginmanager._handle_message("gandalf", "#channel", "!mock")
        d.errback(f)
        mock.assert_called_once_with("gandalf", "#channel", f)
Exemplo n.º 5
0
    def test_automatically_adds_errbacks_multiple_deferreds(self, errb):
        ds = [Deferred(), Deferred()]

        def return_deferred(u, c, t):
            for d in ds:
                yield d

        util.command(command="errb")(return_deferred)
        f = Failure(ValueError(""))
        pluginmanager._handle_message("gandalf", "#channel", "!errb")
        for d in ds:
            d.errback(f)
        self.assertEqual(errb.call_count, 2)
        c = [mock.call("gandalf", "#channel", f)] * 2
        self.assertEqual(c, errb.call_args_list)
Exemplo n.º 6
0
    def test_admin_only_command_as_non_admin(self, mock):
        util._BOT.factory.nspassword = None
        mock.return_value = "superman"

        util.command(command="mock", admin_only=True)(f3)
        pluginmanager._handle_message("gandalf", "#channel", "!mock")
Exemplo n.º 7
0
 def test_message_called(self):
     mocked_f = mock.Mock(spec=f)
     pluginmanager.register_callback("test", mocked_f)
     pluginmanager._handle_message("user", "channel", "!test")
     mocked_f.assert_called_once_with("user", "channel", "")