示例#1
0
    def test_is_oper(self):
        tmp = IRCWrapper(nullLogger)
        tmp.channels["#tmp"] = Channel()
        tmp.channels["#tmp"].operdict["foobar"] = True

        assert tmp.is_oper("#tmp", "foobar") is True
        assert tmp.is_oper("#tmp", "quux") is False
    def test_is_oper(self):
        tmp = IRCWrapper(nullLogger)
        tmp.channels["#tmp"] = Channel()
        tmp.channels["#tmp"].operdict["foobar"] = True

        assert tmp.is_oper("#tmp", "foobar") is True
        assert tmp.is_oper("#tmp", "quux") is False
    def test_on_join(self):
        class Event(object):
            target = "#tmp"

        tmp = IRCWrapper(nullLogger)
        tmp.on_join(None, Event())

        # Just making sure this does not crash
        assert True
示例#4
0
    def test_on_join(self):
        class Event(object):
            target = "#tmp"

        tmp = IRCWrapper(nullLogger)
        tmp.on_join(None, Event())

        # Just making sure this does not crash
        assert True
示例#5
0
    def test_on_pubmsg(self):
        class EventSource(object):
            def __init__(self, nick=""):
                self.nick = nick

        class Event(object):
            def __init__(self, channel="", nick="", text=""):
                self.arguments = [text]
                self.target = channel
                self.source = EventSource(nick)

        class FakeSettings(object):
            QUEUE_DELAY = 1

        class FakeBot(object):
            data = None

            def irc_command(self, *args):
                self.data = args

            def chat_message(self, *args):
                pass

        bot = FakeBot()

        tmp = IRCWrapper(nullLogger, bot, FakeSettings())
        tmp.on_pubmsg(
            None,
            Event("#tmp", "foobar",
                  "Hello, world! I am a traveler looking for safety!"))

        assert bot.data is None

        tmp.on_pubmsg(None,
                      Event("#tmp", "foobar", "!hello can you hear me?"),
                      timestamp=1)

        expected = ("#tmp", "foobar", "hello", ["can", "you", "hear",
                                                "me?"], 1)

        self.assertEqual(bot.data, expected)

        tmp = IRCWrapper(nullLogger,
                         bot,
                         FakeSettings(),
                         commandPrefix="Hello, world!")
        tmp.on_pubmsg(None,
                      Event(
                          "#tmp", "foobar",
                          "Hello, world! I am a traveler looking for safety!"),
                      timestamp=1)

        expected = ("#tmp", "foobar", "i",
                    ["am", "a", "traveler", "looking", "for", "safety!"], 1)

        self.assertEqual(bot.data, expected)
    def test_on_welcome(self):
        expected = ["#foo", "#bar"]
        joinList = []

        class FakeConnection(object):
            def join(self, channel):
                joinList.append(channel)

        tmp = IRCWrapper(nullLogger, channelList=expected)
        tmp.on_welcome(FakeConnection(), None)

        self.assertEqual(joinList, expected)
示例#7
0
    def test_on_welcome(self):
        expected = ["#foo", "#bar"]
        joinList = []

        class FakeConnection(object):
            def join(self, channel):
                joinList.append(channel)

        tmp = IRCWrapper(nullLogger, channelList=expected)
        tmp.on_welcome(FakeConnection(), None)

        self.assertEqual(joinList, expected)
    def test__get_command(self):
        text = "!test command"

        tmp = IRCWrapper(nullLogger, commandPrefix="!")
        command, args = tmp._get_command(text)

        assert command == "test"
        self.assertEqual(args, ["command"])

        text = "#testing rare command prefix... here's the args"

        tmp = IRCWrapper(nullLogger, commandPrefix="#testing rare command "
                                                   "prefix")
        command, args = tmp._get_command(text)

        assert command == "..."
        self.assertEqual(args, ["here's", "the", "args"])

        # Just making sure this does not crash
        assert True
示例#9
0
    def test__get_command(self):
        text = "!test command"

        tmp = IRCWrapper(nullLogger, commandPrefix="!")
        command, args = tmp._get_command(text)

        assert command == "test"
        self.assertEqual(args, ["command"])

        text = "#testing rare command prefix... here's the args"

        tmp = IRCWrapper(nullLogger,
                         commandPrefix="#testing rare command "
                         "prefix")
        command, args = tmp._get_command(text)

        assert command == "..."
        self.assertEqual(args, ["here's", "the", "args"])

        # Just making sure this does not crash
        assert True
    def test_on_pubmsg(self):
        class EventSource(object):
            def __init__(self, nick=""):
                self.nick = nick

        class Event(object):
            def __init__(self, channel="", nick="", text=""):
                self.arguments = [text]
                self.target = channel
                self.source = EventSource(nick)

        class FakeSettings(object):
            QUEUE_DELAY = 1

        class FakeBot(object):
            data = None

            def irc_command(self, *args):
                self.data = args

            def chat_message(self, *args):
                pass

        bot = FakeBot()

        tmp = IRCWrapper(nullLogger, bot, FakeSettings())
        tmp.on_pubmsg(None, Event(
            "#tmp",
            "foobar",
            "Hello, world! I am a traveler looking for safety!"
        ))

        assert bot.data is None

        tmp.on_pubmsg(None, Event(
            "#tmp",
            "foobar",
            "!hello can you hear me?"
        ), timestamp=1)

        expected = (
            "#tmp",
            "foobar",
            "hello",
            ["can", "you", "hear", "me?"],
            1
        )

        self.assertEqual(bot.data, expected)

        tmp = IRCWrapper(
            nullLogger, bot, FakeSettings(), commandPrefix="Hello, world!"
        )
        tmp.on_pubmsg(None, Event(
            "#tmp",
            "foobar",
            "Hello, world! I am a traveler looking for safety!"
        ), timestamp=1)

        expected = (
            "#tmp",
            "foobar",
            "i",
            ["am", "a", "traveler", "looking", "for", "safety!"],
            1
        )

        self.assertEqual(bot.data, expected)