diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-07-20 14:32:20 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-07-20 14:32:20 +0000 |
| commit | 56394220d5d4ae443dfc0fb55f677099696a55bf (patch) | |
| tree | a583ad099af9ca95cee4a0018b8d4b2de51531b5 /django/test/testcases.py | |
| parent | bdc5a3eb51f42946ef6d56333edaff16caeecb34 (diff) | |
Fixed #4901 -- Modified assertContains to provide a default check of 'any instances of text in content'. Thanks for the suggestion, nis@superlativ.dk.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5731 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/testcases.py')
| -rw-r--r-- | django/test/testcases.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index e88741e94c..df583b3ce3 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -73,19 +73,23 @@ class TestCase(unittest.TestCase): "Couldn't retrieve redirection page '%s': response code was %d (expected %d)" % (path, redirect_response.status_code, target_status_code)) - def assertContains(self, response, text, count=1, status_code=200): + def assertContains(self, response, text, count=None, status_code=200): """Assert that a response indicates that a page was retreived successfully, (i.e., the HTTP status code was as expected), and that ``text`` occurs ``count`` - times in the content of the response. + times in the content of the response. If ``count`` is None, the count doesn't + matter - the assertion is true if the text occurs at least once in the response. """ self.assertEqual(response.status_code, status_code, "Couldn't retrieve page: Response code was %d (expected %d)'" % (response.status_code, status_code)) real_count = response.content.count(text) - self.assertEqual(real_count, count, - "Found %d instances of '%s' in response (expected %d)" % (real_count, text, count)) - + if count: + self.assertEqual(real_count, count, + "Found %d instances of '%s' in response (expected %d)" % (real_count, text, count)) + else: + self.assertTrue(real_count != 0, "Couldn't find '%s' in response" % text) + def assertFormError(self, response, form, field, errors): "Assert that a form used to render the response has a specific field error" if not response.context: |
