From a9facb455f6f0d5a2d3d594832cecccbee323d6b Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 15 Aug 2012 17:41:09 +0200 Subject: [PATCH] [py3] Fix some more encoding issues in tests --- tests/regressiontests/cache/tests.py | 4 ++-- tests/regressiontests/middleware/tests.py | 11 ++++++----- tests/regressiontests/servers/tests.py | 2 +- tests/regressiontests/views/tests/debug.py | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index ce6b7e74cd..3c7c2115ed 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -774,13 +774,13 @@ class BaseCacheTests(object): 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): diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py index 08a385e6cf..681de276f7 100644 --- a/tests/regressiontests/middleware/tests.py +++ b/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.middleware.gzip import GZipMiddleware 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 @@ class GZipMiddlewareTest(TestCase): @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 @@ class GZipMiddlewareTest(TestCase): """ 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 @@ class GZipMiddlewareTest(TestCase): 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): diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py index b98b4b73c2..c90c785a6e 100644 --- a/tests/regressiontests/servers/tests.py +++ b/tests/regressiontests/servers/tests.py @@ -144,7 +144,7 @@ class LiveServerDatabase(LiveServerBase): 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): """ diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py index e8a7d49e79..56383ac196 100644 --- a/tests/regressiontests/views/tests/debug.py +++ b/tests/regressiontests/views/tests/debug.py @@ -36,7 +36,7 @@ class DebugViewTests(TestCase): 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)