mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-28 05:29:25 +01:00
pr/insp: more tests for hooks, etc
This commit is contained in:
parent
0f03a2398b
commit
85e6a1aea2
@ -180,7 +180,7 @@ def handle_kill(irc, source, command, args):
|
|||||||
irc.pseudoclient = spawnClient(irc, 'PyLink', 'pylink', irc.serverdata["hostname"])
|
irc.pseudoclient = spawnClient(irc, 'PyLink', 'pylink', irc.serverdata["hostname"])
|
||||||
for chan in irc.serverdata['channels']:
|
for chan in irc.serverdata['channels']:
|
||||||
joinClient(irc, irc.pseudoclient.uid, chan)
|
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):
|
def handle_kick(irc, source, command, args):
|
||||||
# :70MAAAAAA KICK #endlessvoid 70MAAAAAA :some reason
|
# :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]])
|
handle_part(irc, kicked, 'KICK', [channel, args[2]])
|
||||||
if kicked == irc.pseudoclient.uid:
|
if kicked == irc.pseudoclient.uid:
|
||||||
joinClient(irc, irc.pseudoclient.uid, channel)
|
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):
|
def handle_part(irc, source, command, args):
|
||||||
channel = args[0].lower()
|
channel = args[0].lower()
|
||||||
@ -199,7 +199,7 @@ def handle_part(irc, source, command, args):
|
|||||||
reason = args[1]
|
reason = args[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
reason = ''
|
reason = ''
|
||||||
return {'channel': channel, 'reason': reason}
|
return {'channel': channel, 'text': reason}
|
||||||
|
|
||||||
def handle_error(irc, numeric, command, args):
|
def handle_error(irc, numeric, command, args):
|
||||||
irc.connected = False
|
irc.connected = False
|
||||||
@ -218,14 +218,15 @@ def handle_fjoin(irc, servernumeric, command, args):
|
|||||||
irc.name, channel, their_ts, our_ts)
|
irc.name, channel, their_ts, our_ts)
|
||||||
irc.channels[channel].ts = their_ts
|
irc.channels[channel].ts = their_ts
|
||||||
modestring = args[2:-1] or args[2]
|
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 = []
|
namelist = []
|
||||||
for user in userlist:
|
for user in userlist:
|
||||||
modeprefix, user = user.split(',', 1)
|
modeprefix, user = user.split(',', 1)
|
||||||
namelist.append(user)
|
namelist.append(user)
|
||||||
utils.applyModes(irc, channel, [('+%s' % mode, user) for mode in modeprefix])
|
utils.applyModes(irc, channel, [('+%s' % mode, user) for mode in modeprefix])
|
||||||
irc.channels[channel].users.add(user)
|
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):
|
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
|
# :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):
|
def handle_quit(irc, numeric, command, args):
|
||||||
# <- :1SRAAGB4T QUIT :Quit: quit message goes here
|
# <- :1SRAAGB4T QUIT :Quit: quit message goes here
|
||||||
removeClient(irc, numeric)
|
removeClient(irc, numeric)
|
||||||
return {'reason': args[0]}
|
return {'text': args[0]}
|
||||||
|
|
||||||
def handle_burst(irc, numeric, command, args):
|
def handle_burst(irc, numeric, command, args):
|
||||||
# BURST is sent by our uplink when we link.
|
# BURST is sent by our uplink when we link.
|
||||||
|
@ -154,10 +154,13 @@ class TestProtoInspIRCd(unittest.TestCase):
|
|||||||
|
|
||||||
def testHandleKill(self):
|
def testHandleKill(self):
|
||||||
self.irc.takeMsgs() # Ignore the initial connect messages
|
self.irc.takeMsgs() # Ignore the initial connect messages
|
||||||
|
utils.add_hook(self.irc.dummyhook, 'KILL')
|
||||||
olduid = self.irc.pseudoclient.uid
|
olduid = self.irc.pseudoclient.uid
|
||||||
self.irc.run(':{u} KILL {u} :killed'.format(u=olduid))
|
self.irc.run(':{u} KILL {u} :killed'.format(u=olduid))
|
||||||
msgs = self.irc.takeMsgs()
|
msgs = self.irc.takeMsgs()
|
||||||
commands = self.irc.takeCommands(msgs)
|
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
|
# Make sure we're respawning our PseudoClient when its killed
|
||||||
self.assertIn('UID', commands)
|
self.assertIn('UID', commands)
|
||||||
self.assertIn('FJOIN', commands)
|
self.assertIn('FJOIN', commands)
|
||||||
@ -166,42 +169,56 @@ class TestProtoInspIRCd(unittest.TestCase):
|
|||||||
|
|
||||||
def testHandleKick(self):
|
def testHandleKick(self):
|
||||||
self.irc.takeMsgs() # Ignore the initial connect messages
|
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))
|
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
|
# Ditto above
|
||||||
msgs = self.irc.takeMsgs()
|
msgs = self.irc.takeMsgs()
|
||||||
commands = self.irc.takeCommands(msgs)
|
commands = self.irc.takeCommands(msgs)
|
||||||
self.assertIn('FJOIN', commands)
|
self.assertIn('FJOIN', commands)
|
||||||
|
|
||||||
def testHandleFjoinUsers(self):
|
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.assertEqual({'10XAAAAAA', '10XAAAAAB'}, self.irc.channels['#chat'].users)
|
||||||
# self.assertIn('10XAAAAAB', self.irc.channels['#chat'].users)
|
# self.assertIn('10XAAAAAB', self.irc.channels['#chat'].users)
|
||||||
# Sequential FJOINs must NOT remove existing 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.
|
# 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):
|
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)
|
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
|
||||||
# Sequential FJOINs must NOT remove existing 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)
|
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
|
||||||
|
|
||||||
def testHandleFjoinModesWithArgs(self):
|
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.assertEqual({('n', None), ('s', None), ('l', '10'), ('k', 't0psekrit')},
|
||||||
self.irc.channels['#chat'].modes)
|
self.irc.channels['#chat'].modes)
|
||||||
|
|
||||||
def testHandleFjoinPrefixes(self):
|
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({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
|
||||||
self.assertEqual({'10XAAAAAA', '10XAAAAAB', '10XAAAAAC'}, self.irc.channels['#chat'].users)
|
self.assertEqual({'10XAAAAAA', '10XAAAAAB', '10XAAAAAC'}, self.irc.channels['#chat'].users)
|
||||||
self.assertIn('10XAAAAAA', self.irc.channels['#chat'].prefixmodes['ops'])
|
self.assertIn('10XAAAAAA', self.irc.channels['#chat'].prefixmodes['ops'])
|
||||||
self.assertEqual({'10XAAAAAA', '10XAAAAAB'}, self.irc.channels['#chat'].prefixmodes['voices'])
|
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):
|
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.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.assertEqual({('i', None), ('k', 'herebedragons'), ('l', '100'), ('n', None)}, self.irc.channels['#pylink'].modes)
|
||||||
self.irc.run(':70M FMODE #pylink 1423790413 -ilk+m herebedragons')
|
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['topic'], 'test')
|
||||||
self.assertEqual(hookdata['channel'], '#pylink')
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user