You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. from openerp.tools import mute_logger
  6. class ExtractorCase(TransactionCase):
  7. def setUp(self):
  8. super(ExtractorCase, self).setUp()
  9. # Shortcut
  10. self.imgs_from_html = self.env["ir.fields.converter"].imgs_from_html
  11. def test_mixed_images_found(self):
  12. """Images correctly found in <img> elements and backgrounds."""
  13. content = u"""
  14. <div>
  15. <!-- src-less img -->
  16. <img/>
  17. <p/>
  18. <img src="/path/0"/>
  19. <img src="/path/1"/>
  20. <img src="/path/2"/>
  21. <img src="/path/3"/>
  22. <section style="background : URL('/path/4');;background;ö;">
  23. <div style='BACKGROUND-IMAGE:url(/path/5)'>
  24. <p style="background:uRl(&quot;/path/6&quot;)">
  25. <img src="/path/7"/>
  26. </p>
  27. </div>
  28. </section>
  29. </div>
  30. """
  31. # Read all images
  32. for n, url in enumerate(self.imgs_from_html(content)):
  33. self.assertEqual("/path/%d" % n, url)
  34. self.assertEqual(n, 7)
  35. # Read only first image
  36. for n, url in enumerate(self.imgs_from_html(content, 1)):
  37. self.assertEqual("/path/%d" % n, url)
  38. self.assertEqual(n, 0)
  39. @mute_logger("openerp.addons.html_image_url_extractor.models"
  40. ".ir_fields_converter")
  41. def test_empty_html(self):
  42. """Empty HTML handled correctly."""
  43. for laps, text in self.imgs_from_html(""):
  44. self.assertTrue(False) # You should never get here
  45. with self.assertRaises(Exception):
  46. list(self.imgs_from_html("", fail=True))
  47. @mute_logger("openerp.addons.html_image_url_extractor.models"
  48. ".ir_fields_converter")
  49. def test_false_html(self):
  50. """``False`` HTML handled correctly."""
  51. for laps, text in self.imgs_from_html(False):
  52. self.assertTrue(False) # You should never get here
  53. with self.assertRaises(Exception):
  54. list(self.imgs_from_html(False, fail=True))