Do not die miserably when you get `False` as the HTML input. Test it.

pull/2590/head
Yajo 2016-04-05 16:58:19 +02:00 committed by dsolanki
parent 4c087f67f1
commit 971a270066
2 changed files with 7 additions and 1 deletions

View File

@ -41,7 +41,7 @@ class IrFieldsConverter(models.Model):
# Parse HTML
try:
doc = html.fromstring(html_content)
except (etree.XMLSyntaxError, etree.ParserError):
except (TypeError, etree.XMLSyntaxError, etree.ParserError):
if fail:
raise
else:

View File

@ -46,6 +46,12 @@ class ExtractorCase(TransactionCase):
with self.assertRaises(etree.XMLSyntaxError):
self.text_from_html("", fail=True)
def test_false_html(self):
"""``False`` HTML handled correctly."""
self.assertEqual(self.text_from_html(False), "")
with self.assertRaises(TypeError):
self.text_from_html(False, fail=True)
def test_bad_html(self):
"""Bad HTML handled correctly."""
self.assertEqual(self.text_from_html("<<bad>"), "")