mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Fix those test cases again.
This commit is contained in:
parent
6c503b3603
commit
3217f726f8
27
classes.py
27
classes.py
@ -391,29 +391,22 @@ class Protocol():
|
||||
self.casemapping = 'rfc1459'
|
||||
self.hook_map = {}
|
||||
|
||||
class FakeProto():
|
||||
class FakeProto(Protocol):
|
||||
"""Dummy protocol module for testing purposes."""
|
||||
def __init__(self):
|
||||
self.hook_map = {}
|
||||
self.casemapping = 'rfc1459'
|
||||
self.__name__ = 'FakeProto'
|
||||
|
||||
@staticmethod
|
||||
def handle_events(irc, data):
|
||||
def handle_events(self, data):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def connect(irc):
|
||||
def connect(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def spawnClient(irc, nick, *args, **kwargs):
|
||||
def spawnClient(self, nick, *args, **kwargs):
|
||||
uid = randint(1, 10000000000)
|
||||
ts = int(time.time())
|
||||
irc.users[uid] = user = IrcUser(nick, ts, uid)
|
||||
self.irc.users[uid] = user = IrcUser(nick, ts, uid)
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def joinClient(irc, client, channel):
|
||||
irc.channels[channel].users.add(client)
|
||||
irc.users[client].channels.add(channel)
|
||||
def joinClient(self, client, channel):
|
||||
self.irc.channels[channel].users.add(client)
|
||||
self.irc.users[client].channels.add(channel)
|
||||
|
||||
FakeProto.Class = FakeProto
|
||||
|
@ -29,7 +29,7 @@ class CorePluginTestCase(tests_common.PluginTestCase):
|
||||
self.assertNotEqual(self.irc.pseudoclient.uid, spmain[0]['olduser'])
|
||||
|
||||
def testKickrejoin(self):
|
||||
self.proto.kickClient(self.irc, self.u, '#pylink', self.u, 'test')
|
||||
self.proto.kickClient(self.u, '#pylink', self.u, 'test')
|
||||
msgs = self.irc.takeMsgs()
|
||||
commands = self.irc.takeCommands(msgs)
|
||||
self.assertIn('FJOIN', commands)
|
||||
|
@ -7,7 +7,7 @@ import unittest
|
||||
|
||||
class TestFakeIRC(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.irc = classes.FakeIRC('unittest', classes.FakeProto())
|
||||
self.irc = classes.FakeIRC('unittest', classes.FakeProto)
|
||||
|
||||
def testFakeIRC(self):
|
||||
self.irc.run('this should do nothing')
|
||||
|
@ -19,7 +19,7 @@ class InspIRCdTestCase(tests_common.CommonProtoTestCase):
|
||||
self.assertRaises(classes.ProtocolError, self.irc.run, 'SERVER somehow.someday BADPASS 0 0AL :Somehow Server - McMurdo Station, Antarctica')
|
||||
|
||||
def testConnect(self):
|
||||
self.proto.connect(self.irc)
|
||||
self.proto.connect()
|
||||
initial_messages = self.irc.takeMsgs()
|
||||
commands = self.irc.takeCommands(initial_messages)
|
||||
# SERVER pylink.unittest abcd 0 9PY :PyLink Service
|
||||
@ -40,20 +40,20 @@ class InspIRCdTestCase(tests_common.CommonProtoTestCase):
|
||||
|
||||
def testHandleSQuit(self):
|
||||
# Spawn a messy network map, just because!
|
||||
self.proto.spawnServer(self.irc, 'level1.pylink', '34P')
|
||||
self.proto.spawnServer(self.irc, 'level2.pylink', '34Q', uplink='34P')
|
||||
self.proto.spawnServer(self.irc, 'level3.pylink', '34Z', uplink='34Q')
|
||||
self.proto.spawnServer(self.irc, 'level4.pylink', '34Y', uplink='34Z')
|
||||
self.proto.spawnServer('level1.pylink', '34P')
|
||||
self.proto.spawnServer('level2.pylink', '34Q', uplink='34P')
|
||||
self.proto.spawnServer('level3.pylink', '34Z', uplink='34Q')
|
||||
self.proto.spawnServer('level4.pylink', '34Y', uplink='34Z')
|
||||
self.assertEqual(self.irc.servers['34Y'].uplink, '34Z')
|
||||
s4u = self.proto.spawnClient(self.irc, 'person1', 'person', 'users.overdrive.pw', server='34Y').uid
|
||||
s3u = self.proto.spawnClient(self.irc, 'person2', 'person', 'users.overdrive.pw', server='34Z').uid
|
||||
self.proto.joinClient(self.irc, s3u, '#pylink')
|
||||
self.proto.joinClient(self.irc, s4u, '#pylink')
|
||||
s4u = self.proto.spawnClient('person1', 'person', 'users.overdrive.pw', server='34Y').uid
|
||||
s3u = self.proto.spawnClient('person2', 'person', 'users.overdrive.pw', server='34Z').uid
|
||||
self.proto.joinClient(s3u, '#pylink')
|
||||
self.proto.joinClient(s4u, '#pylink')
|
||||
self.irc.run(':34Z SQUIT 34Y :random squit messsage')
|
||||
self.assertNotIn(s4u, self.irc.users)
|
||||
self.assertNotIn('34Y', self.irc.servers)
|
||||
# Netsplits are obviously recursive, so all these should be removed.
|
||||
self.proto.handle_squit(self.irc, '9PY', 'SQUIT', ['34P'])
|
||||
self.proto.handle_squit('9PY', 'SQUIT', ['34P'])
|
||||
self.assertNotIn(s3u, self.irc.users)
|
||||
self.assertNotIn('34P', self.irc.servers)
|
||||
self.assertNotIn('34Q', self.irc.servers)
|
||||
@ -136,11 +136,16 @@ class InspIRCdTestCase(tests_common.CommonProtoTestCase):
|
||||
self.assertEqual(expected, hookdata)
|
||||
|
||||
def testHandleFMode(self):
|
||||
# Default channels start with +nt
|
||||
self.irc.run(':70M FMODE #pylink 1423790412 -nt')
|
||||
self.assertEqual(set(), self.irc.channels['#pylink'].modes)
|
||||
self.irc.takeHooks()
|
||||
|
||||
self.irc.run(':70M FMODE #pylink 1423790412 +ikl herebedragons 100')
|
||||
self.assertEqual({('i', None), ('k', 'herebedragons'), ('l', '100')}, self.irc.channels['#pylink'].modes)
|
||||
self.irc.run(':70M FMODE #pylink 1423790413 -ilk+m herebedragons')
|
||||
self.assertEqual({('m', None)}, self.irc.channels['#pylink'].modes)
|
||||
|
||||
|
||||
hookdata = self.irc.takeHooks()
|
||||
expected = [['70M', 'FMODE', {'target': '#pylink', 'modes':
|
||||
[('+i', None), ('+k', 'herebedragons'),
|
||||
@ -175,9 +180,10 @@ class InspIRCdTestCase(tests_common.CommonProtoTestCase):
|
||||
|
||||
def testHandleFModeRemovesOldParams(self):
|
||||
self.irc.run(':70M FMODE #pylink 1423790412 +l 50')
|
||||
self.assertEqual({('l', '50')}, self.irc.channels['#pylink'].modes)
|
||||
self.assertIn(('l', '50'), self.irc.channels['#pylink'].modes)
|
||||
self.irc.run(':70M FMODE #pylink 1423790412 +l 30')
|
||||
self.assertEqual({('l', '30')}, self.irc.channels['#pylink'].modes)
|
||||
self.assertIn(('l', '30'), self.irc.channels['#pylink'].modes)
|
||||
self.assertNotIn(('l', '50'), self.irc.channels['#pylink'].modes)
|
||||
hookdata = self.irc.takeHooks()
|
||||
expected = [['70M', 'FMODE', {'target': '#pylink', 'modes': [('+l', '50')], 'ts': 1423790412}],
|
||||
['70M', 'FMODE', {'target': '#pylink', 'modes': [('+l', '30')], 'ts': 1423790412}]]
|
||||
|
@ -12,13 +12,13 @@ def dummyf():
|
||||
|
||||
class TestRelay(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.irc = classes.FakeIRC('unittest', classes.FakeProto())
|
||||
self.irc = classes.FakeIRC('fakeirc', classes.FakeProto)
|
||||
self.irc.maxnicklen = 20
|
||||
self.f = lambda nick: relay.normalizeNick(self.irc, 'unittest', nick)
|
||||
# Fake our protocol name to something that supports slashes in nicks.
|
||||
# relay uses a whitelist for this to prevent accidentally introducing
|
||||
# bad nicks:
|
||||
self.irc.proto.__name__ = "inspircd"
|
||||
self.irc.protoname = "inspircd"
|
||||
|
||||
def testNormalizeNick(self):
|
||||
# Second argument simply states the suffix.
|
||||
@ -36,10 +36,10 @@ class TestRelay(unittest.TestCase):
|
||||
self.assertEqual(self.f('helloworld'), 'helloworl///unittest')
|
||||
|
||||
def testNormalizeNickRemovesSlashes(self):
|
||||
self.irc.proto.__name__ = "charybdis"
|
||||
self.irc.protoname = "charybdis"
|
||||
try:
|
||||
self.assertEqual(self.f('helloworld'), 'helloworld|unittest')
|
||||
self.assertEqual(self.f('abcde/eJanus'), 'abcde|eJanu|unittest')
|
||||
self.assertEqual(self.f('ObnoxiouslyLongNick'), 'Obnoxiously|unittest')
|
||||
finally:
|
||||
self.irc.proto.__name__ = "inspircd"
|
||||
self.irc.protoname = "inspircd"
|
||||
|
@ -13,7 +13,7 @@ def dummyf():
|
||||
|
||||
class TestUtils(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.irc = classes.FakeIRC('fakeirc', classes.FakeProto())
|
||||
self.irc = classes.FakeIRC('fakeirc', classes.FakeProto)
|
||||
|
||||
def testTS6UIDGenerator(self):
|
||||
uidgen = utils.TS6UIDGenerator('9PY')
|
||||
|
@ -17,80 +17,82 @@ class PluginTestCase(unittest.TestCase):
|
||||
self.u = self.irc.pseudoclient.uid
|
||||
self.maxDiff = None
|
||||
# Dummy servers/users used in tests below.
|
||||
self.proto.spawnServer(self.irc, 'whatever.', sid='10X')
|
||||
self.proto.spawnServer('whatever.', sid='10X')
|
||||
for x in range(3):
|
||||
self.proto.spawnClient(self.irc, 'user%s' % x, server='10X')
|
||||
self.proto.spawnClient('user%s' % x, server='10X')
|
||||
|
||||
class CommonProtoTestCase(PluginTestCase):
|
||||
def testJoinClient(self):
|
||||
u = self.u
|
||||
self.proto.joinClient(self.irc, u, '#Channel')
|
||||
self.proto.joinClient(u, '#Channel')
|
||||
self.assertIn(u, self.irc.channels['#channel'].users)
|
||||
# Non-existant user.
|
||||
self.assertRaises(LookupError, self.proto.joinClient, self.irc, '9PYZZZZZZ', '#test')
|
||||
self.assertRaises(LookupError, self.proto.joinClient, '9PYZZZZZZ', '#test')
|
||||
|
||||
def testKickClient(self):
|
||||
target = self.proto.spawnClient(self.irc, 'soccerball', 'soccerball', 'abcd').uid
|
||||
self.proto.joinClient(self.irc, target, '#pylink')
|
||||
target = self.proto.spawnClient('soccerball', 'soccerball', 'abcd').uid
|
||||
self.proto.joinClient(target, '#pylink')
|
||||
self.assertIn(self.u, self.irc.channels['#pylink'].users)
|
||||
self.assertIn(target, self.irc.channels['#pylink'].users)
|
||||
self.proto.kickClient(self.irc, self.u, '#pylink', target, 'Pow!')
|
||||
self.proto.kickClient(self.u, '#pylink', target, 'Pow!')
|
||||
self.assertNotIn(target, self.irc.channels['#pylink'].users)
|
||||
|
||||
def testModeClient(self):
|
||||
testuser = self.proto.spawnClient(self.irc, 'testcakes')
|
||||
testuser = self.proto.spawnClient('testcakes')
|
||||
self.irc.takeMsgs()
|
||||
self.proto.modeClient(self.irc, self.u, testuser.uid, [('+i', None), ('+w', None)])
|
||||
self.proto.modeClient(self.u, testuser.uid, [('+i', None), ('+w', None)])
|
||||
self.assertEqual({('i', None), ('w', None)}, testuser.modes)
|
||||
|
||||
self.proto.modeClient(self.irc, self.u, '#pylink', [('+s', None), ('+l', '30')])
|
||||
self.assertEqual({('s', None), ('l', '30')}, self.irc.channels['#pylink'].modes)
|
||||
# Default channels start with +nt
|
||||
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#pylink'].modes)
|
||||
self.proto.modeClient(self.u, '#pylink', [('+s', None), ('+l', '30')])
|
||||
self.assertEqual({('s', None), ('l', '30'), ('n', None), ('t', None)}, self.irc.channels['#pylink'].modes)
|
||||
|
||||
cmds = self.irc.takeCommands(self.irc.takeMsgs())
|
||||
self.assertEqual(cmds, ['MODE', 'FMODE'])
|
||||
|
||||
def testNickClient(self):
|
||||
self.proto.nickClient(self.irc, self.u, 'NotPyLink')
|
||||
self.proto.nickClient(self.u, 'NotPyLink')
|
||||
self.assertEqual('NotPyLink', self.irc.users[self.u].nick)
|
||||
|
||||
def testPartClient(self):
|
||||
u = self.u
|
||||
self.proto.joinClient(self.irc, u, '#channel')
|
||||
self.proto.partClient(self.irc, u, '#channel')
|
||||
self.proto.joinClient(u, '#channel')
|
||||
self.proto.partClient(u, '#channel')
|
||||
self.assertNotIn(u, self.irc.channels['#channel'].users)
|
||||
|
||||
def testQuitClient(self):
|
||||
u = self.proto.spawnClient(self.irc, 'testuser3', 'moo', 'hello.world').uid
|
||||
self.proto.joinClient(self.irc, u, '#channel')
|
||||
self.assertRaises(LookupError, self.proto.quitClient, self.irc, '9PYZZZZZZ', 'quit reason')
|
||||
self.proto.quitClient(self.irc, u, 'quit reason')
|
||||
u = self.proto.spawnClient('testuser3', 'moo', 'hello.world').uid
|
||||
self.proto.joinClient(u, '#channel')
|
||||
self.assertRaises(LookupError, self.proto.quitClient, '9PYZZZZZZ', 'quit reason')
|
||||
self.proto.quitClient(u, 'quit reason')
|
||||
self.assertNotIn(u, self.irc.channels['#channel'].users)
|
||||
self.assertNotIn(u, self.irc.users)
|
||||
self.assertNotIn(u, self.irc.servers[self.irc.sid].users)
|
||||
|
||||
def testSpawnClient(self):
|
||||
u = self.proto.spawnClient(self.irc, 'testuser3', 'moo', 'hello.world').uid
|
||||
u = self.proto.spawnClient('testuser3', 'moo', 'hello.world').uid
|
||||
# Check the server index and the user index
|
||||
self.assertIn(u, self.irc.servers[self.irc.sid].users)
|
||||
self.assertIn(u, self.irc.users)
|
||||
# Raise ValueError when trying to spawn a client on a server that's not ours
|
||||
self.assertRaises(ValueError, self.proto.spawnClient, self.irc, 'abcd', 'user', 'dummy.user.net', server='44A')
|
||||
self.assertRaises(ValueError, self.proto.spawnClient, 'abcd', 'user', 'dummy.user.net', server='44A')
|
||||
# Unfilled args should get placeholder fields and not error.
|
||||
self.proto.spawnClient(self.irc, 'testuser4')
|
||||
self.proto.spawnClient('testuser4')
|
||||
|
||||
def testSpawnClientOnServer(self):
|
||||
self.proto.spawnServer(self.irc, 'subserver.pylink', '34Q')
|
||||
u = self.proto.spawnClient(self.irc, 'person1', 'person', 'users.overdrive.pw', server='34Q')
|
||||
self.proto.spawnServer('subserver.pylink', '34Q')
|
||||
u = self.proto.spawnClient('person1', 'person', 'users.overdrive.pw', server='34Q')
|
||||
# We're spawning clients on the right server, hopefully...
|
||||
self.assertIn(u.uid, self.irc.servers['34Q'].users)
|
||||
self.assertNotIn(u.uid, self.irc.servers[self.irc.sid].users)
|
||||
|
||||
def testSpawnServer(self):
|
||||
# Incorrect SID length
|
||||
self.assertRaises(Exception, self.proto.spawnServer, self.irc, 'subserver.pylink', '34Q0')
|
||||
self.proto.spawnServer(self.irc, 'subserver.pylink', '34Q')
|
||||
self.assertRaises(Exception, self.proto.spawnServer, 'subserver.pylink', '34Q0')
|
||||
self.proto.spawnServer('subserver.pylink', '34Q')
|
||||
# Duplicate server name
|
||||
self.assertRaises(Exception, self.proto.spawnServer, self.irc, 'Subserver.PyLink', '34Z')
|
||||
self.assertRaises(Exception, self.proto.spawnServer, 'Subserver.PyLink', '34Z')
|
||||
# Duplicate SID
|
||||
self.assertRaises(Exception, self.proto.spawnServer, self.irc, 'another.Subserver.PyLink', '34Q')
|
||||
self.assertRaises(Exception, self.proto.spawnServer, 'another.Subserver.PyLink', '34Q')
|
||||
self.assertIn('34Q', self.irc.servers)
|
||||
|
Loading…
Reference in New Issue
Block a user