From 4af7be3e41a6e98844a70eefbce4c8d33e729117 Mon Sep 17 00:00:00 2001 From: nanoric Date: Sun, 7 Oct 2018 03:34:50 -0400 Subject: [PATCH] =?UTF-8?q?[Add]=20=E5=A2=9E=E5=8A=A0WebsocketClient?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/restful/WebsocketClientTest.py | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/restful/WebsocketClientTest.py diff --git a/tests/restful/WebsocketClientTest.py b/tests/restful/WebsocketClientTest.py new file mode 100644 index 00000000..86da454d --- /dev/null +++ b/tests/restful/WebsocketClientTest.py @@ -0,0 +1,44 @@ +# encoding: UTF-8 +import json +import unittest + +from Promise import Promise +from vnpy.restful.WebsocketClient import WebsocketClient + + +class TestWebsocketClient(WebsocketClient): + + def __init__(self): + urlBase = 'wss://echo.websocket.org' + super(TestWebsocketClient, self).__init__(urlBase) + self.p = Promise() + + def onMessage(self, packet): + self.p.set_result(packet) + pass + + def onConnect(self): + pass + + def onError(self, exceptionType, exceptionValue, tb): + self.p.set_exception(exceptionValue) + pass + + +class WebsocketClientTest(unittest.TestCase): + + def setUp(self): + self.c = TestWebsocketClient() + self.c.start() + + def tearDown(self): + self.c.stop() + + def test_sendReq(self): + req = { + 'name': 'val' + } + self.c.sendReq(req) + res = self.c.p.get(3) + + self.assertEqual(res, req)