How to write TestCase for websockets?

956 views Asked by At

I just want to write a TestCase for WebSocketClientProtocol in the setUp and tearDown I think I setup correctly the Server.

All I want is test client connected to server and server send some message client will receive that's it.

Below is the code I tried to make but I don't go further from here

class WebSocketTest(unittest.TestCase):

    def setUp(self):
        factory = WebSocketServerFactory("ws://localhost:8000")
        self.listening_port = listenWS(factory)
        self.factory, self.port = factory, port

    def tearDown(self):
        self.listening_port.stopListening()

    def test_client_message(self):
        client_factory = TestClientProtocolFactory(
            url="ws://127.0.0.1:8000".format(self.port))
        connectWS(client_factory)
0

There are 0 answers