From 18528c9cabc0b683aebfa8bda1547aff19219e23 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 3 Jul 2015 23:32:41 -0700 Subject: [PATCH] add tests for spawn/quit/join/partClient --- tests/test_proto_inspircd.py | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/tests/test_proto_inspircd.py b/tests/test_proto_inspircd.py index 3f9d612..5157510 100644 --- a/tests/test_proto_inspircd.py +++ b/tests/test_proto_inspircd.py @@ -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()