From ee804eeeb7fe86266c7caa3dfee3f15f960d0549 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 25 Oct 2015 20:08:09 +0100 Subject: [PATCH] [TASK] Add tests for join,part,kick. --- piebot/irc.py | 2 +- tests/test_message.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/piebot/irc.py b/piebot/irc.py index da3f364..ee21e0d 100644 --- a/piebot/irc.py +++ b/piebot/irc.py @@ -205,7 +205,7 @@ class Kick(Message, metaclass=register_derivative): "trailing": message }) def parse(self): - self.source = self.get("subject") + self.source = self.get("nick") self.channel = self.get("params")[0] self.target = self.get("params")[1] self.message = self.get("trailing") diff --git a/tests/test_message.py b/tests/test_message.py index cbe3124..66f4edb 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -77,3 +77,42 @@ class Message(unittest.TestCase): msg = irc.Notice(target="#somewhere", message="wheee eee!") self.assertEqual(str(msg), "NOTICE #somewhere :wheee eee!") + + def test_parse_kick(self): + raw = ":devil!~evil@guy.nl KICK #mods mike :damn it, mike!" + msg = irc.Message.from_string(raw) + self.assertIsInstance(msg, irc.Kick, msg="Not a Kick!") + self.assertEqual(msg.source, "devil") + self.assertEqual(msg.channel, "#mods") + self.assertEqual(msg.target, "mike") + self.assertEqual(msg.message, "damn it, mike!") + + def test_construct_kick(self): + msg = irc.Kick(channel="#lobby", user="annoying_guy", message="please leave") + self.assertEqual(str(msg), "KICK #lobby annoying_guy :please leave") + + + def test_parse_join(self): + raw = ":frank!~that@guy.again JOIN #lounge" + msg = irc.Message.from_string(raw) + self.assertIsInstance(msg, irc.Join, msg="Not a Join!") + self.assertEqual(msg.nick, "frank") + self.assertEqual(msg.channel, "#lounge") + + def test_construct_join(self): + msg = irc.Join(channel="#hiking") + self.assertEqual(str(msg), "JOIN :#hiking") + + + def test_parse_part(self): + raw = ":trump!~rich@billionaire.gold PART #society :suck it up" + msg = irc.Message.from_string(raw) + self.assertIsInstance(msg, irc.Part, msg="Not a Part!") + self.assertEqual(msg.nick, "trump") + self.assertEqual(msg.channel, "#society") + self.assertEqual(msg.message, "suck it up") + + def test_construct_part(self): + msg = irc.Part(channel="#tower", message="don't fall off") + self.assertEqual(str(msg), "PART #tower :don't fall off") +