Beispiel #1
0
    def test_command(self):
        self.assertEqual(len(pluginmanager._callbacks), 0)

        util.command(f)

        self.assertEqual(len(pluginmanager._callbacks), 1)
        self.assertTrue("f" in pluginmanager._callbacks)
Beispiel #2
0
    def test_command(self):
        self.assertEqual(len(util._PM._callbacks), 0)

        util.command(f)

        self.assertEqual(len(util._PM._callbacks), 1)
        self.assertTrue("f" in util._PM._callbacks)
Beispiel #3
0
    def test_command_aliases(self):
        self.assertEqual(len(pluginmanager._callbacks), 0)

        util.command(f, aliases=["foo", "bar"])

        self.assertTrue("Aliases: foo, bar" in pluginmanager._callbacks["f"].func.__doc__)
        self.assertTrue("foo" in pluginmanager._callbacks.keys())
        self.assertTrue("bar" in pluginmanager._callbacks.keys())
        self.assertEqual(pluginmanager._callbacks["foo"], pluginmanager._callbacks["bar"])
        self.assertEqual(pluginmanager._callbacks["f"], pluginmanager._callbacks["bar"])
Beispiel #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)
Beispiel #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)
Beispiel #6
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")
Beispiel #7
0
    def test_named_command(self):
        self.assertEqual(len(pluginmanager._callbacks), 0)

        c = util.command("command")
        c(f)

        self.assertEqual(len(pluginmanager._callbacks), 1)
        self.assertTrue("command" in pluginmanager._callbacks)
Beispiel #8
0
    def test_named_command(self):
        self.assertEqual(len(util._PM._callbacks), 0)

        c = util.command("command")
        c(f)

        self.assertEqual(len(util._PM._callbacks), 1)
        self.assertTrue("command" in util._PM._callbacks)
Beispiel #9
0
    def test_reenabled_command(self):
        c = util.command("command", aliases=["foo"])
        c(f3)

        pluginmanager.disable("command")
        pluginmanager.enable("command")
        self.assertTrue(pluginmanager._callbacks["command"].enabled)
        self.assertTrue(pluginmanager._callbacks["foo"].enabled)
        self.assertRaises(ValueError, pluginmanager._handle_message, "user",
        "channel", "!command")
Beispiel #10
0
 def test_command_aliases(self):
     c = util.command(aliases=["foo", "bar"])
     c(f)
     lala.pluginmanager.register_callback.assert_called_once_with("f", f, False, ["foo", "bar"])
Beispiel #11
0
 def test_named_command(self):
     c = util.command("command")
     c(f)
     lala.pluginmanager.register_callback.assert_called_once_with("command", f, False, None)
Beispiel #12
0
 def test_command(self):
     util.command(f)
     lala.pluginmanager.register_callback.assert_called_once_with("f", f, False, None)
Beispiel #13
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")
Beispiel #14
0
 def test_named_command(self):
     c = util.command("command")
     c(f)
     util._PM.register_callback.assert_called_once_with("command", f)
Beispiel #15
0
 def test_command(self):
     util.command(f)
     util._PM.register_callback.assert_called_once_with("f", f)