[py3] Fix some more encoding issues in tests
This commit is contained in:
parent
518af78e21
commit
a9facb455f
|
@ -774,13 +774,13 @@ class BaseCacheTests(object):
|
||||||
|
|
||||||
get_cache_data = fetch_middleware.process_request(request)
|
get_cache_data = fetch_middleware.process_request(request)
|
||||||
self.assertNotEqual(get_cache_data, None)
|
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)
|
self.assertEqual(get_cache_data.cookies, response.cookies)
|
||||||
|
|
||||||
update_middleware.process_response(request, get_cache_data)
|
update_middleware.process_response(request, get_cache_data)
|
||||||
get_cache_data = fetch_middleware.process_request(request)
|
get_cache_data = fetch_middleware.process_request(request)
|
||||||
self.assertNotEqual(get_cache_data, None)
|
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)
|
self.assertEqual(get_cache_data.cookies, response.cookies)
|
||||||
|
|
||||||
def custom_key_func(key, key_prefix, version):
|
def custom_key_func(key, key_prefix, version):
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import gzip
|
import gzip
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
@ -15,7 +16,7 @@ from django.middleware.gzip import GZipMiddleware
|
||||||
from django.test import TestCase, RequestFactory
|
from django.test import TestCase, RequestFactory
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils.six.moves import xrange
|
from django.utils.six.moves import xrange
|
||||||
from django.utils.six import StringIO
|
|
||||||
|
|
||||||
class CommonMiddlewareTest(TestCase):
|
class CommonMiddlewareTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -526,14 +527,14 @@ class GZipMiddlewareTest(TestCase):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decompress(gzipped_string):
|
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):
|
def test_compress_response(self):
|
||||||
"""
|
"""
|
||||||
Tests that compression is performed on responses with compressible content.
|
Tests that compression is performed on responses with compressible content.
|
||||||
"""
|
"""
|
||||||
r = GZipMiddleware().process_response(self.req, self.resp)
|
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-Encoding'), 'gzip')
|
||||||
self.assertEqual(r.get('Content-Length'), str(len(r.content)))
|
self.assertEqual(r.get('Content-Length'), str(len(r.content)))
|
||||||
|
|
||||||
|
@ -544,7 +545,7 @@ class GZipMiddlewareTest(TestCase):
|
||||||
"""
|
"""
|
||||||
self.resp.status_code = 404
|
self.resp.status_code = 404
|
||||||
r = GZipMiddleware().process_response(self.req, self.resp)
|
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-Encoding'), 'gzip')
|
||||||
|
|
||||||
def test_no_compress_short_response(self):
|
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.req.META['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)'
|
||||||
self.resp['Content-Type'] = 'application/javascript; charset=UTF-8'
|
self.resp['Content-Type'] = 'application/javascript; charset=UTF-8'
|
||||||
r = GZipMiddleware().process_response(self.req, self.resp)
|
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)
|
self.assertEqual(r.get('Content-Encoding'), None)
|
||||||
|
|
||||||
def test_no_compress_uncompressible_response(self):
|
def test_no_compress_uncompressible_response(self):
|
||||||
|
|
|
@ -144,7 +144,7 @@ class LiveServerDatabase(LiveServerBase):
|
||||||
Refs #2879.
|
Refs #2879.
|
||||||
"""
|
"""
|
||||||
f = self.urlopen('/model_view/')
|
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):
|
def test_database_writes(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DebugViewTests(TestCase):
|
||||||
self.assertEqual(response.status_code, 500)
|
self.assertEqual(response.status_code, 500)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'file_data.txt': SimpleUploadedFile('file_data.txt', 'haha'),
|
'file_data.txt': SimpleUploadedFile('file_data.txt', b'haha'),
|
||||||
}
|
}
|
||||||
response = self.client.post('/raises/', data)
|
response = self.client.post('/raises/', data)
|
||||||
self.assertContains(response, 'file_data.txt', status_code=500)
|
self.assertContains(response, 'file_data.txt', status_code=500)
|
||||||
|
|
Loading…
Reference in New Issue