如何为websockets编写TestCase?

时间:2016-07-21 16:35:26

标签: python twisted autobahnws

我只想在setUp和tearDown中为WebSocketClientProtocol编写一个TestCase,我想我正确设置了服务器。

我想要的只是test client connected to server and server send some message client will receive就是这样。

以下是我尝试制作的代码,但我不会再从这里开始了

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 个答案:

没有答案