From b6f489fa9c5ed7b8f9d7e461781e11ab69084137 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 4 Jul 2015 12:34:33 -0700 Subject: [PATCH] add tests for KILL, KICK, UID, and SERVER handlers todo: rewrite the MODE handling so it doesn't suck, and test those too --- protocols/inspircd.py | 2 +- tests/test_proto_common.py | 6 +++++- tests/test_proto_inspircd.py | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/protocols/inspircd.py b/protocols/inspircd.py index 662d24d..d199c9c 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -187,7 +187,7 @@ def handle_kick(irc, source, command, args): channel = args[0] channel = channel.lower() kicked = args[1] - irc.channels[channel].users.discard(kicked) + handle_part(irc, kicked, 'KICK', [channel, args[2]]) if kicked == irc.pseudoclient.uid: joinClient(irc, irc.pseudoclient.uid, channel) diff --git a/tests/test_proto_common.py b/tests/test_proto_common.py index 3b2a265..e4d6d5d 100644 --- a/tests/test_proto_common.py +++ b/tests/test_proto_common.py @@ -83,8 +83,12 @@ class Test_TestProtoCommon(unittest.TestCase): msgs = self.irc.takeMsgs() self.assertEqual(['ADD this message', ':add THIS message too'], msgs) + # takeMsgs() clears cached messages queue, so the next call should + # return an empty list. + msgs = self.irc.takeMsgs() + self.assertEqual([], msgs) - def testFakeIRC_takeMsgs(self): + def testFakeIRCtakeCommands(self): msgs = ['ADD this message', ':9PY THIS message too'] self.assertEqual(['ADD', 'THIS'], self.irc.takeCommands(msgs)) diff --git a/tests/test_proto_inspircd.py b/tests/test_proto_inspircd.py index e58b846..56f79a3 100644 --- a/tests/test_proto_inspircd.py +++ b/tests/test_proto_inspircd.py @@ -32,7 +32,7 @@ class TestInspIRCdProtocol(unittest.TestCase): self.assertIn('UID', commands) self.assertIn('FJOIN', commands) - def test_checkRecvpass(self): + def testCheckRecvpass(self): # Correct recvpass here. self.irc.run('SERVER somehow.someday abcd 0 0AL :Somehow Server - McMurdo Station, Antarctica') # Incorrect recvpass here; should raise ProtocolError. @@ -135,5 +135,38 @@ class TestInspIRCdProtocol(unittest.TestCase): self.assertIn('SQUIT', self.irc.takeCommands(self.irc.takeMsgs())) self.assertNotIn('34P', self.irc.servers) + def testHandleServer(self): + self.irc.run('SERVER whatever.net abcd 0 10X :something') + self.assertIn('10X', self.irc.servers) + self.assertEqual('whatever.net', self.irc.servers['10X'].name) + self.irc.run(':10X SERVER test.server * 1 0AL :testing raw message syntax') + self.assertIn('0AL', self.irc.servers) + self.assertEqual('test.server', self.irc.servers['0AL'].name) + + def testHandleUID(self): + self.irc.run('SERVER whatever.net abcd 0 10X :something') + self.irc.run(':10X UID 10XAAAAAB 1429934638 GL 0::1 hidden-7j810p.9mdf.lrek.0000.0000.IP gl 0::1 1429934638 +Wioswx +ACGKNOQXacfgklnoqvx :realname') + self.assertIn('10XAAAAAB', self.irc.servers['10X'].users) + self.assertIn('10XAAAAAB', self.irc.users) + u = self.irc.users['10XAAAAAB'] + self.assertEqual('GL', u.nick) + + def testHandleKill(self): + self.irc.takeMsgs() # Ignore the initial connect messages + self.irc.run(':9PYAAAAAA KILL 9PYAAAAAA :killed') + msgs = self.irc.takeMsgs() + commands = self.irc.takeCommands(msgs) + # Make sure we're respawning our PseudoClient when its killed + self.assertIn('UID', commands) + self.assertIn('FJOIN', commands) + + def testHandleKick(self): + self.irc.takeMsgs() # Ignore the initial connect messages + self.irc.run(':9PYAAAAAA KICK #pylink 9PYAAAAAA :kicked') + # Ditto above + msgs = self.irc.takeMsgs() + commands = self.irc.takeCommands(msgs) + self.assertIn('FJOIN', commands) + if __name__ == '__main__': unittest.main()