Skip to content

Commit

Permalink
Fixed #13615 -- Clarified test assertion text to avoid confusion when…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
freakboy3742 committed Aug 6, 2010
1 parent 0c37f8d commit 9767993
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions django/test/testcases.py
Expand Up @@ -347,7 +347,7 @@ def assertRedirects(self, response, expected_url, status_code=302,
def assertContains(self, response, text, count=None, status_code=200, def assertContains(self, response, text, count=None, status_code=200,
msg_prefix=''): 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 successfully, (i.e., the HTTP status code was as expected), and that
``text`` occurs ``count`` times in the content of the response. ``text`` occurs ``count`` times in the content of the response.
If ``count`` is None, the count doesn't matter - the assertion is true If ``count`` is None, the count doesn't matter - the assertion is true
Expand All @@ -357,7 +357,7 @@ def assertContains(self, response, text, count=None, status_code=200,
msg_prefix += ": " msg_prefix += ": "


self.assertEqual(response.status_code, status_code, 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)) " (expected %d)" % (response.status_code, status_code))
text = smart_str(text, response._charset) text = smart_str(text, response._charset)
real_count = response.content.count(text) real_count = response.content.count(text)
Expand All @@ -372,15 +372,15 @@ def assertContains(self, response, text, count=None, status_code=200,
def assertNotContains(self, response, text, status_code=200, def assertNotContains(self, response, text, status_code=200,
msg_prefix=''): 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 successfully, (i.e., the HTTP status code was as expected), and that
``text`` doesn't occurs in the content of the response. ``text`` doesn't occurs in the content of the response.
""" """
if msg_prefix: if msg_prefix:
msg_prefix += ": " msg_prefix += ": "


self.assertEqual(response.status_code, status_code, 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)) " (expected %d)" % (response.status_code, status_code))
text = smart_str(text, response._charset) text = smart_str(text, response._charset)
self.assertEqual(response.content.count(text), 0, self.assertEqual(response.content.count(text), 0,
Expand Down
8 changes: 4 additions & 4 deletions tests/regressiontests/test_client_regress/models.py
Expand Up @@ -34,20 +34,20 @@ def test_contains(self):
try: try:
self.assertContains(response, 'text', status_code=999) self.assertContains(response, 'text', status_code=999)
except AssertionError, e: 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: try:
self.assertContains(response, 'text', status_code=999, msg_prefix='abc') self.assertContains(response, 'text', status_code=999, msg_prefix='abc')
except AssertionError, e: 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: try:
self.assertNotContains(response, 'text', status_code=999) self.assertNotContains(response, 'text', status_code=999)
except AssertionError, e: 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: try:
self.assertNotContains(response, 'text', status_code=999, msg_prefix='abc') self.assertNotContains(response, 'text', status_code=999, msg_prefix='abc')
except AssertionError, e: 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: try:
self.assertNotContains(response, 'once') self.assertNotContains(response, 'once')
Expand Down

0 comments on commit 9767993

Please sign in to comment.