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.

55 lines
1.9 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.text_from_html = self.env["ir.fields.converter"].text_from_html
  11. def test_excerpts(self):
  12. """Text gets correctly extracted."""
  13. html = u"""
  14. <html>
  15. <body>
  16. <div class="this should not appear">
  17. <h1>I'm a title</h1>
  18. <p>I'm a paragraph</p>
  19. <small>¡Pues yo soy español!</small>
  20. </div>
  21. </body>
  22. </html>
  23. """
  24. self.assertEqual(
  25. self.text_from_html(html),
  26. u"I'm a title I'm a paragraph ¡Pues yo soy español!")
  27. self.assertEqual(
  28. self.text_from_html(html, 8),
  29. u"I'm a title I'm a paragraph ¡Pues yo…")
  30. self.assertEqual(
  31. self.text_from_html(html, 8, 31),
  32. u"I'm a title I'm a paragraph ¡P…")
  33. self.assertEqual(
  34. self.text_from_html(html, 7, ellipsis=""),
  35. u"I'm a title I'm a paragraph ¡Pues")
  36. @mute_logger("openerp.addons.html_text.models.ir_fields_converter")
  37. def test_empty_html(self):
  38. """Empty HTML handled correctly."""
  39. self.assertEqual(self.text_from_html(""), "")
  40. with self.assertRaises(Exception):
  41. self.text_from_html("", fail=True)
  42. @mute_logger("openerp.addons.html_text.models.ir_fields_converter")
  43. def test_false_html(self):
  44. """``False`` HTML handled correctly."""
  45. self.assertEqual(self.text_from_html(False), "")
  46. with self.assertRaises(Exception):
  47. self.text_from_html(False, fail=True)