From 9767993a245bd465d64e7bc50d5c4b72eee5b8ef Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 6 Aug 2010 16:54:17 +0000 Subject: [PATCH] Fixed #13615 -- Clarified test assertion text to avoid confusion when response content isn't a web page. Thanks to DaNmarner for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13512 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/test/testcases.py | 8 ++++---- tests/regressiontests/test_client_regress/models.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 276d1f3c41113..10bd6c6c9ffcf 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -347,7 +347,7 @@ def assertRedirects(self, response, expected_url, status_code=302, def assertContains(self, response, text, count=None, status_code=200, msg_prefix=''): """ - Asserts that a response indicates that a page was retrieved + Asserts that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected), and that ``text`` occurs ``count`` times in the content of the response. If ``count`` is None, the count doesn't matter - the assertion is true @@ -357,7 +357,7 @@ def assertContains(self, response, text, count=None, status_code=200, msg_prefix += ": " self.assertEqual(response.status_code, status_code, - msg_prefix + "Couldn't retrieve page: Response code was %d" + msg_prefix + "Couldn't retrieve content: Response code was %d" " (expected %d)" % (response.status_code, status_code)) text = smart_str(text, response._charset) real_count = response.content.count(text) @@ -372,7 +372,7 @@ def assertContains(self, response, text, count=None, status_code=200, def assertNotContains(self, response, text, status_code=200, msg_prefix=''): """ - Asserts that a response indicates that a page was retrieved + Asserts that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected), and that ``text`` doesn't occurs in the content of the response. """ @@ -380,7 +380,7 @@ def assertNotContains(self, response, text, status_code=200, msg_prefix += ": " self.assertEqual(response.status_code, status_code, - msg_prefix + "Couldn't retrieve page: Response code was %d" + msg_prefix + "Couldn't retrieve content: Response code was %d" " (expected %d)" % (response.status_code, status_code)) text = smart_str(text, response._charset) self.assertEqual(response.content.count(text), 0, diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index a740237321c73..7a564e9b69ee6 100644 --- a/tests/regressiontests/test_client_regress/models.py +++ b/tests/regressiontests/test_client_regress/models.py @@ -34,20 +34,20 @@ def test_contains(self): try: self.assertContains(response, 'text', status_code=999) except AssertionError, e: - self.assertEquals(str(e), "Couldn't retrieve page: Response code was 200 (expected 999)") + self.assertEquals(str(e), "Couldn't retrieve content: Response code was 200 (expected 999)") try: self.assertContains(response, 'text', status_code=999, msg_prefix='abc') except AssertionError, e: - self.assertEquals(str(e), "abc: Couldn't retrieve page: Response code was 200 (expected 999)") + self.assertEquals(str(e), "abc: Couldn't retrieve content: Response code was 200 (expected 999)") try: self.assertNotContains(response, 'text', status_code=999) except AssertionError, e: - self.assertEquals(str(e), "Couldn't retrieve page: Response code was 200 (expected 999)") + self.assertEquals(str(e), "Couldn't retrieve content: Response code was 200 (expected 999)") try: self.assertNotContains(response, 'text', status_code=999, msg_prefix='abc') except AssertionError, e: - self.assertEquals(str(e), "abc: Couldn't retrieve page: Response code was 200 (expected 999)") + self.assertEquals(str(e), "abc: Couldn't retrieve content: Response code was 200 (expected 999)") try: self.assertNotContains(response, 'once')