morrowa@51: # CloseTestPing.py morrowa@51: # Tests the closing negotiation facilities of the BLIP 1.1 protocol morrowa@51: morrowa@51: from BLIP import Connection, OutgoingRequest morrowa@51: morrowa@51: import unittest morrowa@51: import asyncore morrowa@51: import logging morrowa@51: morrowa@51: class CloseTestPing(unittest.TestCase): morrowa@51: morrowa@51: def handleCloseRefusal(self, resp): morrowa@51: logging.info("Close request was refused!") morrowa@51: morrowa@51: def setUp(self): morrowa@51: self.connection = Connection( ('localhost', 1337) ) morrowa@51: self.connection.onCloseRefused = self.handleCloseRefusal morrowa@51: morrowa@51: def handleResponse(self, resp): morrowa@51: logging.info("Got response...") morrowa@51: morrowa@51: def testClose(self): morrowa@51: req = OutgoingRequest(self.connection, "Ping") morrowa@51: req.response.onComplete = self.handleResponse morrowa@51: req.send() morrowa@51: morrowa@51: asyncore.loop(timeout=1, count=5) morrowa@51: morrowa@51: self.connection.close() morrowa@51: morrowa@51: asyncore.loop() morrowa@51: morrowa@51: morrowa@51: if __name__ == '__main__': morrowa@51: logging.basicConfig(level=logging.DEBUG) morrowa@51: unittest.main()