Python/CloseTestPong.py
author morrowa
Thu Jul 02 17:51:35 2009 -0700 (2009-07-02)
changeset 55 f240f9023393
child 56 6c3b5372a307
permissions -rw-r--r--
Made C99 project default.
     1 # CloseTestPong.py
     2 # Tests the closing negotiation facilities of the BLIP 1.1 protocol
     3 
     4 from BLIP import Listener
     5 
     6 import logging
     7 import asyncore
     8 import unittest
     9 
    10 class CloseTestPong(unittest.TestCase):
    11     
    12     def shouldClose(self):
    13         logging.info("Allowed to close.")
    14         return True
    15     
    16     def handleConnection(self, conn):
    17         logging.info("Accepted connection.")
    18         conn.onCloseRequest = self.shouldClose
    19     
    20     def handleRequest(self, req):
    21         resp = req.response
    22         resp.body = "Pong"
    23         resp.send()
    24     
    25     def testClose(self):
    26         listen = Listener(1337)
    27         listen.onConnected = self.handleConnection
    28         listen.onRequest = self.handleRequest
    29         
    30         try:
    31             asyncore.loop()
    32         except KeyboardInterrupt:
    33             pass
    34 
    35 
    36 if __name__ == '__main__':
    37     logging.basicConfig(level=logging.DEBUG)
    38     unittest.main()