Permalink
Browse files

Fixed #24112 -- Fixed assertInHTML()'s counting if needle has no root…

… element.
  • Loading branch information...
1 parent ff1e7b4 commit ca2ccf54ffa95cf001260b917dd267fda60e93d5 @adamzap adamzap committed with timgraham Sep 1, 2016
Showing with 10 additions and 0 deletions.
  1. +3 −0 django/test/html.py
  2. +7 −0 tests/test_utils/tests.py
View
@@ -94,6 +94,9 @@ def _count(self, element, count=True):
if not isinstance(element, six.string_types):
if self == element:
return 1
+ if isinstance(element, RootElement):
+ if self.children == element.children:
+ return 1
i = 0
for child in self.children:
# child is text content and element is also text content, then
@@ -591,6 +591,8 @@ def test_html_contain(self):
self.assertIn(dom1, dom2)
dom1 = parse_html('<p>bar</p>')
self.assertIn(dom1, dom2)
+ dom1 = parse_html('<div><p>foo</p><p>bar</p></div>')
+ self.assertIn(dom2, dom1)
def test_count(self):
# equal html contains each other one time
@@ -626,6 +628,11 @@ def test_count(self):
dom2 = parse_html('<p>foo<p>bar</p></p>')
self.assertEqual(dom2.count(dom1), 0)
+ # html with a root element contains the same html with no root element
+ dom1 = parse_html('<p>foo</p><p>bar</p>')
+ dom2 = parse_html('<div><p>foo</p><p>bar</p></div>')
+ self.assertEqual(dom2.count(dom1), 1)
+
def test_parsing_errors(self):
with self.assertRaises(AssertionError):
self.assertHTMLEqual('<p>', '')

0 comments on commit ca2ccf5

Please sign in to comment.