Ticket #7165: assert_not_contains.2.diff
| File assert_not_contains.2.diff, 2.4 kB (added by J. Pablo Fernandez <pupeno@pupeno.com>, 7 months ago) |
|---|
-
a/django/test/testcases.py
old new 128 128 self.failUnless(real_count != 0, 129 129 "Couldn't find '%s' in response" % text) 130 130 131 def assertNotContains(self, response, text, status_code=200): 132 """ 133 Asserts that a response indicates that a page was retrieved 134 successfully, (i.e., the HTTP status code was as expected), and that 135 ``text`` doesn't occurs in the content of the response. 136 """ 137 self.assertEqual(response.status_code, status_code, 138 "Couldn't retrieve page: Response code was %d (expected %d)'" % 139 (response.status_code, status_code)) 140 self.assertEqual(response.content.count(text), 0, 141 "Response should't have had '%s'" % text) 142 131 143 def assertFormError(self, response, form, field, errors): 132 144 """ 133 145 Asserts that a form used to render the response has a specific field -
a/docs/testing.txt
old new 822 822 that ``text`` appears in the content of the response. If ``count`` is 823 823 provided, ``text`` must occur exactly ``count`` times in the response. 824 824 825 ``assertNotContains(response, text, status_code=200)`` 826 Asserts that a ``Response`` instance produced the given ``status_code`` and 827 that ``text`` does not appears in the content of the response. 828 825 829 ``assertFormError(response, form, field, errors)`` 826 830 Asserts that a field on a form raises the provided list of errors when 827 831 rendered on the form. -
a/tests/modeltests/test_client/models.py
old new 406 406 self.assertEqual(mail.outbox[1].to[0], 'second@example.com') 407 407 self.assertEqual(mail.outbox[1].to[1], 'third@example.com') 408 408 409 def test_not_contains(self): 410 response = self.client.get('/test_client/get_view/') 411 self.assertNotContains(response, "surely not there") 412 self.assertRaises(AssertionError, 413 self.assertNotContains, response, "This is a test") 414
