]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add tests for both binary and unicode messages in websockets.
authorBen Darnell <ben@bendarnell.com>
Thu, 3 Jul 2014 02:00:14 +0000 (22:00 -0400)
committerBen Darnell <ben@bendarnell.com>
Thu, 3 Jul 2014 02:00:14 +0000 (22:00 -0400)
tornado/test/websocket_test.py

index 7b3c34ceef5196768df2d4c318022aab24f2e984..177abc3bb5daff25f97fe02d0239ee413d484e86 100644 (file)
@@ -8,6 +8,7 @@ from tornado.log import gen_log
 from tornado.testing import AsyncHTTPTestCase, gen_test, bind_unused_port, ExpectLog
 from tornado.test.util import unittest
 from tornado.web import Application, RequestHandler
+from tornado.util import u
 
 try:
     import tornado.websocket
@@ -107,6 +108,26 @@ class WebSocketTest(AsyncHTTPTestCase):
         ws.close()
         self.wait()
 
+    @gen_test
+    def test_binary_message(self):
+        ws = yield websocket_connect(
+            'ws://localhost:%d/echo' % self.get_http_port())
+        ws.write_message(b'hello \xe9', binary=True)
+        response = yield ws.read_message()
+        self.assertEqual(response, b'hello \xe9')
+        ws.close()
+        yield self.close_future
+
+    @gen_test
+    def test_unicode_message(self):
+        ws = yield websocket_connect(
+            'ws://localhost:%d/echo' % self.get_http_port())
+        ws.write_message(u('hello \u00e9'))
+        response = yield ws.read_message()
+        self.assertEqual(response, u('hello \u00e9'))
+        ws.close()
+        yield self.close_future
+
     @gen_test
     def test_websocket_http_fail(self):
         with self.assertRaises(HTTPError) as cm: