From 40e62a5ccd08f241e977c9ffcb96005b9f2d95e6 Mon Sep 17 00:00:00 2001 From: Jeremy Dunck Date: Tue, 18 Sep 2012 20:58:40 +0200 Subject: [PATCH] Fixed #18980 -- Fixed assertContains regression when passed an object --- django/test/testcases.py | 2 ++ tests/regressiontests/test_client_regress/tests.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/django/test/testcases.py b/django/test/testcases.py index 3c681db329..d37be58a71 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -647,6 +647,7 @@ 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)) + text = force_text(text, encoding=response._charset) content = response.content.decode(response._charset) if html: content = assert_and_parse_html(self, content, None, @@ -682,6 +683,7 @@ 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)) + text = force_text(text, encoding=response._charset) content = response.content.decode(response._charset) if html: content = assert_and_parse_html(self, content, None, diff --git a/tests/regressiontests/test_client_regress/tests.py b/tests/regressiontests/test_client_regress/tests.py index d80293b358..9deb8a4755 100644 --- a/tests/regressiontests/test_client_regress/tests.py +++ b/tests/regressiontests/test_client_regress/tests.py @@ -16,6 +16,7 @@ from django.test import Client, TestCase from django.test.client import encode_file, RequestFactory from django.test.utils import ContextList, override_settings, str_prefix from django.template.response import SimpleTemplateResponse +from django.utils.translation import ugettext_lazy from django.http import HttpResponse @@ -129,6 +130,14 @@ class AssertContainsTests(TestCase): self.assertNotContains(r, 'はたけ') 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): """ Test that we can pass in an unrendered SimpleTemplateReponse without throwing an error.