[TEST] base/qweb: add tests for dynamic namespace in qweb python
This commit is contained in:
@@ -984,7 +984,8 @@ class QWeb(object):
|
||||
else:
|
||||
# Etree will remove the ns prefixes indirection by inlining the corresponding
|
||||
# nsmap definition into the tag attribute. Restore the tag and prefix here.
|
||||
# Note: we do not support namespace dynamic attributes.
|
||||
# Note: we do not support namespace dynamic attributes, we need a default URI
|
||||
# on the root and use attribute directive t-att="{'xmlns:example': value}".
|
||||
unqualified_el_tag = etree.QName(el.tag).localname
|
||||
el_tag = unqualified_el_tag
|
||||
if el.prefix:
|
||||
|
||||
@@ -207,6 +207,89 @@ class TestQWebNS(TransactionCase):
|
||||
|
||||
self.assertEqual(etree.fromstring(view1._render()), etree.fromstring(expected_result))
|
||||
|
||||
def test_render_static_xml_with_namespace_dynamic(self):
|
||||
""" Test the rendering on a namespaced view with dynamic URI (need default namespace uri).
|
||||
"""
|
||||
tempate = u"""
|
||||
<root xmlns:h="https://default.namespace.url/h">
|
||||
<h:table t-att="{'xmlns:h': h1}">
|
||||
<h:tr>
|
||||
<h:td t-att="{'xmlns:h': h2}">Apples</h:td>
|
||||
<h:td>Bananas</h:td>
|
||||
</h:tr>
|
||||
</h:table>
|
||||
</root>
|
||||
"""
|
||||
expected_result = u"""
|
||||
<root xmlns:h="https://default.namespace.url/h">
|
||||
<h:table xmlns:h="%(h1)s">
|
||||
<h:tr>
|
||||
<h:td xmlns:h="%(h2)s">Apples</h:td>
|
||||
<h:td>Bananas</h:td>
|
||||
</h:tr>
|
||||
</h:table>
|
||||
</root>
|
||||
"""
|
||||
|
||||
values = dict(h1="http://www.example.org/table", h2="http://www.w3.org/TD/html4/")
|
||||
|
||||
view1 = self.env['ir.ui.view'].create({
|
||||
'name': "dummy",
|
||||
'type': 'qweb',
|
||||
'arch': u"""
|
||||
<t t-name="base.dummy">%s</t>
|
||||
""" % tempate
|
||||
})
|
||||
|
||||
rendering = view1._render(values, engine='ir.qweb')
|
||||
|
||||
self.assertEqual(etree.fromstring(rendering), etree.fromstring(expected_result % values))
|
||||
|
||||
def test_render_static_xml_with_namespace_dynamic_2(self):
|
||||
""" Test the rendering on a namespaced view with dynamic URI (need default namespace uri).
|
||||
Default URIs must be differents.
|
||||
"""
|
||||
tempate = u"""
|
||||
<root xmlns:f="https://default.namespace.url/f" xmlns:h="https://default.namespace.url/h" >
|
||||
<h:table t-att="{'xmlns:h': h1}">
|
||||
<h:tr>
|
||||
<h:td t-att="{'xmlns:h': h2}">Apples</h:td>
|
||||
<h:td>Bananas</h:td>
|
||||
</h:tr>
|
||||
</h:table>
|
||||
<f:table t-att="{'xmlns:f': f}">
|
||||
<f:width>80</f:width>
|
||||
</f:table>
|
||||
</root>
|
||||
"""
|
||||
expected_result = u"""
|
||||
<root xmlns:f="https://default.namespace.url/f" xmlns:h="https://default.namespace.url/h">
|
||||
<h:table xmlns:h="%(h1)s">
|
||||
<h:tr>
|
||||
<h:td xmlns:h="%(h2)s">Apples</h:td>
|
||||
<h:td>Bananas</h:td>
|
||||
</h:tr>
|
||||
</h:table>
|
||||
<f:table xmlns:f="%(f)s">
|
||||
<f:width>80</f:width>
|
||||
</f:table>
|
||||
</root>
|
||||
"""
|
||||
|
||||
values = dict(h1="http://www.example.org/table", h2="http://www.w3.org/TD/html4/", f="http://www.example.org/furniture")
|
||||
|
||||
view1 = self.env['ir.ui.view'].create({
|
||||
'name': "dummy",
|
||||
'type': 'qweb',
|
||||
'arch': u"""
|
||||
<t t-name="base.dummy">%s</t>
|
||||
""" % tempate
|
||||
})
|
||||
|
||||
rendering = view1._render(values, engine='ir.qweb')
|
||||
|
||||
self.assertEqual(etree.fromstring(rendering), etree.fromstring(expected_result % values))
|
||||
|
||||
def test_render_dynamic_xml_with_namespace_t_esc(self):
|
||||
""" Test that rendering a template containing a node having both an ns declaration and a t-esc attribute correctly
|
||||
handles the t-esc attribute and keep the ns declaration.
|
||||
|
||||
Reference in New Issue
Block a user