Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x] Add assertInHTML method to TestCase

Backport of dc70451 from master
  • Loading branch information...
commit f2a7b52cfbe51cff2ef6d9f0c7ea05a7f04f33cc 1 parent 903892b
Ian Clelland authored September 27, 2012 spookylukey committed December 24, 2012

Showing 1 changed file with 14 additions and 0 deletions. Show diff stats Hide diff stats

  1. 14  django/test/testcases.py
14  django/test/testcases.py
@@ -393,6 +393,20 @@ def assertHTMLNotEqual(self, html1, html2, msg=None):
393 393
                 safe_repr(dom1, True), safe_repr(dom2, True))
394 394
             self.fail(self._formatMessage(msg, standardMsg))
395 395
 
  396
+    def assertInHTML(self, needle, haystack, count = None, msg_prefix=''):
  397
+        needle = assert_and_parse_html(self, needle, None,
  398
+            'First argument is not valid HTML:')
  399
+        haystack = assert_and_parse_html(self, haystack, None,
  400
+            'Second argument is not valid HTML:')
  401
+        real_count = haystack.count(needle)
  402
+        if count is not None:
  403
+            self.assertEqual(real_count, count,
  404
+                msg_prefix + "Found %d instances of '%s' in response"
  405
+                " (expected %d)" % (real_count, needle, count))
  406
+        else:
  407
+            self.assertTrue(real_count != 0,
  408
+                msg_prefix + "Couldn't find '%s' in response" % needle)
  409
+
396 410
     def assertXMLEqual(self, xml1, xml2, msg=None):
397 411
         """
398 412
         Asserts that two XML snippets are semantically the same.

0 notes on commit f2a7b52

Please sign in to comment.
Something went wrong with that request. Please try again.