Python/CloseTestPing.py
author Jens Alfke <jens@mooseyard.com>
Fri Jul 24 14:06:28 2009 -0700 (2009-07-24)
changeset 63 5e4855a592ee
parent 53 e9f209a24d53
permissions -rw-r--r--
* The BLIPConnection receivedRequest: delegate method now returns BOOL. If the method returns NO (or if the method isn't implemented in the delegate), that means it didn't handle the message at all; an error will be returned to the sender.
* If the connection closes unexpectedly due to an error, then the auto-generated responses to pending requests will contain that error. This makes it easier to display a meaningful error message in the handler for the request.
     1 # CloseTestPing.py
     2 # Tests the closing negotiation facilities of the BLIP 1.1 protocol
     3 
     4 from BLIP import Connection, OutgoingRequest
     5 
     6 import unittest
     7 import asyncore
     8 import logging
     9 
    10 class CloseTestPing(unittest.TestCase):
    11     
    12     def handleCloseRefusal(self, resp):
    13         logging.info("Close request was refused!")
    14     
    15     def setUp(self):
    16         self.connection = Connection( ('localhost', 1337) )
    17         self.connection.onCloseRefused = self.handleCloseRefusal
    18     
    19     def handleResponse(self, resp):
    20         logging.info("Got response...")
    21     
    22     def testClose(self):
    23         req = OutgoingRequest(self.connection, "Ping")
    24         req.response.onComplete = self.handleResponse
    25         req.send()
    26         
    27         asyncore.loop(timeout=0, count=5) # give things time to send
    28         
    29         self.connection.close()
    30         
    31         asyncore.loop()
    32 
    33 
    34 if __name__ == '__main__':
    35     logging.basicConfig(level=logging.INFO)
    36     unittest.main()