रूप @Vladimir कहा, तुम अब भी AsyncHTTPTestCase
का उपयोग बनाने के लिए/परीक्षण वेबसर्वर उदाहरण प्रबंधन कर सकते हैं, लेकिन आप अभी भी WebSockets ठीक उसी तरह आप सामान्य HTTP अनुरोध के रूप में परीक्षण कर सकते हैं - वहाँ बस कोई वाक्यात्मक चीनी आपकी मदद के लिए।
टॉरनाडो का अपना वेबस्केट क्लाइंट भी है, इसलिए किसी तीसरे पक्ष के क्लाइंट का उपयोग करने के लिए कोई आवश्यकता नहीं है (जहां तक मैंने देखा है) - शायद यह हालिया जोड़ा है। तो कुछ ऐसा प्रयास करें:
import tornado
class TestWebSockets(tornado.testing.AsyncHTTPTestCase):
def get_app(self):
# Required override for AsyncHTTPTestCase, sets up a dummy
# webserver for this test.
app = tornado.web.Application([
(r'/path/to/websocket', MyWebSocketHandler)
])
return app
@tornado.testing.gen_test
def test_websocket(self):
# self.get_http_port() gives us the port of the running test server.
ws_url = "ws://localhost:" + str(self.get_http_port()) + "/path/to/websocket"
# We need ws_url so we can feed it into our WebSocket client.
# ws_url will read (eg) "ws://localhost:56436/path/to/websocket
ws_client = yield tornado.websocket.websocket_connect(ws_url)
# Now we can run a test on the WebSocket.
ws_client.write_message("Hi, I'm sending a message to the server.")
response = yield ws_client.read_message()
self.assertEqual(response, "Hi client! This is a response from the server.")
# ...etc
उम्मीद है कि यह एक अच्छा प्रारंभिक बिंदु है।
http://www.tornadoweb.org/documentation/testing.html –
हाँ मैंने उस पृष्ठ को देखा। मैं गलत हो सकता था, लेकिन मेरा मानना है कि उनके द्वारा दस्तावेज किए गए एसिंक्रोनस टेस्ट केस नियमित HTTP अनुरोधों के लिए हैं, न कि वेबस्केट्स। –
ऐसा लगता है कि आप वास्तव में एक परीक्षण सर्वर हिट करने के लिए क्लाइंट का उपयोग करना चाहते हैं, इस मामले में मुझे लगता है कि उत्तर नहीं है, ऐसा नहीं है। 'tornado.testing' में एक वेबसाईट क्लाइंट शामिल नहीं है। आप सेलेनियम की तरह कुछ कोशिश कर सकते हैं। –