Fixed #18980 -- Fixed assertContains regression when passed an object

This commit is contained in:
Jeremy Dunck 2012-09-18 20:58:40 +02:00 committed by Claude Paroz
parent 319e135519
commit 40e62a5ccd
2 changed files with 11 additions and 0 deletions

View File

@ -647,6 +647,7 @@ class TransactionTestCase(SimpleTestCase):
self.assertEqual(response.status_code, status_code, self.assertEqual(response.status_code, status_code,
msg_prefix + "Couldn't retrieve content: Response code was %d" msg_prefix + "Couldn't retrieve content: Response code was %d"
" (expected %d)" % (response.status_code, status_code)) " (expected %d)" % (response.status_code, status_code))
text = force_text(text, encoding=response._charset)
content = response.content.decode(response._charset) content = response.content.decode(response._charset)
if html: if html:
content = assert_and_parse_html(self, content, None, content = assert_and_parse_html(self, content, None,
@ -682,6 +683,7 @@ class TransactionTestCase(SimpleTestCase):
self.assertEqual(response.status_code, status_code, self.assertEqual(response.status_code, status_code,
msg_prefix + "Couldn't retrieve content: Response code was %d" msg_prefix + "Couldn't retrieve content: Response code was %d"
" (expected %d)" % (response.status_code, status_code)) " (expected %d)" % (response.status_code, status_code))
text = force_text(text, encoding=response._charset)
content = response.content.decode(response._charset) content = response.content.decode(response._charset)
if html: if html:
content = assert_and_parse_html(self, content, None, content = assert_and_parse_html(self, content, None,

View File

@ -16,6 +16,7 @@ from django.test import Client, TestCase
from django.test.client import encode_file, RequestFactory from django.test.client import encode_file, RequestFactory
from django.test.utils import ContextList, override_settings, str_prefix from django.test.utils import ContextList, override_settings, str_prefix
from django.template.response import SimpleTemplateResponse from django.template.response import SimpleTemplateResponse
from django.utils.translation import ugettext_lazy
from django.http import HttpResponse from django.http import HttpResponse
@ -129,6 +130,14 @@ class AssertContainsTests(TestCase):
self.assertNotContains(r, 'はたけ') self.assertNotContains(r, 'はたけ')
self.assertNotContains(r, b'\xe3\x81\xaf\xe3\x81\x9f\xe3\x81\x91'.decode('utf-8')) self.assertNotContains(r, b'\xe3\x81\xaf\xe3\x81\x9f\xe3\x81\x91'.decode('utf-8'))
def test_nontext_contains(self):
r = self.client.get('/test_client_regress/no_template_view/')
self.assertContains(r, ugettext_lazy('once'))
def test_nontext_not_contains(self):
r = self.client.get('/test_client_regress/no_template_view/')
self.assertNotContains(r, ugettext_lazy('never'))
def test_assert_contains_renders_template_response(self): def test_assert_contains_renders_template_response(self):
""" Test that we can pass in an unrendered SimpleTemplateReponse """ Test that we can pass in an unrendered SimpleTemplateReponse
without throwing an error. without throwing an error.