Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[py3] Favoured unicode strings in assert(Not)Contains

In Python 3, HTMLParser does not support bytestrings.
  • Loading branch information...
commit d1452f60974da6f0e54ff9ad7a03d2c115675d10 1 parent e04230e
Claude Paroz authored August 14, 2012

Showing 1 changed file with 6 additions and 8 deletions. Show diff stats Hide diff stats

  1. 14  django/test/testcases.py
14  django/test/testcases.py
@@ -647,14 +647,13 @@ def assertContains(self, response, text, count=None, status_code=200,
647 647
         self.assertEqual(response.status_code, status_code,
648 648
             msg_prefix + "Couldn't retrieve content: Response code was %d"
649 649
             " (expected %d)" % (response.status_code, status_code))
650  
-        enc_text = smart_bytes(text, response._charset)
651  
-        content = response.content
  650
+        content = response.content.decode(response._charset)
652 651
         if html:
653 652
             content = assert_and_parse_html(self, content, None,
654 653
                 "Response's content is not valid HTML:")
655  
-            enc_text = assert_and_parse_html(self, enc_text, None,
  654
+            text = assert_and_parse_html(self, text, None,
656 655
                 "Second argument is not valid HTML:")
657  
-        real_count = content.count(enc_text)
  656
+        real_count = content.count(text)
658 657
         if count is not None:
659 658
             self.assertEqual(real_count, count,
660 659
                 msg_prefix + "Found %d instances of '%s' in response"
@@ -683,14 +682,13 @@ def assertNotContains(self, response, text, status_code=200,
683 682
         self.assertEqual(response.status_code, status_code,
684 683
             msg_prefix + "Couldn't retrieve content: Response code was %d"
685 684
             " (expected %d)" % (response.status_code, status_code))
686  
-        enc_text = smart_bytes(text, response._charset)
687  
-        content = response.content
  685
+        content = response.content.decode(response._charset)
688 686
         if html:
689 687
             content = assert_and_parse_html(self, content, None,
690 688
                 'Response\'s content is not valid HTML:')
691  
-            enc_text = assert_and_parse_html(self, enc_text, None,
  689
+            text = assert_and_parse_html(self, text, None,
692 690
                 'Second argument is not valid HTML:')
693  
-        self.assertEqual(content.count(enc_text), 0,
  691
+        self.assertEqual(content.count(text), 0,
694 692
             msg_prefix + "Response should not contain '%s'" % text)
695 693
 
696 694
     def assertFormError(self, response, form, field, errors, msg_prefix=''):

0 notes on commit d1452f6

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