From: Ben Darnell Date: Sun, 15 May 2011 23:30:41 +0000 (-0700) Subject: Python3-ify this test X-Git-Tag: v2.0.0~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6894ba7c21e7a888333faae00832f1409f6ff5e5;p=thirdparty%2Ftornado.git Python3-ify this test --- diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index ce71b6e99..2b82b36b8 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -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)