9 if __name__ =="__main__":
10 tests = unittest.defaultTestLoader.loadTestsFromNames([sys.argv[0][:-3]])
11 result = unittest.TextTestRunner().run(tests)
14 def connectionForAddr(host, port):
17 class Receiver(protocol.Factory):
21 def krpc_store(self, msg, _krpc_sender):
23 def krpc_echo(self, msg, _krpc_sender):
26 class SimpleTest(TestCase):
32 self.a = listenAirhookStream(4040, self.af)
33 self.b = listenAirhookStream(4041, self.bf)
35 def testSimpleMessage(self):
37 self.a.connectionForAddr(('127.0.0.1', 4041)).protocol.sendRequest('store', {'msg' : "This is a test."})
41 self.assertEqual(self.bf.buf, ["This is a test."])
43 class SimpleTest(TestCase):
49 self.a = listenAirhookStream(4050, self.af)
50 self.b = listenAirhookStream(4051, self.bf)
52 def testSimpleMessage(self):
54 self.a.connectionForAddr(('127.0.0.1', 4051)).protocol.sendRequest('store', {'msg' : "This is a test."})
58 self.assertEqual(self.bf.buf, ["This is a test."])
60 class BlastTest(TestCase):
66 self.a = listenAirhookStream(4060, self.af)
67 self.b = listenAirhookStream(4061, self.bf)
69 def testMessageBlast(self):
70 self.a.connectionForAddr(('127.0.0.1', 4061)).protocol.sendRequest('store', {'msg' : "This is a test."})
74 self.assertEqual(self.bf.buf, ["This is a test."])
78 self.a.connectionForAddr(('127.0.0.1', 4061)).protocol.sendRequest('store', {'msg' : "This is a test."})
81 self.assertEqual(self.bf.buf, ["This is a test."] * 100)
83 class EchoTest(TestCase):
90 self.a = listenAirhookStream(4042, self.af)
91 self.b = listenAirhookStream(4043, self.bf)
95 df = self.a.connectionForAddr(('127.0.0.1', 4043)).protocol.sendRequest('echo', {'msg' : "This is a test."})
96 df.addCallback(self.gotMsg)
101 self.assertEqual(self.msg, "This is a test.")
103 def gotMsg(self, dict):
104 _krpc_sender = dict['_krpc_sender']
108 class MultiEchoTest(TestCase):
115 self.a = listenAirhookStream(4048, self.af)
116 self.b = listenAirhookStream(4049, self.bf)
118 def testMultiEcho(self):
120 df = self.a.connectionForAddr(('127.0.0.1', 4049)).protocol.sendRequest('echo', {'msg' : "This is a test."})
121 df.addCallback(self.gotMsg)
126 self.assertEqual(self.msg, "This is a test.")
128 df = self.a.connectionForAddr(('127.0.0.1', 4049)).protocol.sendRequest('echo', {'msg' : "This is another test."})
129 df.addCallback(self.gotMsg)
134 self.assertEqual(self.msg, "This is another test.")
136 df = self.a.connectionForAddr(('127.0.0.1', 4049)).protocol.sendRequest('echo', {'msg' : "This is yet another test."})
137 df.addCallback(self.gotMsg)
142 self.assertEqual(self.msg, "This is yet another test.")
144 def gotMsg(self, dict):
145 _krpc_sender = dict['_krpc_sender']
149 class EchoResetTest(TestCase):
156 self.a = listenAirhookStream(4078, self.af)
157 self.b = listenAirhookStream(4079, self.bf)
159 def testEchoReset(self):
161 df = self.a.connectionForAddr(('127.0.0.1', 4079)).protocol.sendRequest('echo', {'msg' : "This is a test."})
162 df.addCallback(self.gotMsg)
167 self.assertEqual(self.msg, "This is a test.")
169 df = self.a.connectionForAddr(('127.0.0.1', 4079)).protocol.sendRequest('echo', {'msg' : "This is another test."})
170 df.addCallback(self.gotMsg)
175 self.assertEqual(self.msg, "This is another test.")
177 df = self.a.connectionForAddr(('127.0.0.1', 4079)).protocol.sendRequest('echo', {'msg' : "This is yet another test."})
178 df.addCallback(self.gotMsg)
183 self.assertEqual(self.msg, "This is yet another test.")
185 def gotMsg(self, dict):
186 _krpc_sender = dict['_krpc_sender']
190 class UnknownMethErrTest(TestCase):
196 self.a = listenAirhookStream(4044, self.af)
197 self.b = listenAirhookStream(4045, self.bf)
199 def testUnknownMeth(self):
201 df = self.a.connectionForAddr(('127.0.0.1', 4045)).protocol.sendRequest('blahblah', {'msg' : "This is a test."})
202 df.addErrback(self.gotErr)
207 self.assertEqual(self.err, KRPC_ERROR_METHOD_UNKNOWN)
209 def gotErr(self, err):