mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-24 03:29:28 +01:00
add tests for spawn/quit/join/partClient
This commit is contained in:
parent
d6341109be
commit
18528c9cab
@ -2,18 +2,23 @@ import sys
|
||||
import os
|
||||
sys.path += [os.getcwd(), os.path.join(os.getcwd(), 'protocols')]
|
||||
import unittest
|
||||
import time
|
||||
|
||||
import inspircd
|
||||
from . import test_proto_common
|
||||
from classes import ProtocolError
|
||||
import utils
|
||||
|
||||
class TestInspIRCdProtocol(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.irc = test_proto_common.FakeIRC(inspircd)
|
||||
self.proto = self.irc.proto
|
||||
self.sdata = self.irc.serverdata
|
||||
|
||||
# This is to initialize ourself as an internal PseudoServer, so we can spawn clients
|
||||
self.proto.connect(self.irc)
|
||||
self.u = self.irc.pseudoclient.uid
|
||||
|
||||
def test_connect(self):
|
||||
self.irc.proto.connect(self.irc)
|
||||
initial_messages = self.irc.takeMsgs()
|
||||
commands = self.irc.takeCommands(initial_messages)
|
||||
|
||||
@ -33,5 +38,38 @@ class TestInspIRCdProtocol(unittest.TestCase):
|
||||
# Incorrect recvpass here; should raise ProtocolError.
|
||||
self.assertRaises(ProtocolError, self.irc.run, 'SERVER somehow.someday BADPASS 0 0AL :Somehow Server - McMurdo Station, Antarctica')
|
||||
|
||||
def testSpawnClient(self):
|
||||
u = self.proto.spawnClient(self.irc, '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')
|
||||
|
||||
def testJoinClient(self):
|
||||
u = self.u
|
||||
self.proto.joinClient(self.irc, u, '#Channel')
|
||||
self.assertIn(u, self.irc.channels['#channel'].users)
|
||||
# Non-existant user.
|
||||
self.assertRaises(LookupError, self.proto.joinClient, self.irc, '9PYZZZZZZ', '#test')
|
||||
# Invalid channel.
|
||||
self.assertRaises(ValueError, self.proto.joinClient, self.irc, u, 'aaaa')
|
||||
|
||||
def testPartClient(self):
|
||||
u = self.u
|
||||
self.proto.joinClient(self.irc, u, '#channel')
|
||||
self.proto.partClient(self.irc, 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')
|
||||
self.assertNotIn(u, self.irc.channels['#channel'].users)
|
||||
self.assertNotIn(u, self.irc.users)
|
||||
self.assertNotIn(u, self.irc.servers[self.irc.sid].users)
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user