|
|
@ -3,6 +3,7 @@ |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
from lxml import etree |
|
|
|
from openerp.tools.misc import mute_logger |
|
|
|
from openerp.tests.common import TransactionCase |
|
|
|
|
|
|
|
|
|
|
@ -12,6 +13,8 @@ class ExtractorCase(TransactionCase): |
|
|
|
|
|
|
|
# Shortcut |
|
|
|
self.imgs_from_html = self.env["ir.fields.converter"].imgs_from_html |
|
|
|
self.logger = ('openerp.addons.html_image_url_extractor' |
|
|
|
'.models.ir_fields_converter') |
|
|
|
|
|
|
|
def test_mixed_images_found(self): |
|
|
|
"""Images correctly found in <img> elements and backgrounds.""" |
|
|
@ -46,24 +49,35 @@ class ExtractorCase(TransactionCase): |
|
|
|
|
|
|
|
def test_empty_html(self): |
|
|
|
"""Empty HTML handled correctly.""" |
|
|
|
for laps, text in self.imgs_from_html(""): |
|
|
|
self.assertTrue(False) # You should never get here |
|
|
|
with mute_logger(self.logger): |
|
|
|
for laps, text in self.imgs_from_html(""): |
|
|
|
self.assertTrue(False) # You should never get here |
|
|
|
|
|
|
|
with self.assertRaises(etree.XMLSyntaxError): |
|
|
|
list(self.imgs_from_html("", fail=True)) |
|
|
|
with mute_logger(self.logger): |
|
|
|
list(self.imgs_from_html("", fail=True)) |
|
|
|
|
|
|
|
def test_false_html(self): |
|
|
|
"""``False`` HTML handled correctly.""" |
|
|
|
for laps, text in self.imgs_from_html(False): |
|
|
|
self.assertTrue(False) # You should never get here |
|
|
|
with mute_logger(self.logger): |
|
|
|
for laps, text in self.imgs_from_html(False): |
|
|
|
self.assertTrue(False) # You should never get here |
|
|
|
|
|
|
|
with self.assertRaises(TypeError): |
|
|
|
list(self.imgs_from_html(False, fail=True)) |
|
|
|
|
|
|
|
def test_bad_html(self): |
|
|
|
"""Bad HTML handled correctly.""" |
|
|
|
for laps, text in self.imgs_from_html("<<bad>"): |
|
|
|
self.assertTrue(False) # You should never get here |
|
|
|
with mute_logger(self.logger): |
|
|
|
for laps, text in self.imgs_from_html("<<bad>"): |
|
|
|
self.assertTrue(False) # You should never get here |
|
|
|
|
|
|
|
with self.assertRaises(etree.ParserError): |
|
|
|
list(self.imgs_from_html("<<bad>", fail=True)) |
|
|
|
try: |
|
|
|
# Newer versions of lxml parse this as |
|
|
|
# '<html><body><p><<bad/></p></body></html>' |
|
|
|
# so the exception is not guaranteed |
|
|
|
with mute_logger(self.logger): |
|
|
|
images = list(self.imgs_from_html("<<bad>", fail=True)) |
|
|
|
self.assertFalse(images) |
|
|
|
except etree.ParserError: |
|
|
|
pass |