Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Fix some more encoding issues in tests

  • Loading branch information...
commit a9facb455f6f0d5a2d3d594832cecccbee323d6b 1 parent 518af78
@claudep claudep authored
View
4 tests/regressiontests/cache/tests.py
@@ -774,13 +774,13 @@ def test_cache_write_unpickable_object(self):
get_cache_data = fetch_middleware.process_request(request)
self.assertNotEqual(get_cache_data, None)
- self.assertEqual(get_cache_data.content, content)
+ self.assertEqual(get_cache_data.content, content.encode('utf-8'))
self.assertEqual(get_cache_data.cookies, response.cookies)
update_middleware.process_response(request, get_cache_data)
get_cache_data = fetch_middleware.process_request(request)
self.assertNotEqual(get_cache_data, None)
- self.assertEqual(get_cache_data.content, content)
+ self.assertEqual(get_cache_data.content, content.encode('utf-8'))
self.assertEqual(get_cache_data.cookies, response.cookies)
def custom_key_func(key, key_prefix, version):
View
11 tests/regressiontests/middleware/tests.py
@@ -3,6 +3,7 @@
import gzip
import re
import random
+from io import BytesIO
from django.conf import settings
from django.core import mail
@@ -15,7 +16,7 @@
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
from django.utils.six.moves import xrange
-from django.utils.six import StringIO
+
class CommonMiddlewareTest(TestCase):
def setUp(self):
@@ -526,14 +527,14 @@ def setUp(self):
@staticmethod
def decompress(gzipped_string):
- return gzip.GzipFile(mode='rb', fileobj=StringIO(gzipped_string)).read()
+ return gzip.GzipFile(mode='rb', fileobj=BytesIO(gzipped_string)).read()
def test_compress_response(self):
"""
Tests that compression is performed on responses with compressible content.
"""
r = GZipMiddleware().process_response(self.req, self.resp)
- self.assertEqual(self.decompress(r.content), self.compressible_string)
+ self.assertEqual(self.decompress(r.content), self.compressible_string.encode('utf-8'))
self.assertEqual(r.get('Content-Encoding'), 'gzip')
self.assertEqual(r.get('Content-Length'), str(len(r.content)))
@@ -544,7 +545,7 @@ def test_compress_non_200_response(self):
"""
self.resp.status_code = 404
r = GZipMiddleware().process_response(self.req, self.resp)
- self.assertEqual(self.decompress(r.content), self.compressible_string)
+ self.assertEqual(self.decompress(r.content), self.compressible_string.encode('utf-8'))
self.assertEqual(r.get('Content-Encoding'), 'gzip')
def test_no_compress_short_response(self):
@@ -572,7 +573,7 @@ def test_no_compress_ie_js_requests(self):
self.req.META['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)'
self.resp['Content-Type'] = 'application/javascript; charset=UTF-8'
r = GZipMiddleware().process_response(self.req, self.resp)
- self.assertEqual(r.content, self.compressible_string)
+ self.assertEqual(r.content, self.compressible_string.encode('utf-8'))
self.assertEqual(r.get('Content-Encoding'), None)
def test_no_compress_uncompressible_response(self):
View
2  tests/regressiontests/servers/tests.py
@@ -144,7 +144,7 @@ def test_fixtures_loaded(self):
Refs #2879.
"""
f = self.urlopen('/model_view/')
- self.assertEqual(f.read().splitlines(), ['jane', 'robert'])
+ self.assertEqual(f.read().splitlines(), [b'jane', b'robert'])
def test_database_writes(self):
"""
View
2  tests/regressiontests/views/tests/debug.py
@@ -36,7 +36,7 @@ def test_files(self):
self.assertEqual(response.status_code, 500)
data = {
- 'file_data.txt': SimpleUploadedFile('file_data.txt', 'haha'),
+ 'file_data.txt': SimpleUploadedFile('file_data.txt', b'haha'),
}
response = self.client.post('/raises/', data)
self.assertContains(response, 'file_data.txt', status_code=500)
Please sign in to comment.
Something went wrong with that request. Please try again.