]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Python3-ify this test
authorBen Darnell <ben@bendarnell.com>
Sun, 15 May 2011 23:30:41 +0000 (16:30 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 15 May 2011 23:30:41 +0000 (16:30 -0700)
tornado/test/simple_httpclient_test.py

index ce71b6e99b4682bf217c07911264b7ce7197c9ff..2b82b36b80d9aef9e64751bc8f09e127c0ceb8aa 100644 (file)
@@ -3,6 +3,7 @@
 from __future__ import with_statement
 
 import base64
+import binascii
 import collections
 import gzip
 import logging
@@ -233,16 +234,26 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
                          response.body)
 
     def test_body_encoding(self):
+        unicode_body = u"\xe9"
+        byte_body = binascii.a2b_hex(b("e9"))
+
         # unicode string in body gets converted to utf8
-        response = self.fetch("/echopost", method="POST", body=u"\xe9")
-        self.assertEqual(response.body, utf8(u"\xe9"))
+        response = self.fetch("/echopost", method="POST", body=unicode_body,
+                              headers={"Content-Type": "application/blah"})
+        self.assertEqual(response.headers["Content-Length"], "2")
+        self.assertEqual(response.body, utf8(unicode_body))
 
         # byte strings pass through directly
-        response = self.fetch("/echopost", method="POST", body="\xe9")
-        self.assertEqual(response.body, "\xe9")
+        response = self.fetch("/echopost", method="POST",
+                              body=byte_body,
+                              headers={"Content-Type": "application/blah"})
+        self.assertEqual(response.headers["Content-Length"], "1")
+        self.assertEqual(response.body, byte_body)
 
         # Mixing unicode in headers and byte string bodies shouldn't
         # break anything
-        response = self.fetch("/echopost", method="POST", body="\xe9",
+        response = self.fetch("/echopost", method="POST", body=byte_body,
+                              headers={"Content-Type": "application/blah"},
                               user_agent=u"foo")
-        self.assertEqual(response.body, "\xe9")
+        self.assertEqual(response.headers["Content-Length"], "1")
+        self.assertEqual(response.body, byte_body)