[TASK] Tests for topic, TODO: refactor irc.Mode.

This commit is contained in:
Jan Philipp Timme 2015-10-25 20:46:29 +01:00
parent ee804eeeb7
commit 35f358cccf
2 changed files with 43 additions and 1 deletions

View File

@ -239,13 +239,14 @@ class Part(Message, metaclass=register_derivative):
self.message = self.get("trailing") self.message = self.get("trailing")
class Mode(Message, metaclass=register_derivative): class Mode(Message, metaclass=register_derivative):
def __init__(self, *args, **kwargs): def __init__(self, subject="", modes=None, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if "data" not in kwargs: if "data" not in kwargs:
self.update({ self.update({
"command": "MODE", "command": "MODE",
}) })
def parse(self): def parse(self):
#TODO: Implement this in a proper way!
self.usermode = False self.usermode = False
self.source = self.get("nick") self.source = self.get("nick")
self.subject = self.get("params")[0] self.subject = self.get("params")[0]

View File

@ -116,3 +116,44 @@ class Message(unittest.TestCase):
msg = irc.Part(channel="#tower", message="don't fall off") msg = irc.Part(channel="#tower", message="don't fall off")
self.assertEqual(str(msg), "PART #tower :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!")