Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 40e62a5ccd08f241e977c9ffcb96005b9f2d95e6 1 parent 319e135
@jdunck jdunck authored claudep committed
View
2  django/test/testcases.py
@@ -647,6 +647,7 @@ 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))
+ 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 @@ 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))
+ text = force_text(text, encoding=response._charset)
content = response.content.decode(response._charset)
if html:
content = assert_and_parse_html(self, content, None,
View
9 tests/regressiontests/test_client_regress/tests.py
@@ -16,6 +16,7 @@
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 @@ def test_unicode_not_contains(self):
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.
Please sign in to comment.
Something went wrong with that request. Please try again.