diff --git a/openerp/tests/__init__.py b/openerp/tests/__init__.py index d3ab62ebc1c..aa3055f471c 100644 --- a/openerp/tests/__init__.py +++ b/openerp/tests/__init__.py @@ -9,7 +9,7 @@ See the :ref:`test-framework` section in the :ref:`features` list. """ from . import test_expression, test_html_sanitize, test_ir_sequence, test_orm,\ - test_view_validation, test_uninstall + test_view_validation, test_uninstall, test_misc fast_suite = [ test_ir_sequence, @@ -20,6 +20,7 @@ checks = [ test_html_sanitize, test_orm, test_view_validation, + test_misc, ] # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/tests/test_misc.py b/openerp/tests/test_misc.py new file mode 100644 index 00000000000..7661f253b17 --- /dev/null +++ b/openerp/tests/test_misc.py @@ -0,0 +1,21 @@ +# This test can be run stand-alone with something like: +# > PYTHONPATH=. python2 openerp/tests/test_misc.py + +import unittest2 + +class test_misc(unittest2.TestCase): + """ Test some of our generic utility functions """ + + def test_append_to_html(self): + from openerp.tools import append_content_to_html + test_samples = [ + ('some content', '--\nYours truly', True, + 'some content\n
--\nYours truly\n'), + ('some content', '\n\n
--
\nYours truly
\n\n', False, + 'some content\n\n\n--
\nYours truly
\n\n\n'), + ] + for html, content, flag, expected in test_samples: + self.assertEqual(append_content_to_html(html,content,flag), expected, 'append_content_to_html is broken') + +if __name__ == '__main__': + unittest2.main() \ No newline at end of file diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index e86f189e9ca..39e86b1ec4a 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -400,6 +400,37 @@ def email_split(text): if not text: return [] return re.findall(r'([^ ,<@]+@[^> ,]+)', text) +def append_content_to_html(html, content, plaintext=True): + """Append extra content at the end of an HTML snippet, trying + to locate the end of the HTML document (