From 35f358cccfe49b7012b76665c80bcaa1e35e5b05 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 25 Oct 2015 20:46:29 +0100 Subject: [PATCH] [TASK] Tests for topic, TODO: refactor irc.Mode. --- piebot/irc.py | 3 ++- tests/test_message.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/piebot/irc.py b/piebot/irc.py index ee21e0d..a74a00b 100644 --- a/piebot/irc.py +++ b/piebot/irc.py @@ -239,13 +239,14 @@ class Part(Message, metaclass=register_derivative): self.message = self.get("trailing") class Mode(Message, metaclass=register_derivative): - def __init__(self, *args, **kwargs): + def __init__(self, subject="", modes=None, *args, **kwargs): super().__init__(*args, **kwargs) if "data" not in kwargs: self.update({ "command": "MODE", }) def parse(self): + #TODO: Implement this in a proper way! self.usermode = False self.source = self.get("nick") self.subject = self.get("params")[0] diff --git a/tests/test_message.py b/tests/test_message.py index 66f4edb..582c78b 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -116,3 +116,44 @@ class Message(unittest.TestCase): msg = irc.Part(channel="#tower", message="don't fall off") self.assertEqual(str(msg), "PART #tower :don't fall off") + + def test_parse_mode_usermode(self): + #TODO + raw = ":Me!~myself@localhost MODE Me :+ix" + msg = irc.Message.from_string(raw) + self.assertIsInstance(msg, irc.Mode, msg="Not a Mode!") + self.assertEqual(msg.usermode, True) + self.assertEqual(msg.flags, [('i', True), ('x', True)]) + self.assertEqual(msg.source, "Me") + self.assertEqual(msg.subject, "Me") + + def test_parse_mode_channelmode(self): + #TODO + raw = ":Mod!~moderator@ordering.chat MODE #botted +vo admin admin" + msg = irc.Message.from_string(raw) + self.assertIsInstance(msg, irc.Mode, msg="Not a Mode!") + self.assertEqual(msg.usermode, False) + self.assertEqual(msg.flags, [('v', True, 'admin'), ('o', True, 'admin')]) + self.assertEqual(msg.source, "Mod") + self.assertEqual(msg.subject, "#botted") + + def test_construct_mode_usermode(self): + #TODO + pass + + def test_construct_mode_channelmode(self): + #TODO + pass + + + def test_parse_topic(self): + raw = ":chanop!~important@guy.org TOPIC #couch :New Topic!" + msg = irc.Message.from_string(raw) + self.assertIsInstance(msg, irc.Topic, msg="Not a Topic!") + self.assertEqual(msg.source, "chanop") + self.assertEqual(msg.channel, "#couch") + self.assertEqual(msg.topic, "New Topic!") + + def test_construct_topic(self): + msg = irc.Topic(channel="#politics", topic="Yes, we can!") + self.assertEqual(str(msg), "TOPIC #politics :Yes, we can!") \ No newline at end of file