From d1452f60974da6f0e54ff9ad7a03d2c115675d10 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 14 Aug 2012 12:19:17 +0200 Subject: [PATCH] [py3] Favoured unicode strings in assert(Not)Contains In Python 3, HTMLParser does not support bytestrings. --- django/test/testcases.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 56ba56caf1..af807e075f 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -647,14 +647,13 @@ class TransactionTestCase(SimpleTestCase): self.assertEqual(response.status_code, status_code, msg_prefix + "Couldn't retrieve content: Response code was %d" " (expected %d)" % (response.status_code, status_code)) - enc_text = smart_bytes(text, response._charset) - content = response.content + content = response.content.decode(response._charset) if html: content = assert_and_parse_html(self, content, None, "Response's content is not valid HTML:") - enc_text = assert_and_parse_html(self, enc_text, None, + text = assert_and_parse_html(self, text, None, "Second argument is not valid HTML:") - real_count = content.count(enc_text) + real_count = content.count(text) if count is not None: self.assertEqual(real_count, count, msg_prefix + "Found %d instances of '%s' in response" @@ -683,14 +682,13 @@ class TransactionTestCase(SimpleTestCase): self.assertEqual(response.status_code, status_code, msg_prefix + "Couldn't retrieve content: Response code was %d" " (expected %d)" % (response.status_code, status_code)) - enc_text = smart_bytes(text, response._charset) - content = response.content + content = response.content.decode(response._charset) if html: content = assert_and_parse_html(self, content, None, 'Response\'s content is not valid HTML:') - enc_text = assert_and_parse_html(self, enc_text, None, + text = assert_and_parse_html(self, text, None, 'Second argument is not valid HTML:') - self.assertEqual(content.count(enc_text), 0, + self.assertEqual(content.count(text), 0, msg_prefix + "Response should not contain '%s'" % text) def assertFormError(self, response, form, field, errors, msg_prefix=''):