[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
This commit is contained in:
Raphael Collet
2015-11-03 15:44:03 +01:00
committed by Nicolas Lempereur
parent f5acea7f9c
commit ee46560004
2 changed files with 25 additions and 2 deletions
@@ -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 blah 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 blah 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 = []
+1 -2
View File
@@ -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>