|
@ -1,15 +1,16 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
# © 2016 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis |
|
|
|
|
|
|
|
|
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com> |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
|
from lxml import etree |
|
|
from lxml import etree |
|
|
from openerp.tests.common import TransactionCase |
|
|
|
|
|
|
|
|
from odoo.tools import mute_logger |
|
|
|
|
|
from odoo.tests.common import TransactionCase |
|
|
|
|
|
from ..models import ir_fields_converter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExtractorCase(TransactionCase): |
|
|
class ExtractorCase(TransactionCase): |
|
|
def setUp(self): |
|
|
def setUp(self): |
|
|
super(ExtractorCase, self).setUp() |
|
|
super(ExtractorCase, self).setUp() |
|
|
|
|
|
|
|
|
# Shortcut |
|
|
# Shortcut |
|
|
self.text_from_html = self.env["ir.fields.converter"].text_from_html |
|
|
self.text_from_html = self.env["ir.fields.converter"].text_from_html |
|
|
|
|
|
|
|
@ -40,18 +41,21 @@ class ExtractorCase(TransactionCase): |
|
|
self.text_from_html(html, 7, ellipsis=""), |
|
|
self.text_from_html(html, 7, ellipsis=""), |
|
|
u"I'm a title I'm a paragraph ¡Pues") |
|
|
u"I'm a title I'm a paragraph ¡Pues") |
|
|
|
|
|
|
|
|
|
|
|
@mute_logger(ir_fields_converter.__name__) |
|
|
def test_empty_html(self): |
|
|
def test_empty_html(self): |
|
|
"""Empty HTML handled correctly.""" |
|
|
"""Empty HTML handled correctly.""" |
|
|
self.assertEqual(self.text_from_html(""), "") |
|
|
self.assertEqual(self.text_from_html(""), "") |
|
|
with self.assertRaises(etree.XMLSyntaxError): |
|
|
with self.assertRaises(etree.XMLSyntaxError): |
|
|
self.text_from_html("", fail=True) |
|
|
self.text_from_html("", fail=True) |
|
|
|
|
|
|
|
|
|
|
|
@mute_logger(ir_fields_converter.__name__) |
|
|
def test_false_html(self): |
|
|
def test_false_html(self): |
|
|
"""``False`` HTML handled correctly.""" |
|
|
"""``False`` HTML handled correctly.""" |
|
|
self.assertEqual(self.text_from_html(False), "") |
|
|
self.assertEqual(self.text_from_html(False), "") |
|
|
with self.assertRaises(TypeError): |
|
|
with self.assertRaises(TypeError): |
|
|
self.text_from_html(False, fail=True) |
|
|
self.text_from_html(False, fail=True) |
|
|
|
|
|
|
|
|
|
|
|
@mute_logger(ir_fields_converter.__name__) |
|
|
def test_bad_html(self): |
|
|
def test_bad_html(self): |
|
|
"""Bad HTML handled correctly.""" |
|
|
"""Bad HTML handled correctly.""" |
|
|
self.assertEqual(self.text_from_html("<<bad>"), "") |
|
|
self.assertEqual(self.text_from_html("<<bad>"), "") |
|
|