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 EchoTest(TestCase):
67 self.a = listenAirhookStream(4042, self.af)
68 self.b = listenAirhookStream(4043, self.bf)
72 df = self.a.connectionForAddr(('127.0.0.1', 4043)).protocol.sendRequest('echo', {'msg' : "This is a test."})
73 df.addCallback(self.gotMsg)
78 self.assertEqual(self.msg, "This is a test.")
80 def gotMsg(self, msg):
83 class MultiEchoTest(TestCase):
90 self.a = listenAirhookStream(4048, self.af)
91 self.b = listenAirhookStream(4049, self.bf)
93 def testMultiEcho(self):
95 df = self.a.connectionForAddr(('127.0.0.1', 4049)).protocol.sendRequest('echo', {'msg' : "This is a test."})
96 df.addCallback(self.gotMsg)
101 self.assertEqual(self.msg, "This is a test.")
103 df = self.a.connectionForAddr(('127.0.0.1', 4049)).protocol.sendRequest('echo', {'msg' : "This is another test."})
104 df.addCallback(self.gotMsg)
109 self.assertEqual(self.msg, "This is another test.")
111 df = self.a.connectionForAddr(('127.0.0.1', 4049)).protocol.sendRequest('echo', {'msg' : "This is yet another test."})
112 df.addCallback(self.gotMsg)
117 self.assertEqual(self.msg, "This is yet another test.")
119 def gotMsg(self, msg):
122 class UnknownMethErrTest(TestCase):
128 self.a = listenAirhookStream(4044, self.af)
129 self.b = listenAirhookStream(4045, self.bf)
131 def testUnknownMeth(self):
133 df = self.a.connectionForAddr(('127.0.0.1', 4045)).protocol.sendRequest('blahblah', {'msg' : "This is a test."})
134 df.addErrback(self.gotErr)
139 self.assertEqual(self.err, KRPC_ERROR_METHOD_UNKNOWN)
141 def gotErr(self, err):