Skip to content

Commit

Permalink
Fix html contain testing if needle has no root element
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed Feb 5, 2015
1 parent 1a56cea commit 430531c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions django/test/html.py
Expand Up @@ -95,6 +95,9 @@ def _count(self, element, count=True):
if not isinstance(element, six.string_types):
if self == element:
return 1
if isinstance(element, RootElement):
raise ValueError('Needle HTML does not have a root element')

i = 0
for child in self.children:
# child is text content and element is also text content, then
Expand Down
3 changes: 2 additions & 1 deletion tests/test_utils/tests.py
Expand Up @@ -576,7 +576,8 @@ def test_html_contain(self):
# when a root element is used for the needle but not the haystack
dom1 = parse_html('<p>foo</p><p>bar</p>')
dom2 = parse_html('<div><p>foo</p><p>bar</p></div>')
self.assertIn(dom1, dom2)
with self.assertRaises(ValueError):
self.assertIn(dom1, dom2)

def test_count(self):
# equal html contains each other one time
Expand Down

0 comments on commit 430531c

Please sign in to comment.