Python/CloseTestPong.py
changeset 53 e9f209a24d53
child 56 6c3b5372a307
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Python/CloseTestPong.py	Tue Jun 23 12:46:40 2009 -0700
     1.3 @@ -0,0 +1,38 @@
     1.4 +# CloseTestPong.py
     1.5 +# Tests the closing negotiation facilities of the BLIP 1.1 protocol
     1.6 +
     1.7 +from BLIP import Listener
     1.8 +
     1.9 +import logging
    1.10 +import asyncore
    1.11 +import unittest
    1.12 +
    1.13 +class CloseTestPong(unittest.TestCase):
    1.14 +    
    1.15 +    def shouldClose(self):
    1.16 +        logging.info("Allowed to close.")
    1.17 +        return True
    1.18 +    
    1.19 +    def handleConnection(self, conn):
    1.20 +        logging.info("Accepted connection.")
    1.21 +        conn.onCloseRequest = self.shouldClose
    1.22 +    
    1.23 +    def handleRequest(self, req):
    1.24 +        resp = req.response
    1.25 +        resp.body = "Pong"
    1.26 +        resp.send()
    1.27 +    
    1.28 +    def testClose(self):
    1.29 +        listen = Listener(1337)
    1.30 +        listen.onConnected = self.handleConnection
    1.31 +        listen.onRequest = self.handleRequest
    1.32 +        
    1.33 +        try:
    1.34 +            asyncore.loop()
    1.35 +        except KeyboardInterrupt:
    1.36 +            pass
    1.37 +
    1.38 +
    1.39 +if __name__ == '__main__':
    1.40 +    logging.basicConfig(level=logging.DEBUG)
    1.41 +    unittest.main()