3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

add tests for KILL, KICK, UID, and SERVER handlers

todo: rewrite the MODE handling so it doesn't suck, and test those too
This commit is contained in:
James Lu 2015-07-04 12:34:33 -07:00
parent 8ea62c31de
commit b6f489fa9c
3 changed files with 40 additions and 3 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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()