diff options
| author | Ian Clelland <ian@fullfactor.com> | 2012-09-27 16:49:10 -0700 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2012-12-24 02:18:06 +0000 |
| commit | f2a7b52cfbe51cff2ef6d9f0c7ea05a7f04f33cc (patch) | |
| tree | ab23ee2122d73f6e1583d496b1820b7a42e7b209 | |
| parent | 903892be7b51bd22c10a6e6f49a7a2ee67fd2288 (diff) | |
[1.5.x] Add assertInHTML method to TestCase
Backport of dc704516c240011a9aeda17f631ade35c65cda58 from master
| -rw-r--r-- | django/test/testcases.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index f673a10d08..5ae1316421 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -393,6 +393,20 @@ class SimpleTestCase(ut2.TestCase): safe_repr(dom1, True), safe_repr(dom2, True)) self.fail(self._formatMessage(msg, standardMsg)) + def assertInHTML(self, needle, haystack, count = None, msg_prefix=''): + needle = assert_and_parse_html(self, needle, None, + 'First argument is not valid HTML:') + haystack = assert_and_parse_html(self, haystack, None, + 'Second argument is not valid HTML:') + real_count = haystack.count(needle) + if count is not None: + self.assertEqual(real_count, count, + msg_prefix + "Found %d instances of '%s' in response" + " (expected %d)" % (real_count, needle, count)) + else: + self.assertTrue(real_count != 0, + msg_prefix + "Couldn't find '%s' in response" % needle) + def assertXMLEqual(self, xml1, xml2, msg=None): """ Asserts that two XML snippets are semantically the same. |
