Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[py3] Fixed middleware tests.

Removed several inappropriate .encode('utf-8') calls in the process.
  • Loading branch information...
commit f7c2e82d765c4baa1cd57ac8908aa01807e077a1 1 parent 2b157b0
Aymeric Augustin authored August 15, 2012
15  tests/regressiontests/middleware/tests.py
@@ -15,6 +15,7 @@
15 15
 from django.middleware.gzip import GZipMiddleware
16 16
 from django.test import TestCase, RequestFactory
17 17
 from django.test.utils import override_settings
  18
+from django.utils import six
18 19
 from django.utils.six.moves import xrange
19 20
 
20 21
 
@@ -507,9 +508,9 @@ class GZipMiddlewareTest(TestCase):
507 508
     """
508 509
     Tests the GZip middleware.
509 510
     """
510  
-    short_string = "This string is too short to be worth compressing."
511  
-    compressible_string = 'a' * 500
512  
-    uncompressible_string = ''.join(chr(random.randint(0, 255)) for _ in xrange(500))
  511
+    short_string = b"This string is too short to be worth compressing."
  512
+    compressible_string = b'a' * 500
  513
+    uncompressible_string = b''.join(six.int2byte(random.randint(0, 255)) for _ in xrange(500))
513 514
 
514 515
     def setUp(self):
515 516
         self.req = HttpRequest()
@@ -534,7 +535,7 @@ def test_compress_response(self):
534 535
         Tests that compression is performed on responses with compressible content.
535 536
         """
536 537
         r = GZipMiddleware().process_response(self.req, self.resp)
537  
-        self.assertEqual(self.decompress(r.content), self.compressible_string.encode('utf-8'))
  538
+        self.assertEqual(self.decompress(r.content), self.compressible_string)
538 539
         self.assertEqual(r.get('Content-Encoding'), 'gzip')
539 540
         self.assertEqual(r.get('Content-Length'), str(len(r.content)))
540 541
 
@@ -545,7 +546,7 @@ def test_compress_non_200_response(self):
545 546
         """
546 547
         self.resp.status_code = 404
547 548
         r = GZipMiddleware().process_response(self.req, self.resp)
548  
-        self.assertEqual(self.decompress(r.content), self.compressible_string.encode('utf-8'))
  549
+        self.assertEqual(self.decompress(r.content), self.compressible_string)
549 550
         self.assertEqual(r.get('Content-Encoding'), 'gzip')
550 551
 
551 552
     def test_no_compress_short_response(self):
@@ -573,7 +574,7 @@ def test_no_compress_ie_js_requests(self):
573 574
         self.req.META['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)'
574 575
         self.resp['Content-Type'] = 'application/javascript; charset=UTF-8'
575 576
         r = GZipMiddleware().process_response(self.req, self.resp)
576  
-        self.assertEqual(r.content, self.compressible_string.encode('utf-8'))
  577
+        self.assertEqual(r.content, self.compressible_string)
577 578
         self.assertEqual(r.get('Content-Encoding'), None)
578 579
 
579 580
     def test_no_compress_uncompressible_response(self):
@@ -591,7 +592,7 @@ class ETagGZipMiddlewareTest(TestCase):
591 592
     """
592 593
     Tests if the ETag middleware behaves correctly with GZip middleware.
593 594
     """
594  
-    compressible_string = 'a' * 500
  595
+    compressible_string = b'a' * 500
595 596
 
596 597
     def setUp(self):
597 598
         self.rf = RequestFactory()

0 notes on commit f7c2e82

Please sign in to comment.
Something went wrong with that request. Please try again.