Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.5.x] Add assertInHTML method to TestCase

Backport of dc70451 from master
  • Loading branch information...
commit f2a7b52cfbe51cff2ef6d9f0c7ea05a7f04f33cc 1 parent 903892b
@clelland clelland authored spookylukey committed
Showing with 14 additions and 0 deletions.
  1. +14 −0 django/test/testcases.py
View
14 django/test/testcases.py
@@ -393,6 +393,20 @@ def assertHTMLNotEqual(self, html1, html2, msg=None):
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.
Please sign in to comment.
Something went wrong with that request. Please try again.