summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2015-10-30 14:09:22 +0100
committerNicolas Lempereur <nle@odoo.com>2015-11-03 15:44:03 +0100
commitee46560004f2301d9c47dfb25b37ce2ee06759cb (patch)
tree97e4309f6e0681b2c7ca474bfe6d938360cbaf0b
parentf5acea7f9ce232773ec3adf1828a3d18bbedee1e (diff)
[IMP] translate: test `xml_translate` with sample translations
The received value of a translation has to be escaped client side. note: testing the use case solved with f5acea7
-rw-r--r--openerp/addons/base/tests/test_translate.py24
-rw-r--r--openerp/tools/translate.py3
2 files changed, 25 insertions, 2 deletions
diff --git a/openerp/addons/base/tests/test_translate.py b/openerp/addons/base/tests/test_translate.py
index 40cf960873c..95b306e1837 100644
--- a/openerp/addons/base/tests/test_translate.py
+++ b/openerp/addons/base/tests/test_translate.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from lxml.etree import XMLSyntaxError
import unittest
from openerp.tools.translate import quote, unquote, xml_translate, html_translate
@@ -41,6 +42,29 @@ class TranslationToolsTestCase(unittest.TestCase):
self.assertItemsEqual(terms,
['Form stuff', 'Blah blah blah', 'Put some more text here'])
+ def test_translate_xml_text(self):
+ """ Test xml_translate() on plain text. """
+ terms = []
+ source = "Blah blah blah"
+ result = xml_translate(terms.append, source)
+ self.assertEquals(result, source)
+ self.assertItemsEqual(terms, [source])
+
+ def test_translate_xml_text_entity_unescaped(self):
+ """ Test xml_translate() on plain text with HTML entities. """
+ terms = []
+ source = "Blah&nbsp;blah&nbsp;blah"
+ with self.assertRaises(XMLSyntaxError):
+ xml_translate(terms.append, source)
+
+ def test_translate_xml_text_entity(self):
+ """ Test xml_translate() on plain text with HTML escaped entities. """
+ terms = []
+ source = "Blah&amp;nbsp;blah&amp;nbsp;blah"
+ result = xml_translate(terms.append, source)
+ self.assertEquals(result, source)
+ self.assertItemsEqual(terms, [source])
+
def test_translate_xml_inline1(self):
""" Test xml_translate() with formatting elements. """
terms = []
diff --git a/openerp/tools/translate.py b/openerp/tools/translate.py
index 3287547c790..07b587d1467 100644
--- a/openerp/tools/translate.py
+++ b/openerp/tools/translate.py
@@ -286,8 +286,7 @@ def html_translate(callback, value):
trans = XMLTranslator(callback, 'html')
wrapped = "<div>%s</div>" % encode(value)
root = etree.fromstring(wrapped, etree.HTMLParser(encoding='utf-8'))
- # html > body > div
- trans.process(root[0][0])
+ trans.process(root[0][0]) # html > body > div
return trans.get_done()[5:-6] # remove tags <div> and </div>