Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

In Python 3, HTMLParser does not support bytestrings.
  • Loading branch information...
commit d1452f60974da6f0e54ff9ad7a03d2c115675d10 1 parent e04230e
@claudep claudep authored
Showing with 6 additions and 8 deletions.
  1. +6 −8 django/test/testcases.py
View
14 django/test/testcases.py
@@ -647,14 +647,13 @@ def assertContains(self, response, text, count=None, status_code=200,
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 @@ def assertNotContains(self, response, text, status_code=200,
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=''):
Please sign in to comment.
Something went wrong with that request. Please try again.