3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 19:52:53 +01:00

pr/insp: more tests for hooks, etc

This commit is contained in:
James Lu 2015-07-07 20:59:35 -07:00
parent 0f03a2398b
commit 85e6a1aea2
2 changed files with 45 additions and 14 deletions

View File

@ -180,7 +180,7 @@ def handle_kill(irc, source, command, args):
irc.pseudoclient = spawnClient(irc, 'PyLink', 'pylink', irc.serverdata["hostname"])
for chan in irc.serverdata['channels']:
joinClient(irc, irc.pseudoclient.uid, chan)
return {'target': killed, 'reason': args[1]}
return {'target': killed, 'text': args[1]}
def handle_kick(irc, source, command, args):
# :70MAAAAAA KICK #endlessvoid 70MAAAAAA :some reason
@ -189,7 +189,7 @@ def handle_kick(irc, source, command, args):
handle_part(irc, kicked, 'KICK', [channel, args[2]])
if kicked == irc.pseudoclient.uid:
joinClient(irc, irc.pseudoclient.uid, channel)
return {'channel': channel, 'target': kicked, 'reason': args[2]}
return {'channel': channel, 'target': kicked, 'text': args[2]}
def handle_part(irc, source, command, args):
channel = args[0].lower()
@ -199,7 +199,7 @@ def handle_part(irc, source, command, args):
reason = args[1]
except IndexError:
reason = ''
return {'channel': channel, 'reason': reason}
return {'channel': channel, 'text': reason}
def handle_error(irc, numeric, command, args):
irc.connected = False
@ -218,14 +218,15 @@ def handle_fjoin(irc, servernumeric, command, args):
irc.name, channel, their_ts, our_ts)
irc.channels[channel].ts = their_ts
modestring = args[2:-1] or args[2]
utils.applyModes(irc, channel, utils.parseModes(irc, channel, modestring))
parsedmodes = utils.parseModes(irc, channel, modestring)
utils.applyModes(irc, channel, parsedmodes)
namelist = []
for user in userlist:
modeprefix, user = user.split(',', 1)
namelist.append(user)
utils.applyModes(irc, channel, [('+%s' % mode, user) for mode in modeprefix])
irc.channels[channel].users.add(user)
return {'channel': channel, 'users': namelist}
return {'channel': channel, 'users': namelist, 'modes': parsedmodes}
def handle_uid(irc, numeric, command, args):
# :70M UID 70MAAAAAB 1429934638 GL 0::1 hidden-7j810p.9mdf.lrek.0000.0000.IP gl 0::1 1429934638 +Wioswx +ACGKNOQXacfgklnoqvx :realname
@ -241,7 +242,7 @@ def handle_uid(irc, numeric, command, args):
def handle_quit(irc, numeric, command, args):
# <- :1SRAAGB4T QUIT :Quit: quit message goes here
removeClient(irc, numeric)
return {'reason': args[0]}
return {'text': args[0]}
def handle_burst(irc, numeric, command, args):
# BURST is sent by our uplink when we link.

View File

@ -154,10 +154,13 @@ class TestProtoInspIRCd(unittest.TestCase):
def testHandleKill(self):
self.irc.takeMsgs() # Ignore the initial connect messages
utils.add_hook(self.irc.dummyhook, 'KILL')
olduid = self.irc.pseudoclient.uid
self.irc.run(':{u} KILL {u} :killed'.format(u=olduid))
msgs = self.irc.takeMsgs()
commands = self.irc.takeCommands(msgs)
hookdata = self.irc.takeHooks()[0]
self.assertEqual({'target': olduid, 'text': 'killed'}, hookdata)
# Make sure we're respawning our PseudoClient when its killed
self.assertIn('UID', commands)
self.assertIn('FJOIN', commands)
@ -166,42 +169,56 @@ class TestProtoInspIRCd(unittest.TestCase):
def testHandleKick(self):
self.irc.takeMsgs() # Ignore the initial connect messages
utils.add_hook(self.irc.dummyhook, 'KICK')
self.irc.run(':{u} KICK #pylink {u} :kicked'.format(u=self.irc.pseudoclient.uid))
hookdata = self.irc.takeHooks()[0]
self.assertEqual({'target': self.u, 'text': 'kicked', 'channel': '#pylink'}, hookdata)
# Ditto above
msgs = self.irc.takeMsgs()
commands = self.irc.takeCommands(msgs)
self.assertIn('FJOIN', commands)
def testHandleFjoinUsers(self):
self.irc.run(':70M FJOIN #Chat 1423790411 + :,10XAAAAAA ,10XAAAAAB')
self.irc.run(':10X FJOIN #Chat 1423790411 + :,10XAAAAAA ,10XAAAAAB')
self.assertEqual({'10XAAAAAA', '10XAAAAAB'}, self.irc.channels['#chat'].users)
# self.assertIn('10XAAAAAB', self.irc.channels['#chat'].users)
# Sequential FJOINs must NOT remove existing users
self.irc.run(':70M FJOIN #Chat 1423790412 + :,10XAAAAAC')
self.irc.run(':10X FJOIN #Chat 1423790412 + :,10XAAAAAC')
# Join list can be empty too, in the case of permanent channels with 0 users.
self.irc.run(':70M FJOIN #Chat 1423790413 +nt :')
self.irc.run(':10X FJOIN #Chat 1423790413 +nt :')
def testHandleFjoinModes(self):
self.irc.run(':70M FJOIN #Chat 1423790411 +nt :,10XAAAAAA ,10XAAAAAB')
self.irc.run(':10X FJOIN #Chat 1423790411 +nt :,10XAAAAAA ,10XAAAAAB')
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
# Sequential FJOINs must NOT remove existing modes
self.irc.run(':70M FJOIN #Chat 1423790412 + :,10XAAAAAC')
self.irc.run(':10X FJOIN #Chat 1423790412 + :,10XAAAAAC')
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
def testHandleFjoinModesWithArgs(self):
self.irc.run(':70M FJOIN #Chat 1423790414 +nlks 10 t0psekrit :,10XAAAAAA ,10XAAAAAB')
self.irc.run(':10X FJOIN #Chat 1423790414 +nlks 10 t0psekrit :,10XAAAAAA ,10XAAAAAB')
self.assertEqual({('n', None), ('s', None), ('l', '10'), ('k', 't0psekrit')},
self.irc.channels['#chat'].modes)
def testHandleFjoinPrefixes(self):
self.irc.run(':70M FJOIN #Chat 1423790418 +nt :ov,10XAAAAAA v,10XAAAAAB ,10XAAAAAC')
self.irc.run(':10X FJOIN #Chat 1423790418 +nt :ov,10XAAAAAA v,10XAAAAAB ,10XAAAAAC')
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
self.assertEqual({'10XAAAAAA', '10XAAAAAB', '10XAAAAAC'}, self.irc.channels['#chat'].users)
self.assertIn('10XAAAAAA', self.irc.channels['#chat'].prefixmodes['ops'])
self.assertEqual({'10XAAAAAA', '10XAAAAAB'}, self.irc.channels['#chat'].prefixmodes['voices'])
def testHandleFjoinHook(self):
utils.add_hook(self.irc.dummyhook, 'JOIN')
self.irc.run(':10X FJOIN #PyLink 1423790418 +ls 10 :ov,10XAAAAAA v,10XAAAAAB ,10XAAAAAC')
hookdata = self.irc.takeHooks()[0]
expected = {'modes': [('+l', '10'), ('+s', None)],
'channel': '#pylink',
'users': ['10XAAAAAA', '10XAAAAAB', '10XAAAAAC']}
self.assertEqual(expected, hookdata)
def testHandleFmode(self):
self.irc.run(':70M FJOIN #pylink 1423790411 +n :o,10XAAAAAA ,10XAAAAAB')
# utils.add_hook(self.irc.dummyhook, 'MODE')
self.irc.run(':10X FJOIN #pylink 1423790411 +n :o,10XAAAAAA ,10XAAAAAB')
self.irc.run(':70M FMODE #pylink 1423790412 +ikl herebedragons 100')
self.assertEqual({('i', None), ('k', 'herebedragons'), ('l', '100'), ('n', None)}, self.irc.channels['#pylink'].modes)
self.irc.run(':70M FMODE #pylink 1423790413 -ilk+m herebedragons')
@ -248,5 +265,18 @@ class TestProtoInspIRCd(unittest.TestCase):
self.assertEqual(hookdata['topic'], 'test')
self.assertEqual(hookdata['channel'], '#pylink')
def testMsgHooks(self):
for m in ('NOTICE', 'PRIVMSG'):
utils.add_hook(self.irc.dummyhook, m)
self.irc.run(':70MAAAAAA %s #dev :afasfsa' % m)
hookdata = self.irc.takeHooks()[0]
self.assertEqual({'target': '#dev', 'text': 'afasfsa'}, hookdata)
def testHandlePart(self):
utils.add_hook(self.irc.dummyhook, 'PART')
self.irc.run(':9PYAAAAAA PART #pylink')
hookdata = self.irc.takeHooks()[0]
self.assertEqual({'channel': '#pylink', 'text': ''}, hookdata)
if __name__ == '__main__':
unittest.main()